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

OpenApi generation OpenApiSchemaComparer fails with null values for Properties, AllOf, or AnyOf #59507

Open
1 task done
FrankSzendzielarz opened this issue Dec 16, 2024 · 1 comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-openapi

Comments

@FrankSzendzielarz
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

OpenApiSchemaComparer uses code like hashCode.Add(obj.Properties.Count); . In custom schema transforms where I might want to replace allof , anyof, or properties, intuitively I would set unwanted properties to null. Either the setter should prevent this, or the obj.Properties.Count should be obj.Properties?.Count??0 or otherwise take care of nulls.

Expected Behavior

Not crash when a schema property is null.

Steps To Reproduce

Custom schema transform - set Properties to null. OpenApi doc gen and Scalar result have missing elements.

Exceptions (if any)

Object reference not set to an instance of an object.

.NET Version

9

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Dec 16, 2024
@martincostello martincostello added feature-openapi area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels labels Dec 16, 2024
@captainsafia
Copy link
Member

@FrankSzendzielarz Thanks for filing this issue!

I believe as a temporary workaround you can initialize the designated properties to empty lists. The OpenAPI document writer should do the write thing and not emit them but let me know if that's not the case.

With regard to how we might solve this in the long-term, with the adoption of Microsoft.OpenApi v2, we're hoping to move forward with the comparers being implemented in the library themselves (instead of in the ASP.NET Core codebase). There's also some changes coming to the nullability/default blues for collection-based properties like AllOf and friends.

I'll take this one as a sub-issue under #58619 for now since the comparers are removed from source in #59480.

@captainsafia captainsafia added this to the .NET 10 Planning milestone Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-openapi
Projects
None yet
Development

No branches or pull requests

3 participants