-
Notifications
You must be signed in to change notification settings - Fork 80
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 schema for Elasticsearch Serverless #2047
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is excellent, nice work @swallez! Left a few comments inline, some may not make sense due to unfamiliarity with Rust and this code:
Following you can find the validation results for the APIs you have changed.
You can validate these APIs yourself by using the |
c312f00
to
ad93d9a
Compare
ad93d9a
to
22c046e
Compare
Great stuff @swallez 👏 I notice that there are a few errors (denoting actual issues with the produced formatting, rather than "nice to have"s) when linting the generated OpenAPI with https://github.com/stoplightio/spectral - just wondering if you're aware of or are validating the schema with any other tools? Looks like it's largely the following buckets:
There are also some circular references that may break some OpenAPI libraries (it appears to break https://github.com/getkin/kin-openapi) |
a48c7d6
to
915dd15
Compare
@jamietanna thanks for the pointer, Spectral is a great linter, picky as it should. The conversion code has been updated and the linter is happy. The OpenAPI output now comes in two flavors, stack (full API) and serverless. I still have to implement a few |
Awesome stuff @swallez 👏 Appreciate the tweaks. A couple of plumbing points to note: I believe the circular references may still be an issue (in
Some other validators (like There appears to be a clash in one of the related Key errors I can see in Spectral are:
It loosk like I also note that we've got generated code like: "/_async_search/{id}": {
"get": {
"description": "Retrieves the results of a previously submitted async search request given its ID.",
"externalDocs": {
"url": "https://www.elastic.co/guide/en/elasticsearch/reference/current/async-search.html"
},
"operationId": "async_search.get#0", and "schemas": {
"_types:Id": {
"type": "string"
}, Is there anything we can do to maybe massage these into more human-readable names? This may make the generated code that's used with these a little better. |
@jamietanna thanks for the feedback. Regarding the failure of linters and code generators, this has to be put of into perspective with the context and and purpose of this conversion:
Regarding the other points you mention:
|
915dd15
to
3f9daef
Compare
1a1b5b4
to
11d15f3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd change the name of the main directory from openapi-converter
to something meaningful like compiler-rs
. There's much more than OpenApi in that folder.
Except for a nit left in a comment, looks great!
} | ||
|
||
#[derive(Debug, Clone, PartialEq, ValueEnum)] | ||
pub enum SchemaFlavor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not reuse the values from client_schema::Flavor
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we're likely to have a Common
code generation target in the future (currently commented-out) that will be used to retain what's in both Stack and Serverless. So client_schema::Flavor
represents the @availability
annotation whereas here this represents the generation flavor that can be different from a simple XOR between Stack and Serverless.
This PR adds a converter from
schema.json
to OpenAPI for Elasticsearch serverless.make contrib
now produces theoutput/openapi/elasticsearch-serverless-openapi.json
file.This converter is written in Rust. To ensure a smooth integration with our existing tooling, the Rust code is compiled to WebAssembly with a JavaScript binding using wasm-pack that exploses the OpenAPI generation function.
As part of this, the
clients-schema
crate provides a complete implementation of theschema.json
metamodel along with utilities and common transformation functions such as generics expansion and flavor (stack/serverless) filtering.