Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PropertyNameGenerator as an optional Parameter #516

Closed
fsamiec opened this issue Oct 31, 2024 · 2 comments
Closed

Add PropertyNameGenerator as an optional Parameter #516

fsamiec opened this issue Oct 31, 2024 · 2 comments
Assignees
Labels
enhancement New feature, bug fix, or request

Comments

@fsamiec
Copy link

fsamiec commented Oct 31, 2024

Is your feature request related to a problem? Please describe.
Currently, CodeGeneratorSettings does not provide an option to define a custom PropertyNameGenerator. In my projects this does not match the PascalNaming convention, as the properties are named like this:

[System.Text.Json.Serialization.JsonPropertyName("business_partner")]
public int Business_partner { get; set; }

[System.Text.Json.Serialization.JsonPropertyName("main_consultant_number")]
public int Main_consultant_number { get; set; }

Describe the solution you'd like
I would like to see an option in CodeGeneratorSettings that allows for the integration of a custom PropertyNameGenerator like the given sample below:

//Refitter.Core/CSharpClientGeneratorFactory.cs
internal class CSharpClientGeneratorFactory(RefitGeneratorSettings settings, OpenApiDocument document)
{
	public CustomCSharpClientGenerator Create()
    {
		var csharpClientGeneratorSettings = new CSharpClientGeneratorSettings
		{
			CodeGeneratorSettings = { PropertyNameGenerator = settings.CodeGeneratorSettings.PropertyNameGenerator ?? new CustomCSharpPropertyNameGenerator(), },
		};
	}
}
//Refitter.Core/Settings/RefitGeneratorSettings.cs

/// <summary>
/// Provide settings for Refit generator.
/// </summary>
[ExcludeFromCodeCoverage]
public class RefitGeneratorSettings
{    
	/// <summary>Gets or sets the property name generator.</summary>
	[JsonIgnore]
	public IPropertyNameGenerator PropertyNameGenerator { get; set; }		
}

Describe alternatives you've considered
NSwag unfortunately does not meet our logging requirements, as we need the method names from the RestMethodInfo.

Additional context
If there is any other way to customize the property names please let me know.

/cc @christianerbsmehl

@fsamiec fsamiec added the enhancement New feature, bug fix, or request label Oct 31, 2024
@fsamiec fsamiec changed the title Make NameGenerator an optional Add PropertyNameGenerator as an optional Parameter Oct 31, 2024
@christianhelle
Copy link
Owner

@fsamiec Thanks for taking the time to report this. Unfortunately, I'm too busy with other things to look into this. If you find a solution yourself and create a pull request, then I will find the time to review and make sure your fix gets merged in and released. Otherwise, this will have to wait a few weeks

/cc @christianerbsmehl

@fsamiec
Copy link
Author

fsamiec commented Nov 4, 2024

thank you for merging. 👍
i will add another pull request, based on your feedback.

@fsamiec fsamiec closed this as completed Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, bug fix, or request
Projects
None yet
Development

No branches or pull requests

2 participants