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

Adds examples to schema.json and OpenAPI outputs #3737

Merged
merged 12 commits into from
Mar 12, 2025
Merged

Conversation

siamakp-elastic
Copy link
Contributor

@siamakp-elastic siamakp-elastic commented Feb 6, 2025

This feature scans All the API folders in the specification to locate API request and response examples. It then adds the 'examples' info to schema.json and to the OpenAPI JSON files.

@siamakp-elastic siamakp-elastic requested a review from a team as a code owner February 6, 2025 16:23
@pquentin pquentin changed the title This featre scans All the API folders in the specfication to locate API request and response examples. It then adds the 'examples' info to schema.json and to the OpenAPI JSON files. Adds examples to schema.json and OpenAPI outputs Feb 11, 2025
@swallez swallez self-requested a review February 11, 2025 13:51
Comment on lines 272 to 277
value?: string
external_value?: string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add doc-comments explaining what these are.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment above the class references the OpenAPI spec page which fully explains the fields.

https://spec.openapis.org/oas/v3.1.0#example-object

let mut openapi_examples = indexmap! {};
for (name, schema_example) in schema_examples {
let openapi_example = Example {
value: Some(json!(schema_example.value)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will output the example as a JSON string, e.g. "value": "{\"foo\":\"bar\"}" instead of "value": {"foo": "bar"}.

Is this what we want? The OpenAPI spec shows that this should be a value and not a value-in-a-string.

Copy link
Contributor

@lcawl lcawl Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a docs point of view, it doesn't seem to matter. For example when I run our current overlays, I get both variations and they both publish fine. For example:

 "ClusterPutComponentTemplateRequestExample1": {
        "summary": "Create a template",
        "value": {
          "template": null,
          "settings": {
            "number_of_shards": 1
          }...

as well as:

     "ClosePointInTimeResponseExample1": {
        "description": "A successful response from `DELETE /_pit`.",
        "value": "{\n  \"succeeded\": true, \n  \"num_freed\": 3     \n}"
      },

If one of these is preferable from a client point of view, that would be good to know. Otherwise from a docs point of view I'm good with whatever is easiest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the example files, I commonly saw JSON strings, but there were also instances of YAML objects. For consistency, I have converted everything to JSON strings.

@lcawl lcawl force-pushed the feature/openapi-examples branch from 7689d65 to ba16216 Compare March 7, 2025 02:51
@lcawl
Copy link
Contributor

lcawl commented Mar 7, 2025

I've rebased and marked the resolved comments... I think this is ready for re-evaluation

@swallez swallez force-pushed the feature/openapi-examples branch from 17dfe3e to b594e24 Compare March 12, 2025 16:25
@swallez swallez merged commit e9bc80f into main Mar 12, 2025
10 checks passed
@swallez swallez deleted the feature/openapi-examples branch March 12, 2025 16:32
Copy link
Contributor

The backport to 8.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-8.x 8.x
# Navigate to the new working tree
cd .worktrees/backport-8.x
# Create a new branch
git switch --create backport-3737-to-8.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 e9bc80f1c92fcfa3dd2dae3deb87177b0855e35a
# Push it to GitHub
git push --set-upstream origin backport-3737-to-8.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-8.x

Then, create a pull request where the base branch is 8.x and the compare/head branch is backport-3737-to-8.x.

Copy link
Contributor

The backport to 8.18 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-8.18 8.18
# Navigate to the new working tree
cd .worktrees/backport-8.18
# Create a new branch
git switch --create backport-3737-to-8.18
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 e9bc80f1c92fcfa3dd2dae3deb87177b0855e35a
# Push it to GitHub
git push --set-upstream origin backport-3737-to-8.18
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-8.18

Then, create a pull request where the base branch is 8.18 and the compare/head branch is backport-3737-to-8.18.

Copy link
Contributor

The backport to 9.0 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-9.0 9.0
# Navigate to the new working tree
cd .worktrees/backport-9.0
# Create a new branch
git switch --create backport-3737-to-9.0
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 e9bc80f1c92fcfa3dd2dae3deb87177b0855e35a
# Push it to GitHub
git push --set-upstream origin backport-3737-to-9.0
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-9.0

Then, create a pull request where the base branch is 9.0 and the compare/head branch is backport-3737-to-9.0.

swallez added a commit that referenced this pull request Mar 12, 2025
* This featre scans All the API folders in the specfication to locate API request and response examples. It then adds the 'examples' info to schema.json and to the OpenAPI JSON files.

---------

Co-authored-by: Lisa Cawley <lcawley@elastic.co>
Co-authored-by: Sylvain Wallez <sylvain@elastic.co>
swallez added a commit that referenced this pull request Mar 12, 2025
* This featre scans All the API folders in the specfication to locate API request and response examples. It then adds the 'examples' info to schema.json and to the OpenAPI JSON files.

---------

Co-authored-by: Lisa Cawley <lcawley@elastic.co>
Co-authored-by: Sylvain Wallez <sylvain@elastic.co>
swallez added a commit that referenced this pull request Mar 12, 2025
* This featre scans All the API folders in the specfication to locate API request and response examples. It then adds the 'examples' info to schema.json and to the OpenAPI JSON files.

---------

Co-authored-by: Siamak Poursabahian <siamak.poursabahian@elastic.co>
Co-authored-by: Lisa Cawley <lcawley@elastic.co>
swallez added a commit that referenced this pull request Mar 12, 2025
* This featre scans All the API folders in the specfication to locate API request and response examples. It then adds the 'examples' info to schema.json and to the OpenAPI JSON files.

---------

Co-authored-by: Lisa Cawley <lcawley@elastic.co>
Co-authored-by: Sylvain Wallez <sylvain@elastic.co>
swallez added a commit that referenced this pull request Mar 12, 2025
* This featre scans All the API folders in the specfication to locate API request and response examples. It then adds the 'examples' info to schema.json and to the OpenAPI JSON files.

---------

Co-authored-by: Siamak Poursabahian <siamak.poursabahian@elastic.co>
Co-authored-by: Lisa Cawley <lcawley@elastic.co>
swallez added a commit that referenced this pull request Mar 12, 2025
* This featre scans All the API folders in the specfication to locate API request and response examples. It then adds the 'examples' info to schema.json and to the OpenAPI JSON files.

---------

Co-authored-by: Siamak Poursabahian <siamak.poursabahian@elastic.co>
Co-authored-by: Lisa Cawley <lcawley@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants