swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

ModelResolver#resolve ignores TYPE_USE annotations on property types

Open olsavmic opened this issue 10 months ago • 3 comments

We're using the JSpecify annotations (which will become the default nullability annotations in Spring Framework 7) and we encountered an issue with Swagger-core capabilities.

These nullability annotations are properly targeting TYPE_USE element type, which is currently not read at all by the io.swagger.v3.core.jackson.ModelResolver#resolve, making it impossible to set OpenAPI properties (such as eg. nullability) automatically.

  • Do you see any blocker why TYPE_USE annotations should not be considered by the ModelResolver?
  • Do you see any way around until the swagger-core is improved?

olsavmic avatar Feb 26 '25 10:02 olsavmic

We've encountered the same issue, I would expect to find the TYPE_USE annotations within io.swagger.v3.core.converter.AnnotatedType so they can be used when implementing a custom ModelConverter.

This issue is preventing us from deriving OpenAPI nullability from JSpecify annotations.

TijsSchoneveld avatar Mar 24 '25 09:03 TijsSchoneveld

I think swagger definitely should be compatible with jSpecify or probable even should be a member of it -> https://jspecify.dev/about/

HerrDerb avatar Apr 16 '25 07:04 HerrDerb

I'm experiencing the same issue.

Is there maybe a workaround until it's supported?

Here is also a blog post about Spring Framework moving to JSpecify. So wider adoption of these annotation is expected sooner or later.

Besides JSpecify's @Nullable and @NonNull also @NullMarked on package level should be supported to indicate all fields are "non-null", but can still be overridden per field with @Nullable where needed.

marceloverdijk avatar May 12 '25 09:05 marceloverdijk