swagger-api / swagger-core

Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API
http://swagger.io
Apache License 2.0
7.37k stars 2.17k forks source link

ArraySchema annotation items() value does not appear to be properly supported #4610

Closed pjfanning closed 7 months ago

pjfanning commented 8 months ago

I may or may not be correct but the ArraySchema annotation now has items() and schema() but they both have the same Javadoc. I assume that items() is meant to be a synonym for schema() but is less ambiguously named. items() is a recent addition.

See https://docs.swagger.io/swagger-core/v2.2.20/apidocs/io/swagger/v3/oas/annotations/media/ArraySchema.html

I have a test case in Scala where I use an ArraySchema annotation to override the item implementation. I have 2 variants. One that uses schema and the other that uses items but the override only works with schema.

I'm using swagger 2.2.20.

The 2 classes are in: https://github.com/swagger-akka-http/swagger-scala-module/blob/develop/src/test/scala/models/AddRequest.scala

The AddRequestOldStyleAnnotation variant works as expected when I run it through the swagger-core ModelResolver.

I suspect that this line is at fault

https://github.com/swagger-api/swagger-core/blob/0d067d03b6ef78a78efe3e4f957f977254c72030/modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.java#L166

Note how it only looks at the schema value and not the items value.

frantuma commented 7 months ago

Thanks for reporting this. It looks like a bug introduced while implementing support for OpenAPI 3.1, as ArraySchema.schema already represents the schema of the items in the array, and ArraySchema.items is a duplicate that has been only processed in terms of types and only in case of OpenAPI 3.1.

4611 deprecates ArraySchema.items for future removal, adding support for OAS 3.1 types by processing existing schema field.