Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paths ordering #34

Closed
carlsonngo opened this issue Dec 9, 2015 · 14 comments
Closed

Paths ordering #34

carlsonngo opened this issue Dec 9, 2015 · 14 comments
Labels

Comments

@carlsonngo
Copy link
Contributor

Generated JSON paths is in reverse order compared to ones defined in routes file

@kailuowang kailuowang added the bug label Dec 9, 2015
@kailuowang
Copy link
Member

@carlsonngo thanks for reporting, I am curious how important this order is to you?

@carlsonngo
Copy link
Contributor Author

Feeding the data to swagger-ui will display the paths in the wrong order. This might be confusing for people if they want to preserve the order in the generated api docs.

@kailuowang
Copy link
Member

@carlsonngo thanks for the context.

@slouc
Copy link

slouc commented Jun 7, 2016

+1 For me it's not even reverse order, but a completely random one. Using 0.2.0.

@bilongc
Copy link

bilongc commented Aug 30, 2016

+1 for me, it is displayed as random order. Using play 2.5.4, play-swagger 0.5.0

@tculshaw
Copy link
Contributor

So how do we order, using play 2.5.x, play-swagger 0.5.3? Looks random to me.

@kailuowang
Copy link
Member

@tculshaw we haven't implement the feature the preserve the ordering in the routes file. Any PR will be more than welcome :)

@tculshaw
Copy link
Contributor

tculshaw commented Mar 20, 2017

If any one is interested I have a partial solution, hence this isn't a formal pull request.

Replacing the path function in SwaggerSpecGenerator, I order the main unique paths as per the ROUTE file, but NOT the order where multiple methods (GET,PUT,POST,DELETE) apply to the same path. It's a lot better than it used to be, and will suffice for my needs, but still not quite 100%!

private def paths(routes: Seq[Route], prefix: String, tag: Option[Tag]): JsObject = {
    JsObject {
      val endPointEntries = routes.flatMap(route => endPointEntry(route, prefix, tag))
      val zgbp = endPointEntries.zipWithIndex.groupBy(_._1._1)
      import collection.mutable.LinkedHashMap
      val lhm = LinkedHashMap(zgbp.toSeq sortBy (_._2.head._2): _*)
      val gbp2 = lhm mapValues (_ map (_._1)) toSeq
      gbp2.toSeq.map( x => (x._1,x._2.map(_._2).reduce(_ deepMerge _)))
    }
 }

I banged my head against the wall to get this going, so hope this is helpful to somebody!

@kailuowang
Copy link
Member

Thanks very much @tculshaw, it's not quite 100% but it's still a step forward. I will appreciate it if you want to submit a PR (just need a simple test for the ordering).

@tculshaw
Copy link
Contributor

tculshaw commented Apr 5, 2017

This can now be closed? Thanks for accepting my change #152

@kailuowang
Copy link
Member

@tculshaw it's still a partial solution right? ("NOT the order where multiple methods (GET,PUT,POST,DELETE) apply to the same path")

@tculshaw
Copy link
Contributor

tculshaw commented Apr 7, 2017 via email

@kailuowang
Copy link
Member

I imagine it would be nice for some users, but I don't particularly have that need in my projects. Thanks for offering! And thanks again for your contribution!

@tculshaw
Copy link
Contributor

tculshaw commented Apr 7, 2017 via email

Javakky-pxv added a commit to scala-steward/play-swagger that referenced this issue Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants