Fixed SystemTextJson indexed properties handling.#1701
Conversation
|
@lahma Could you, please, help me with a build error that I get? I am getting " [ERR] Compile: D:\a\NJsonSchema\NJsonSchema\src\NJsonSchema\Generation\JsonSchemaGenerator.cs(1092,25): error CA1859: Change return type of method 'TryGetInheritanceDiscriminatorConverter' from 'object?' to 'NJsonSchema.Generation.JsonSchemaGenerator.SystemTextJsonInheritanceWrapper?' for improved performance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1859) [D:\a\NJsonSchema\NJsonSchema\src\NJsonSchema\NJsonSchema.csproj::TargetFramework=netstandard2.0]". I tried to fix it as error message suggested, changed return type of method Do you know what is a correct type to use here to fix CA1859? |
| } | ||
|
|
||
| private object? TryGetInheritanceDiscriminatorConverter(Type type) | ||
| private SystemTextJsonInheritanceWrapper? TryGetInheritanceDiscriminatorConverter(Type type) |
There was a problem hiding this comment.
is this really needed?
i think this might break CI?
There was a problem hiding this comment.
Yes, I think this should be reverted, it breaks test When_schema_has_base_schema_then_it_is_referenced_with_Newtonsoft.
However, without it build fails with " [ERR] Compile: D:\a\NJsonSchema\NJsonSchema\src\NJsonSchema\Generation\JsonSchemaGenerator.cs(1092,25): error CA1859: Change return type of method 'TryGetInheritanceDiscriminatorConverter' from 'object?' to 'NJsonSchema.Generation.JsonSchemaGenerator.SystemTextJsonInheritanceWrapper?' for improved performance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1859) [D:\a\NJsonSchema\NJsonSchema\src\NJsonSchema\NJsonSchema.csproj::TargetFramework=netstandard2.0]"."
There was a problem hiding this comment.
Can you suggest a better fix to CA1859?
There was a problem hiding this comment.
You should be able to use
#pragma warning disable CA1859
private object? TryGetInheritanceDiscriminatorConverter(Type type)
#pragma warning enable CA1859This reverts commit d7297d5.
The
SystemTextJsonReflectionServicedid not handle properly types with indexed properties. Exception "The JSON property 'item' is defined multiple times on type" was thrown if schema had been generated for type with multiple indexed properties.In the applied fix indexed properties are detected and not added to the generated schema.
Result schema matches schemas generated with
NewtonsoftJsonReflectionServiceand previous versions of NJsonSchema library.Fixes RicoSuter/NSwag#4874