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

Is there any way to generate swagger-ui endpoints? #1418

Open
alexklibisz opened this issue Mar 5, 2022 · 3 comments
Open

Is there any way to generate swagger-ui endpoints? #1418

alexklibisz opened this issue Mar 5, 2022 · 3 comments
Labels
documentation question A question about usage, not necessarily requiring code changes. May involve documentation.

Comments

@alexklibisz
Copy link

Hi, neat project!

I just want to see if there is some way to generate the Swagger UI HTML/CSS/JS artifacts that need to be served up in order to get Swagger UI running?

@blast-hardcheese
Copy link
Member

Hey Alex, thanks!

I know others at Twilio spent some time getting that working in-house, but it never made it to OSS.

The mission statement of this project is to ensure it's as easy as possible to follow your specification in a type-safe and idiomatic way, while exposing the underlying routing infrastructure for whatever framework you're using. The latter being a great launching off point for integrating with other stuff (the output of a dedicated swagger-ui plugin, existing routing infrastructure that hasn't been converted to guardrail yet, etc)

I'm not opposed to it, I just don't know what that would look like.

@blast-hardcheese blast-hardcheese added question A question about usage, not necessarily requiring code changes. May involve documentation. documentation labels Mar 6, 2022
@alexklibisz
Copy link
Author

Thanks Devon. I did a bit more digging. I think it might be better to keep this out of guardrail. There are a few scala/swagger-ui integrations floating around, but I actually think something like this might be simpler..

Expose the openapi yaml through the server, something like:

val appRoutes: Route = PetResource.routes(...)
val docsRoutes: Route = path("openapi.yaml") {
    getFromResource("petstore.yaml", ContentType(MediaType.customWithFixedCharset("text", "vnd.yaml", `UTF-8`)))
  }
 Await.result(Http().newServerAt("0.0.0.0", 8080).bindFlow(appRoutes ~ docsRoutes), Duration.Inf)

Then just run the swagger-ui docker container and point it at the https://<my service>/openapi.yaml URL.

Spinning up an official docker container is a lot easier than messing with the various language-specific swagger-ui server implementations.

So, maybe the only thing that would be useful to implement in guardrail is the ability to copy the openapi yaml spec into src_managed. That would make it easier to serve the openapi spec from a dockerized akka-http server. Otherwise, we'd have to either remember to copy it into the container, or mount it, or would have to keep it in src/main/resources.

@blast-hardcheese
Copy link
Member

That's not out the realm of possibility, it would go well alongside the different kinds we support, to go alongside client, server, and models. Probably spec, though that's available for bikeshedding.

One possible benefit is that by round-tripping through the OpenAPI parser, I presume it would inline all cross-file references and omit unexpected or unusable fields. External file references was an issue we dealt with when trying to do swagger-ui, iirc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation question A question about usage, not necessarily requiring code changes. May involve documentation.
Projects
None yet
Development

No branches or pull requests

2 participants