-
Notifications
You must be signed in to change notification settings - Fork 98
Add x-codeSamples to generated OpenAPI #4371
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
base: main
Are you sure you want to change the base?
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.
Thank you! This will vastly improve the docs experience.
I'm sure the many if let Some
can be improved, but at least the code is readable. Left two questions.
let mut code_samples = vec![]; | ||
if let Some((_, first_example)) = request_examples.clone().first() { | ||
if let Some(example) = first_example.as_item() { | ||
if let Some(description) = example.description.clone() { |
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.
Could we use summary
when description
is not set?
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 feature does not need summaries or descriptions, all I'm doing here is parsing the description text with the hope that somewhere within it I can find the method and URL of the request. The only reason I'm using description
is because that is how these examples are parsed.
The proper thing to do would be to expand these examples to include this information in a easier format, at which point there wouldn't be a need to use descriptions or summaries for anything.
if r.starts_with("GET ") | ||
|| r.starts_with("POST ") | ||
|| r.starts_with("PUT ") | ||
|| r.starts_with("DELETE ") | ||
|| r.starts_with("HEAD ") | ||
{ | ||
request = Some(String::from(r)); | ||
break; | ||
} |
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.
Do we have examples that don't start with a method? QUERY will be a thing soon!
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 really a hack. I hope we don't have to do this. The problem is that the examples that were added to this repository are not clean Dev Console examples, so I'm forced to reconstruct the DevConsole syntax.
NOTE: this is not only a proof of concept but also a work in progress. DO NOT MERGE!
This change adds the
x-codeSamples
extension to the endpoints that have at least one example. AConsole
listing is added using the standard Kibana DevConsole syntax. Not implemented yet, but the idea is to run this DevConsole example through the request converter to generate versions of the example in all the supported languages.