Closed VachaShah closed 7 months ago
Will raise a PR soon for publishing specs.
We have a number of ongoing PoCs [1], [2], [3] to try out client generation for different programming languages and specs (Smithy, OpenAPI). We are still debating on what is the best approach here (should we use Smithy, OpenAPI or something else completely) but I think the one large key problems is not getting enough attention: crafting the Smithy / OpenAPI / ... specs.
As far as I can tell, all our PoCs craft them by hand, including this repo [4], this is huge effort. But we already have a large chunk of API specs here https://github.com/opensearch-project/OpenSearch/tree/main/rest-api-spec/src/main/resources/rest-api-spec/api, inherited from Elasticsearch. Shouldn't we consider to benefit from it and try to convert them into Smithy / OpenAPI specs?
[1] https://github.com/opensearch-project/opensearch-java/pull/336 [2] https://github.com/opensearch-project/opensearch-java/pull/318 [3] https://github.com/opensearch-project/opensearch-ruby/issues/139 [4] https://github.com/opensearch-project/opensearch-api-specification/tree/main/model
@reta Absolutely! I missed adding that in my proposal that we can explore on how rest-api-spec
can be used to programmatically generate Smithy/OpenAPI specs. Currently, while writing models in this repo, I do look at rest-api-spec
to get a better understanding of the API and figure out the missing pieces that are not reflected in rest-api-spec
to complete the models.
Let me add it in this in the proposal too.
Late to this issue, but had some thoughts.
First, it may be easier to think of API specs being built, released, and follow semver that can match what they specify if that relationship is 1:1, or have their own version if it's 1:many. This way if a mistake was made in the specs for OpenSearch 2.6.0, it can be corrected, but we can distinguish API specs between before and after correction. I envision that this repo gets built and released, possibly just on GitHub. IMO this step is missing from the above proposal.
The GitHub pages hosted website can be a result of publishing a released version of the API specs and I like the idea of enabling it to be consumed by a Swagger UI.
We have this workflow in most clients now, closing.
What/Why
What are you proposing?
A build architecture for API spec generation and code generation for OpenSearch.
Description
Smithy models in this repo are used to generate Smithy and OpenAPI specs for the OpenSearch APIs. Smithy is an open source IDL which is protocol agnostic, extensible and supports code generation. (See https://github.com/opensearch-project/OpenSearch/issues/1590) Smithy models are converted to Smithy and OpenAPI specs during build. These specs can be hosted to view and edit and further be used for client and server generation.
What users have asked for this feature?
34
What problems are you trying to solve?
What is the developer experience going to be?
What is the user experience going to be?
Publish OpenSearch API specs
This proposal talks about hosting OpenSearch API specs on Github Pages. A Github workflow will be triggered when a change is made to the Smithy models. This workflow will build the models and if there is a change to the API specs, it will create a pull request to update the specs hosted in the repo and in turn update the specs on Github Pages. OpenAPI specs will be available to view using Swagger UI.
Similar process can be followed for hosting Smithy specs.
Other options explored
Client Generation
Using the above hosted API specs, client APIs can be generated using an open-api generator or a custom generator. Smithy specs can be used to generate APIs using smithy language generators. Client generators will reside in each client repo. Although what kind of generators can be used to generate clients is a separate proposal for each client (see https://github.com/opensearch-project/opensearch-java/issues/284, https://github.com/opensearch-project/opensearch-ruby/issues/139) which is out of scope for this proposal, this proposal talks about linking the process of how a change in API specs results in incremental API generation for clients.
A Github workflow in each client will be triggered when a change is detected in the API specs (a workflow in one repository can trigger an action in another repository see https://github.com/orgs/community/discussions/26323). The workflow will run the generator using the hosted API specs and a pull request will be created by the workflow to update the generated code.
TODO: Once a generator is ready for a client, implement CI for the client as mentioned above.
Server Route Generation
Similar CI workflow like client generation can be used for server route generation. The generators for server are out of scope of this proposal.
Why should it be built? Any reason not to?
What will it take to execute?
Any remaining open questions?
OpenSearch
repo so they are a better representation of the server or should they live inopensearch-api-specification
as a separate entity which represents both server and clients?rest-api-spec
to create Smithy/OpenAPI specs? - To benefit from the already existing rest-api-spec, a PR is out which converts the rest-api-spec to Smithy models using a translator.