Git Product home page Git Product logo

Comments (7)

joprice avatar joprice commented on June 16, 2024

This may have been addressed by #48. Can you test with a recent version?

from play-swagger.

pettyjamesm avatar pettyjamesm commented on June 16, 2024

Would it be possible to verify this fix and publish a new version? The latest published release is definitely still impacted the issue (using Play 2.5).

from play-swagger.

joprice avatar joprice commented on June 16, 2024

Currently the generate method takes a string of the routes file and reads it as a resource from the classpath. You should be able to call it with generate("api.routes"). However, I think we could improve this interface by having another method that takes an implicit application and looks up the value of play.http.router from the application's configuration. This is likely the most common usage. @kailuowang thoughts?

from play-swagger.

kailuowang avatar kailuowang commented on June 16, 2024

@joprice let's see if @pettyjamesm will be okay with the new generate interface (you can read the root routes file name yourself). I would hesitate adding play application as an dependency.

from play-swagger.

pettyjamesm avatar pettyjamesm commented on June 16, 2024

@joprice I'm not sure exactly how that would work. Are you saying that by default it would parse the whole routing tree?

Hooking to the root application router is definitely useful for determining the accurate HTTP paths, but I wouldn't necessarily assume that all routes should be mapped. For instance, my root routes file looks like this:

# Misc Non-API routes that serve dashboards, etc
GET /   @controllers.HomeController.index
.... more of these omitted ...

# API docs
GET /docs                       @controllers.ApiDocController.redirectToDocs
GET /docs/swagger.json          @controllers.ApiDocController.fullSpecs
GET /docs/swagger-ui/index.html @controllers.ApiDocController.swaggerHome
GET /docs/swagger-ui/*file      @controllers.ApiDocController.swaggerResource(file)

# API resources
->  /api/v1/charge      charge.Routes
->  /api/v1/cart        cart.Routes
->  /api/v1/inventory   inventory.Routes
->  /api/v1/purchase    purchase.Routes

Currently I've made the /docs/swagger.json route call into generate once per sub-route and then I manually merge the generated JSON together and fix the http paths. It kinda works, but it's definitely kludgy. Is that helpful?

from play-swagger.

kailuowang avatar kailuowang commented on June 16, 2024

@pettyjamesm , yes by default it will recursively parse the whole tree.
For now, there are two work around in your case

  1. add ### NoDocs ### to all the routes you don't want to include.
    or 2) have an api.routes file in which you can have
->  /v1/charge      charge.Routes
->  /v1/cart        cart.Routes
->  /v1/inventory   inventory.Routes
->  /v1/purchase    purchase.Routes

And have do generate("api.routes") and then add a root path /api to your swagger.yml file.

from play-swagger.

pettyjamesm avatar pettyjamesm commented on June 16, 2024

@joprice The 2nd workaround is totally fine with me. I just wanted I way to isolate the API resources from the other routes.

Given that my preferred approach is going to be the second option, I think you can proceed with whatever you'd like for the application router traversal.

from play-swagger.

Related Issues (20)

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.