Closed leedsalex closed 1 year ago
there are no failing tests - can you provide a test that shows there is an issue?
I am not very interested in maintaining this project - see the swagger-akka-http readme - since Akka is no longer OSS - I'm not very interested in it. When Pekko is out, I will completely abandon Akka.
Ok - since this module is independent of Akka, I've created #225 - I'll need to look a bit more at this before merging.
It's messy because the deprecated required() is still independent or requiredMode() so swagger-scala-module will still need to read both. requiredMode() is used in preference to required() - the latter is only checked if requiredMode() == Auto (the default mode)
When users add swagger annotations (Schema, ArraySchema, Parameter), they can override whether a model property is required or not. Whether a model property is required or not, is usually based on the type of the related Scala field (Ie fields of type Option[T]
are optional - other fields are required).
The annotations mentioned above have a required()
setting which is boolean and defaults to false. It is impossible to know if the user explicitly set false or if the are using the annotations to override other settings but don't intend to affect the required setting.
swagger v2.2.5 introduces a requiredMode()
setting on the Schema and ArraySchema annotations. The modes are Required, Not_Required and Auto - the latter is the default. This is better - but the required()
setting, while deprecated, is still there and is set independently of the requiredMode()
.
The current treatment of required()=false
is described in the readme. SwaggerScalaModelConverter.setRequiredBasedOnAnnotation will continue to affect how required()=false
is interpreted.
requiredMode() | required() | Effect on Model Property |
---|---|---|
Required | this value is ignored | Model property is overridden to be required. |
NotRequired | this value is ignored | Model property is overridden to be not required. |
Auto (default) | true | Model property is overridden to be required. |
Auto (default) | false (default) | if SwaggerScalaModelConverter.setRequiredBasedOnAnnotation is true (current default), then the model property is overridden to be required. Otherwise, whether the model property is required is not depends on the data type and whether a default value is set. |
Aim is to change the default for if SwaggerScalaModelConverter.setRequiredBasedOnAnnotation to false in a release in a few months time. I'm afraid that some existing users will get unexpected changes in behaviour if these changes are rolled out too quickly.
@SamTheisens could you review this design? This proposal changes how SwaggerScalaModelConverter.setRequiredBasedOnAnnotation(false)
works - this setting no longer ignores the annotations altogether - it means it just ignores required()=false
(which can be set inadvertently)
swagger-scala-module v2.9.0 was released with this change
In the latest release of Swagger Core (as of v2.2.5) they deprecated the
required
annotation property and replaced it withrequiredMode
. I believe support for this change will need to be added to this project.See this PR for the implimentation: https://github.com/swagger-api/swagger-core/pull/4286