xiaodongw / swagger-finatra

Finatra Swagger Support
Apache License 2.0
46 stars 45 forks source link

Filter finatra annotations in bodyParam #25

Closed devshorts closed 7 years ago

devshorts commented 7 years ago

If you have a body param of:

case class PingPostRequestWithRoute(
   @RouteParam name: String,
  data: String
)

And a controller of:

postWithDoc("/api/v1/ping/:name") {
    _.responseWith[PingResponse](200).
      routeParam[String]("name").
      summary("Ping").bodyParam[PingPostRequestWithRoute]("body").
      tag("test")
  } { request: PingPostRequestWithRoute =>

    PingResponse(request.data + thing.name)
  }

The correpondsing swagger body has image

Which incorrectly uses the route param. This has even more repercussions when you have an @Inject request: Request param since it blows up the jackson introspection

To work around this you have to add a class level annotation

JsonIgnoreProperties(Array("fieldName"))

To the payload class. This means that you have to type the route/query/body fields 3 times to get it to properly register. Once in the json ignore, once in the swagger param, and once in the actual payload class

Can we filter these properties or provide a more unified way of registering the params? The finatra way seems to create a single object representing the entire request (queryparams/routeparams/bodyparams). If we could generate the swagger off of that by adding in extra annotations (like the way jersey/dropwizard does it) that would be killer

Maybe something like:

case class PingPostRequestWithRoute(
   @Description("The name for the route")  @RouteParam name: String,
   @Description("The body payload") data: String
)
postWithDoc("/api/v1/ping/:name") {
    _.responseWith[PingResponse](200).    
      summary("Ping").
      request[PingPostRequestWithRoute]. // enough metadata is here to build the swagger request info
      tag("test")
  } { request: PingPostRequestWithRoute =>

    PingResponse(request.data + thing.name)
  }
devshorts commented 7 years ago

I'm trying to help prototype this feature in a fork, but running into some issues running the sampel app with webjars. I can run the app fine locally but the web jars input resource never loads since the META-INF folder doesn't get popualted by intellij

when running command line


$ gradle runSampleApp
Starting a Gradle Daemon, 1 busy Daemon could not be reused, use --status for details
Scala Version: 2.11.8
Scala Version Main: 2.11
Finatra Version: 2.6.0
:compileJava UP-TO-DATE
:compileScala UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:compileTestScala UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:runSampleApp
Dec 15, 2016 6:32:41 PM com.twitter.finagle.http.HttpMuxer$$anonfun$4 apply
INFO: HttpMuxer[/admin/metrics.json] = com.twitter.finagle.stats.MetricsExporter(<function1>)
Dec 15, 2016 6:32:41 PM com.twitter.finagle.http.HttpMuxer$$anonfun$4 apply
INFO: HttpMuxer[/admin/per_host_metrics.json] = com.twitter.finagle.stats.HostMetricsExporter(<function1>)
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
> Building 88% > :runSampleApp```

It just sort of hangs there. Any suggestions? 
xiaodongw commented 7 years ago

I just merged a fix for the swagger UI, please get the latest code.

When you see "Building 88% > :runSampleApp", the sample app actually is ready, you can go to http://localhost:8888/api-docs/ui in browser.

devshorts commented 7 years ago

I think its safe to close this