-
Notifications
You must be signed in to change notification settings - Fork 177
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
feat(csharp): support skipResponseValidation config in c# #5994
base: main
Are you sure you want to change the base?
Conversation
JsonSerializerOptionsWithFallback = new JsonSerializerOptions(options) | ||
{ | ||
TypeInfoResolver = new DefaultJsonTypeInfoResolver | ||
{ | ||
Modifiers = | ||
{ | ||
static typeInfo => | ||
{ | ||
foreach (var propertyInfo in typeInfo.Properties) | ||
{ | ||
// Strip IsRequired constraint from every property. | ||
propertyInfo.IsRequired = false; | ||
} | ||
} | ||
} | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ConfigureJsonSerializerOptions
method is an extension point for SDK maintainers so they can customize some of the options.
I think that this would prevent them from modifying the type info resolvers and modifiers like we are doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah thats fair, i'm not sure how valuable it is to keep that extension method
I'd rather see a single Serialize/Deserialize method. Is there a reason we would surface a validating and non-validating variant at the same time? |
Yes -- we would surface it so that SDK users can decide how they want validation to work. For example, internal consumers of the SDK would turn validation on and external ones would keep it off. |
@@ -39,4 +58,9 @@ public static T Deserialize<T>(string json) | |||
{ | |||
return JsonSerializer.Deserialize<T>(json, JsonOptions.JsonSerializerOptions)!; | |||
} | |||
|
|||
public static T DeserializeWithFallback<T>(string json) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
swap out public -> internal
@@ -6,6 +6,7 @@ namespace <%= namespace%>; | |||
internal static partial class JsonOptions | |||
{ | |||
public static readonly JsonSerializerOptions JsonSerializerOptions; | |||
public static readonly JsonSerializerOptions JsonSerializerOptionsWithFallback; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make it internal
Description
Add new configuration
skipResponseValidation
to skip response validation. When set to true, the generated client will fail fast if the response schema does not match the generated code. This is particularly useful if you are concerned about your API Definition (e.g. OpenAPI, AsyncAPI) not being entirely correct.Changes Made
JsonUtils.Template.cs
SDKGeneratorContext
that returnsDeserialize
orDeserializeWithFallbacks
depending on the feature flagTesting