jakehschwartz / finatra-swagger

Swagger Support For Finatra
https://jakehschwartz.github.io/swagger-finatra
Apache License 2.0
28 stars 19 forks source link

Build time OAS json generation? #42

Open brisssou opened 4 years ago

brisssou commented 4 years ago

Hello, I'd like to be able to get the json spec at build time. (the title may have spoiled it, sry). I'm trying to dig into how the io.swagger.models.Swagger is filled.

Thanks!

jakehschwartz commented 4 years ago

Hey @brisssou, do you need it build time for something specific? If you just want to examine the json, you should be able to use the GET /swagger.json route in the DocsController to get the json. Let me know!

brisssou commented 4 years ago

I'd like to have the spec so I can use it to generate the clients I need, on the CI, matching the merged server code.

jakehschwartz commented 4 years ago

Interesting problem. I could look into it, but I doubt it is possible with the current set up because the Swagger object is created at runtime. When Controllers are added to the Server, the blankWithDoc functions are called and add the route to the Swagger object.

You might be able to create a step within your CI to start your server, call the endpoint to get your json and then build your clients?

mgd43b commented 4 years ago

You could do something like a pre commit step that would start a test that has an embedded server in it, and then dump out the json to a file.

see https://github.com/jakehschwartz/finatra-swagger/blob/71683ef93c4caf7c681a9e28dc7dbbc47d27867d/examples/hello-world/src/test/scala/com/jakehschwartz/finatra/swagger/DocsControllerTest.scala#L12 for an example of how to do the embedded server part in the codebase.

brisssou commented 4 years ago

I'm looking into this. The embedded server seems like something to be leveraged.

Le ven. 28 févr. 2020 à 20:05, mgd43b notifications@github.com a écrit :

You could do something like a pre commit step that would start a test that has an embedded server in it, and then dump out the json to a file.

see https://github.com/jakehschwartz/finatra-swagger/blob/71683ef93c4caf7c681a9e28dc7dbbc47d27867d/examples/hello-world/src/test/scala/com/jakehschwartz/finatra/swagger/DocsControllerTest.scala#L12 for an example of how to do the embedded server part in the codebase.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jakehschwartz/finatra-swagger/issues/42?email_source=notifications&email_token=AACQWGMTCKZ3FI2WRZVC52DRFFOAPA5CNFSM4K5VPWE2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENJY3QY#issuecomment-592678339, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACQWGL3X3T3ITN5EB5EAPDRFFOAPANCNFSM4K5VPWEQ .

xcv58 commented 4 years ago

Another benefit of Build time OAS JSON generation: it will prevent accidentally version bump which might pass the compilation but fail on server startup like this one: https://github.com/jakehschwartz/finatra-swagger/issues/53#issue-643441398

brisssou commented 4 years ago

Hello, we have something that kinda works, with an older version of the project, though it should be compatible with any version. It actually starts a server. I will try to provide a PR soon-ish.

mgd43b commented 2 years ago

@brisssou - just wondered if you still had plans for a PR?

brisssou commented 2 years ago

Actually yes, but you can guess with my answer latency, that I don't have much time. I swear I will try to come up with something before summer.

The idea is to either have a way of launching your app without dependencies (here, read online services that your app may call) or split your controllers in annotated interfaces and implementation and have a piece of code (the part I want to contribute) to be able to automatically provide implementation from interfaces, launch a server, call the endpoint serving the OAS and store it.