swagger-api / swagger-scala-module Goto Github PK
View Code? Open in Web Editor NEWSwagger support for scala
Swagger support for scala
Hi,
When I have something like this:
case class Test(quantity:Int, quantityOpt:Option[Int])
The swagger model will have this properties:
properties:
quantity:
type: integer
format: int32
quantityOpt:
type: object
But the right definition should be something like this
properties:
quantity:
type: integer
format: int32
quantityOpt:
type: integer
format: int32
There are any solution for it ?
Thanks !
Update swagger-core reference so the byte byte and binary property types are available.
Can you please release a minor/bugfix version that includes PR #9 ?
I am using swagger-play2_2.11 (ver. 1.3.12), swagger-scala-module (ver. 1.0.1) and latest swagger-ui in my Scala project. The API method annotations works as expected. The only problem I have is with model annotations. The fields and data types are displayed properly. The only missing thing are descriptions. It does not matter if it is request model or response. It does not work in both cases. The example request model:
@ApiModel(description = "Agency booking request")
case class AgencyBookingRequest(@ApiModelProperty(value = "Experience id") experienceId: String,
@ApiModelProperty(value = "Number of guests") numberOfGuests: Int,
@ApiModelProperty(value = "List of other guests") otherGuests: List[AgencyBookingRequestAccount],
@ApiModelProperty(value = "Booking date") date: String,
@ApiModelProperty(value = "Booking time") time: String,
@ApiModelProperty(value = "Experience price") expectedPrice: Int,
@ApiModelProperty(value = "Coupon code") couponCode: Option[String],
@ApiModelProperty(value = "Coupon codes") couponCodes: Option[List[String]],
@ApiModelProperty(value = "Preferences") preferences: Option[String],
@ApiModelProperty(value = "Company id") companyId: String
) extends ExperienceAgencyBookingRequest with IBookingRequest with HasGuestInfo {
}
This is how it is annotated on the controller level:
@ApiImplicitParams(Array(
new ApiImplicitParam(value = "Booking that needs to be created", required = true, dataType = "viewmodels.api.v2.AgencyBookingRequest", paramType = "body")))
Have you got any ideas?
Thank you in advance.
A property of type List[String]
will be correctly described as an array of strings, but if it's List[Int]
it'll be described as an array of objects. The same goes for any parameterized type, if the type parameter is a primitive— for instance, when I tried to add support for Option[T]
(see issue 7), I found that Option[String]
worked correctly but Option[Int]
did not.
This may be a problem with the underlying Jackson Scala module; a comment on this issue mentioned that Java reflection sometimes misreads Scala primitives as being java.lang.Object. It looked like someone had fixed that in jackson-scala-module, but maybe not. Whatever the reason, it's not currently possible to document a schema that has an array of numbers or booleans in it.
need to give instructions for integration
Hi,
I'm unsure whether to post this here, or in the core-module, but since it is only applicable to the handling of Option-values in Scala I'm trying here.
The following schema-definition will always result in the listOfStrings
-field being required in the model:
@ArraySchema(arraySchema = new Schema(required = false), schema = new Schema(implementation = classOf[String], required = false)) listOfStrings: Seq[String] = Seq.empty[String]
It makes no difference if I try to set either or both of the schemas to not required, however wrapping the field in an Option will work as expected (the result being not required).
As far as I have found this is because swagger-scala-module sets all non-Option fields to required, but the SwaggerAnnotationIntrospector in the core-module will only override the required-argument from false to true, not the other way around, which I would have expected based on the spec for ArraySchema.
Hi,
Collection format allows specifying the format of passing URL parameters that allow multiple values.
http://swagger.io/specification/#parameterCollectionFormat
Setting the following annotation on a parameter someParameter
@ApiParam(allowMultiple = true, collectionFormat = "csv", allowableValues = "one,two,three"
does not change the output swagger definition, the value 'multi' is output:
{ "name" : "someParameter", "in" : "query", "required" : false, "type" : "array", "items" : { "type" : "string", "enum" : [ "one", "two", "three" ], "default" : "null" }, "collectionFormat" : "multi" }
Version used: 1.0.3
Regards, Ondrej
Traits do not seem to be picked up automatically.
If I have the following:
sealed trait Foo(x: Int)
case class Bar(x: Int) extends Foo
the generated Swagger definition is:
Foo: {
type: "object"
}
I would expect the property x
to be there as well.
A case class property of type Option[T]
should be represented in the Swagger model as a property of type T; the optional nature of the property would be indicated by required: false
.
Instead, Option
is being treated like any other Iterable
type, so the model appears to have an array property with items of type T— and required
is always being set to false
. Properties that are not Options should be assumed to be required (or at least it should be possible to tell Swagger to behave that way, if you're never going to use nulls).
sealed abstract class Status(val id: String) {
def self: Status = this
}
case object New extends Status("new")
case object Processed extends Status("processed")
Using this kind of constructions in model definitions leads to errors on Java 8 and below.
at java.lang.Class.getSimpleName(Class.java:1330)
at java.lang.Class.getCanonicalName(Class.java:1399)
at io.swagger.jackson.ModelResolver._isOptionalType(ModelResolver.java:175)
at io.swagger.jackson.ModelResolver.resolveProperty(ModelResolver.java:157)
at io.swagger.jackson.ModelResolver.resolveProperty(ModelResolver.java:112)
at io.swagger.scala.converter.SwaggerScalaModelConverter.resolveProperty(SwaggerScalaModelConverter.scala:70)
at io.swagger.converter.ModelConverterContextImpl.resolveProperty(ModelConverterContextImpl.java:80)
at io.swagger.jackson.ModelResolver.resolve(ModelResolver.java:464)
at io.swagger.jackson.ModelResolver.resolve(ModelResolver.java:185)
at io.swagger.scala.converter.SwaggerScalaModelConverter.resolve(SwaggerScalaModelConverter.scala:86)
at io.swagger.converter.ModelConverterContextImpl.resolve(ModelConverterContextImpl.java:100)
at io.swagger.jackson.ModelResolver.resolve(ModelResolver.java:236)
at io.swagger.jackson.ModelResolver.resolve(ModelResolver.java:185)
at io.swagger.scala.converter.SwaggerScalaModelConverter.resolve(SwaggerScalaModelConverter.scala:86)
at io.swagger.converter.ModelConverterContextImpl.resolve(ModelConverterContextImpl.java:100)
at io.swagger.jackson.ModelResolver.resolveProperty(ModelResolver.java:161)
at io.swagger.jackson.ModelResolver.resolveProperty(ModelResolver.java:112)
at io.swagger.scala.converter.SwaggerScalaModelConverter.resolveProperty(SwaggerScalaModelConverter.scala:70)
at io.swagger.converter.ModelConverterContextImpl.resolveProperty(ModelConverterContextImpl.java:80)
at io.swagger.converter.ModelConverters.readAsProperty(ModelConverters.java:58)
at io.swagger.util.ParameterProcessor.applyAnnotations(ParameterProcessor.java:263)
at play.modules.swagger.PlayReader.readImplicitParam(PlayReader.java:390)
at play.modules.swagger.PlayReader.readImplicitParameters(PlayReader.java:360)
at play.modules.swagger.PlayReader.read(PlayReader.java:198)
at play.modules.swagger.PlayReader.read(PlayReader.java:63)
at play.modules.swagger.PlayReader.read(PlayReader.java:57)
at play.modules.swagger.ApiListingCache$.$anonfun$listing$1(ApiListingCache.scala:17)
at scala.Option.orElse(Option.scala:289)
at play.modules.swagger.ApiListingCache$.listing(ApiListingCache.scala:11)
at play.modules.swagger.SwaggerPluginImpl.<init>(SwaggerPlugin.scala:164)
at myutil.environment$ApplicationEnvironment.<init>(BootstrapLoader.scala:170)
at myutil.BootstrapLoader.load(BootstrapLoader.scala:31)
at play.core.server.ProdServerStart$.start(ProdServerStart.scala:51)
at play.core.server.ProdServerStart$.main(ProdServerStart.scala:25)
at play.core.server.ProdServerStart.main(ProdServerStart.scala)
It uses jackson ModelConverter and crashes whole plugin.
When can we expect release 1.0.3 with new version of jackson-module-scala 2.8.4?
When can a release version be created and deployed to maven central?
The swagger-maven-plugin would like to include this module in its next release.
https://github.com/kongchen/swagger-maven-plugin
/cc @kongchen
jeff
When can we expect release for scala 2.12?
Hi,
Would it be possible to package up the items on the develop branch and release a 1.0.1 jar to maven central?
Thanks,
PJ
Hello, when converting Option[BigDecimal] the output is not as expected, the whole BigDecimal object gets converted. My expectation would be a optional number as BigDecimal converts to number since #13.
When debugging the nextType
passed to chain.next().resolveProperty(...)
is scala.math.BigDecimal but in resolveProperty
the type
will be java.math.BigDecimal after chain.next()
is called.
I couldn't find a fix for this. When extending if (cls.isAssignableFrom(classOf[BigDecimal]))
like this if (cls.isAssignableFrom(classOf[BigDecimal]) || cls.isAssignableFrom(classOf[java.math.BigDecimal]))
the error persists.
I have a partial implementation ( https://github.com/swagger-api/swagger-scala-module/compare/develop...pjfanning:swagger-core-2.0.0?expand=1 )
The issues are:
required
setting for schema properties (API change in swagger-core 2.0.0; you need to set a list of required items on the parent property, but the ModelConverter doesn't have access to the parent property)The README
usage example targets the snapshot, which is incorrect since the released version is 1.0.0. The example line will not currently work in a .sbt
file.
Scala 2.13.0 has been released, it would be great to publish a cross compiled version.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.