RicoSuter / NJsonSchema

JSON Schema reader, generator and validator for .NET
http://NJsonSchema.org
MIT License
1.37k stars 529 forks source link

Fixed SystemTextJson indexed properties handling. #1701

Closed viktoriia-zhel closed 2 months ago

viktoriia-zhel commented 2 months ago

The SystemTextJsonReflectionService did 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 NewtonsoftJsonReflectionService and previous versions of NJsonSchema library.

Fixes https://github.com/RicoSuter/NSwag/issues/4874

viktoriia-zhel commented 2 months ago

@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 TryGetInheritanceDiscriminatorConverter to SystemTextJsonInheritanceWrapper. However, that broke unit test When_schema_has_base_schema_then_it_is_referenced_with_Newtonsoft.

Do you know what is a correct type to use here to fix CA1859? Or can I disable this check for the method TryGetInheritanceDiscriminatorConverter so the build is successful?