azure-functions-openapi-extension icon indicating copy to clipboard operation
azure-functions-openapi-extension copied to clipboard

Allow passing JsonSerializerSettings to OpenApiExampleResolver

Open toriverly opened this issue 3 years ago • 4 comments

Currently, we can pass naming strategy to the Resolve() methods, but I have additional settings (e.g. custom converters) I would like to use for generating examples.

I feel it would be handy to pass serializer settings to resolve, or use JsonConvert.DefaultSettings to get the default settings, which we can set in startup.

toriverly avatar Aug 18 '22 22:08 toriverly

@toriverly Thanks for the issue! I'll take a look.

justinyoo avatar Aug 22 '22 15:08 justinyoo

As this introduce breaking change to IOpenApiExample<T>, it should be re-labelled to v2.0.0

justinyoo avatar Sep 19 '22 09:09 justinyoo

#613 takes care of this issue

justinyoo avatar Sep 19 '23 12:09 justinyoo

As far as I can tell, #613 allowed naming strategy to be set in OpenApiConfigurationOptions, but did not address passing JsonSerializerSettings to Resolve() or using JsonConvert.DefaultSettings(). We are still unable to specify custom converters or additional serializer settings.

OpenApiExampleResolver.cs#L17

private static JsonSerializerSettings settings = new JsonSerializerSettings();

OpenApiExampleResolver.cs#L63

var resolver = new DefaultContractResolver() { NamingStrategy = namingStrategy ?? new DefaultNamingStrategy() };
settings.ContractResolver = resolver;

var openApiExampleValue = OpenApiExampleFactory.CreateInstance<T>(instance,settings);

There was interest in configuring JsonSerializerSettings mentioned in issue #485 as well.

toriverly avatar May 29 '24 15:05 toriverly