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

Generated JSON example is wrong for additional properties when KebabCaseNamingStrategy was configured #2559

Open
gileli121 opened this issue Nov 29, 2022 · 0 comments
Labels
help-wanted A change up for grabs for contributions from the community

Comments

@gileli121
Copy link

Hello, if you configure the service to use KebabCaseNamingStrategy like this:

	public void ConfigureServices(IServiceCollection services)
	{
		services.AddMvc(options =>
			{
				options.UseGeneralRoutePrefix(RoutePrefix);
				options.Filters.Add(typeof(UnhandledExceptionFilter));
				options.EnableEndpointRouting = false;
			})
			.AddNewtonsoftJson(options =>
			{
				options.SerializerSettings.Converters.Add(new StringEnumConverter());
				options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
				options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
				options.SerializerSettings.ContractResolver = new DefaultContractResolver
				{
					NamingStrategy = new KebabCaseNamingStrategy
					{
						ProcessDictionaryKeys = true,
						OverrideSpecifiedNames = true
					}
				};
				options.SerializerSettings.Formatting = Formatting.Indented;
			});


		services.AddSwaggerGen(c =>
		{
			c.SwaggerDoc(ServiceName, new OpenApiInfo { Title = ServiceTitle, Version = "v1" });
			c.AddAuthorizeButton();
		});
		services.AddSwaggerGenNewtonsoftSupport();

		...
	}

And have this DTO:

    public class DTOTest
    {
        [JsonExtensionData] public IDictionary<string, JToken> ExtraStuff { get; set; }
        public string DtoField { get; set; }
    }

Abd has this controller:

[Route("/test")]
[ApiController]
public class TestController : ContextController
{
	[HttpPost]
	[Route("test")]
	public async Task<IActionResult> CreateTestsAsync([FromBody] DTOTest myDto)
	{
		return Ok();
	}
}

Then the swagger generates this example payload:
image

This seems wrong to me because the example fields for ExtraStuff property should be written also in the Kebab-case naming style.
So, I would expect to see here this example payload:

{
  "dto-field": "string",
  "additional-prop1": "string",
  "additional-prop2": "string",
  "additional-prop3": "string"
}

Is there any way to fix this issue?
If not, removing the "additionalProp1", "additionalProp2", and "additionalProp3" is also an option.

Thank you.

@gileli121 gileli121 changed the title Generated JSON example is wrong for additional proptoes when KebabCaseNamingStrategy was configured Generated JSON example is wrong for additional properties when KebabCaseNamingStrategy was configured Nov 29, 2022
@martincostello martincostello added the help-wanted A change up for grabs for contributions from the community label Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help-wanted A change up for grabs for contributions from the community
Projects
None yet
Development

No branches or pull requests

2 participants