-
Notifications
You must be signed in to change notification settings - Fork 422
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
Generate OpenAPI documentation from EndpointSpec data type #1498
Comments
I'll try to do this one |
A subproblem here is to merely translate This can be done by adding Work can be checked by, for example, inspecting the JSON output or converting it to PDF or other form intended for human consumption. |
Hi John, I hope you do not mind providing more detail on the ticket. OpenAPIBase is private so it is not accessible in EndpointSpec. I made it public but EndpointSpec is a case class. I got the error: class EndpointSpec needs to be abstract. Missing implementation for: That would lead to generating the OpenApi as a complete object as:
In this case, how do I go about extracting the data from EndpointSpec to fill up OpenAPI? It is pretty challenging to extract data from the generics in EndpointSpec[Input, Output]. On the HttpCodec side, I am looking at the most obvious to get started and I do see: private[api] final case class Body[A](schema: Schema[A]) extends Atom[CodecType.Body, A] which could be required to return OpenApi's final case class RequestBody(description: Doc, content: Map[String, MediaType], required: Boolean = false) Can you point me to where I can find out how I can pull out Doc, Map[String, MediaType] and required flag from schema passed in? Thank you for your help. |
@wpoosanguansit the |
@jdegoes
What do you think? |
FYI, I created some models for openAI |
@fancellu We have already a model for OpenAPI in zio-http at Also I think what needs improvement here is more likely the zio-http internal representation of endpoints. The OpenAPI model should be in an okay(ish) state. |
/bounty $500 |
💎 $500 bounty created by jdegoes
|
I am on it 🙂 |
@987Nabil I don't know if this helps but I maintain https://github.com/swagger-akka-http/swagger-scala-module This lib supports OpenAPI3 and basically generates Open API models for Scala classes. I have some related libs for non-core Scala classes. Even if this lib is not useful to you, I would be interested in looking at any alternative solution you use for generating Open API models - as I might be able to learn something that could be useful in swagger-scala-module. |
Hey @pjfanning! Thanks for the hint. But I think this are two different approaches to the problem. We are actually not analysing the Scala data structures itself, but only a |
@987Nabil Sounds like you have a good idea of how to proceed. It would be nice to be able to provide a partial definition of the OpenAPI doc when requesting the full doc. The EndpointSpec can provide details to generate server details, API details, model details, etc. There is a fair amount of metadata you should include in an OpenAPI doc though - for instance, the 'Info' object in https://swagger.io/specification/. |
@pjfanning We have already a domain model for the OpenAPI spec in zio-http. Including |
Any updates on this? |
@kitlangton: Reminder that in 7 days the bounty will become up for grabs, so please submit a pull request before then 🙏 |
💡 @987Nabil submitted a pull request that claims the bounty. You can visit your org dashboard to reward. |
…2470) * Improve OpenAPI model; Add OpenAPI generator for EndpointAPI (#1498) * Minimize schema for optional fields * Integrate main changes * Fix Scala 3 build * Fix exhaustive matching * More OpenAPI generation tests * Use latest zio-schema snapshot for Scala 3 macro derivation fix * Formatting * OpenAPI tests now compare json ASTs, to avoid string render differences * Refactoring * improve docs (#2482) * Add a test of a middleware providing a context to a `Routes` (#2487) * Add a test of a middleware providing a context to a `Routes` * Add a test of a middleware providing a context to a `Routes` * scalafmt * scalafmt * Remove usage of deprecated method in build.sbt (#2486) * Update sbt-github-actions to 0.18.0 (#2484) * Update sbt-github-actions to 0.18.0 * Regenerate GitHub Actions workflow Executed command: sbt githubWorkflowGenerate * Update netty-codec-http, ... to 4.1.100.Final (#2485) * Generate readme * OpenAPI gen support for all kinds of enums with(out) discriminators OpenAPI gen support for default values, optional and transient fields --------- Co-authored-by: TomTriple <mail@tomhoefer.de> Co-authored-by: Jules Ivanic <jules.ivanic@gmail.com> Co-authored-by: Scala Steward <43047562+scala-steward@users.noreply.github.com>
🎉🎈 @987Nabil has been awarded $500! 🎈🎊 |
Is your feature request related to a problem? Please describe.
The
zio.http.api.EndpointSpec
contains a declarative description of an API endpoint, while theServiceSpec
data type contains a declarative description of more than one API endpoints.These declarative descriptions are wholly sufficient to generate extremely good OpenAPI documentation for the endpoints. Yet, this is a feature that is wholly missing in the current version of
zio.http.api
.Describe the solution you'd like
Add a method
EndpointSpec#toOpenAPI
, which translates the route, query parameter, header, input and output, into thezio.http.api.openapi.*
family of data types, incorporating the custom documentation that may be included into theEndpointSpec
or into one of theHttpCodec
values that make up its description of the input.Describe alternatives you've considered
N/A
Additional context
This ticket does not include translating the OpenAPI values into HTML or JSON, which is considered outside the scope of this ticket. This ticket is merely to translate the
EndpointSpec
data type into typed OpenAPI values.A separate ticket will cover the generation of JSON (etc.) from the OpenAPI data types.
The text was updated successfully, but these errors were encountered: