Coder Social home page Coder Social logo

swagger-scala-module's People

Contributors

dwickern avatar fehguy avatar frantuma avatar frosforever avatar pculligan avatar pjfanning avatar ponelat avatar ralphdoe avatar sullis avatar webron avatar yaronyam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swagger-scala-module's Issues

case class with field option[Int] is resolved as object and not Number

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

@pjfanning , @fehguy

There are any solution for it ?

Thanks !

Swagger scala model description missing

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.

Scala primitives inside a List become "Object"

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.

Non-option-wrapped @ArraySchema-fields are always required

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.

collectionFormat value ignored

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

Support traits

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.

Option properties are not described correctly, and all properties are being described as optional

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).

ModelConverter fails on certain class definitions due to Java 8 and below limitations.

    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.

Option[scala.math.BigDecimal] not working as expected

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.

Usage wrong in README

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.