Skip to content

[Fleet] remove old bundled.yaml from oas, fixed tags#194788

Merged
juliaElastic merged 16 commits intoelastic:mainfrom
juliaElastic:oas-fleet
Oct 7, 2024
Merged

[Fleet] remove old bundled.yaml from oas, fixed tags#194788
juliaElastic merged 16 commits intoelastic:mainfrom
juliaElastic:oas-fleet

Conversation

@juliaElastic
Copy link
Copy Markdown
Contributor

@juliaElastic juliaElastic commented Oct 3, 2024

Summary

Closes #184685

Release notes: These schema changes shouldn't be breaking, but there were some incorrect/missing response schemas in the old openapi spec.

For example the API POST /api/fleet/agents/{agentId}/actions response was incorrectly documented: https://petstore.swagger.io/?url=https://raw.githubusercontent.com/elastic/kibana/main/x-pack/plugins/fleet/common/openapi/bundled.json#/Elastic%20Agent%20actions/new-agent-action

{
  "body": [
    0
  ],
  "statusCode": 0,
  "headers": "string"
}

Fixed here: https://petstore.swagger.io/?url=https://raw.githubusercontent.com/elastic/kibana/31f8cfd6efc5e79255fec0dfbc1f735592736dad/oas_docs/bundle.json#/Elastic%20Agent%20actions/%252Fapi%252Ffleet%252Fagents%252F%257BagentId%257D%252Factions%230

{
  "item": {
    "ack_data": "string",
    "agents": [
      "string"
    ],
    "created_at": "string",
    "data": "string",
    "expiration": "string",
    "id": "string",
    "minimum_execution_duration": 0,
    "namespaces": [
      "string"
    ],
    "rollout_duration_seconds": 0,
    "sent_at": "string",
    "source_uri": "string",
    "start_time": "string",
    "total": 0,
    "type": "string"
  }
}

Note: Since the schema changes are only included in main branch (9.x) currently, changing to the openapi spec have to be manually done in the old files in the 8.x branch for backports.

The new spec should match the implementation accurately, and responses are being verified when returned. Tests were added to make sure the response schemas are correct.
If there are any bugs in the current schema, it will result in a HTTP 500 error with an error message on where the schema validation failed.
Example of an error where a field is missing:

{
    "statusCode": 500,
    "error": "Internal Server Error",
    "message": "Failed output validation: [request body.items.0.name]: definition for this key is missing"
}

Example of an error where a field is mandatory in the schema, but not provided in the response (missing schema.maybe)

{
    "statusCode": 500,
    "error": "Internal Server Error",
    "message": "Failed output validation: [request body.items.0.internal]: expected value of type [boolean] but got [undefined]"
}

There are a few places where the validation allows unknown fields. Used it where some fields were not included in TS types or fields are more dynamic, e.g. fields coming from packages or elasticsearch settings.
https://github.com/search?q=repo%3Aelastic%2Fkibana+extendsDeep+path%3A%2F%5Ex-pack%5C%2Fplugins%5C%2Ffleet%5C%2Fserver%5C%2Ftypes%5C%2F%2F&type=code

.extendsDeep({
  unknowns: 'allow',
 })

Changes in this pr:
Remove using old bundled.yaml to generate oas, fixed tags.
Removed old openapi files, updated readme.

Here is the new bundle in Swagger UI:
stateful
serverless

Updated serverless scripts too.

Updated Fleet readme: https://github.com/elastic/kibana/blob/da72ee0093c5a1e164b4a24c5f94333c2376e7cc/x-pack/plugins/fleet/common/openapi/README.md

Generated the new bundle by running this script locally:

node scripts/capture_oas_snapshot --include-path /api/fleet --update
@juliaElastic juliaElastic added release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting labels Oct 3, 2024
@juliaElastic juliaElastic self-assigned this Oct 3, 2024
@juliaElastic juliaElastic requested a review from a team as a code owner October 3, 2024 08:27
@botelastic botelastic Bot added the Team:Fleet Team label for Observability Data Collection Fleet team label Oct 3, 2024
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/fleet (Team:Fleet)

@criamico
Copy link
Copy Markdown
Member

criamico commented Oct 3, 2024

Thanks for adding the deprecations and for taking care of this migration!

Could you add a quick explanation on the readme on how to use this new system for the openapi, the commands etc? It's fine on another PR as well.

Also, is already possible to delete the old openapi specs after this PR is merged?

Copy link
Copy Markdown
Member

@criamico criamico left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@juliaElastic juliaElastic added release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. release_note:enhancement and removed release_note:skip Skip the PR/issue when compiling release notes release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. labels Oct 3, 2024
# OpenAPI

The current self-contained spec file, available [as JSON](https://raw.githubusercontent.com/elastic/kibana/master/x-pack/plugins/fleet/common/openapi/bundled.json) or [as YAML](https://raw.githubusercontent.com/elastic/kibana/master/x-pack/plugins/fleet/common/openapi/bundled.yaml), can be used for online tools like those found at https://openapi.tools/.
There is a new way to generate openapi docs from the route definition in code.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the updated readme!

…t --include-path /api/status --include-path /api/alerting/rule/ --include-path /api/alerting/rules --include-path /api/actions --update'
@juliaElastic juliaElastic requested a review from a team as a code owner October 3, 2024 11:25
kibanamachine and others added 3 commits October 3, 2024 12:09
…t --include-path /api/status --include-path /api/alerting/rule/ --include-path /api/alerting/rules --include-path /api/actions --include-path /api/fleet --update'
…t --include-path /api/status --include-path /api/alerting/rule/ --include-path /api/alerting/rules --include-path /api/actions --include-path /api/fleet --update'
Copy link
Copy Markdown
Contributor

@jbudz jbudz left a comment

Choose a reason for hiding this comment

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

.buildkite/scripts/steps/capture_oas_snapshot.sh

…t --include-path /api/status --include-path /api/alerting/rule/ --include-path /api/alerting/rules --include-path /api/actions --include-path /api/security/role --include-path /api/spaces --include-path /api/fleet --update'
Copy link
Copy Markdown
Contributor

@lcawl lcawl left a comment

Choose a reason for hiding this comment

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

There are linting messages about missing descriptions for responses, for example, but IMO those can be added over time. LGTM

@kibana-ci
Copy link
Copy Markdown

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @juliaElastic

@juliaElastic juliaElastic merged commit 52abebf into elastic:main Oct 7, 2024
tiansivive pushed a commit to tiansivive/kibana that referenced this pull request Oct 7, 2024
## Summary

Closes elastic#184685

**Release notes**: These schema changes shouldn't be breaking, but there
were some incorrect/missing response schemas in the old openapi spec.

For example the API `POST /api/fleet/agents/{agentId}/actions` response
was incorrectly documented:
https://petstore.swagger.io/?url=https://raw.githubusercontent.com/elastic/kibana/main/x-pack/plugins/fleet/common/openapi/bundled.json#/Elastic%20Agent%20actions/new-agent-action

```
{
  "body": [
    0
  ],
  "statusCode": 0,
  "headers": "string"
}
```
Fixed here:
https://petstore.swagger.io/?url=https://raw.githubusercontent.com/elastic/kibana/31f8cfd6efc5e79255fec0dfbc1f735592736dad/oas_docs/bundle.json#/Elastic%20Agent%20actions/%252Fapi%252Ffleet%252Fagents%252F%257BagentId%257D%252Factions%230
```
{
  "item": {
    "ack_data": "string",
    "agents": [
      "string"
    ],
    "created_at": "string",
    "data": "string",
    "expiration": "string",
    "id": "string",
    "minimum_execution_duration": 0,
    "namespaces": [
      "string"
    ],
    "rollout_duration_seconds": 0,
    "sent_at": "string",
    "source_uri": "string",
    "start_time": "string",
    "total": 0,
    "type": "string"
  }
}
```

The new spec should match the implementation accurately, and responses
are being verified when returned. Tests were added to make sure the
response schemas are correct.
If there are any bugs in the current schema, it will result in a HTTP
500 error with an error message on where the schema validation failed.
Example of an error where a field is missing:
```
{
    "statusCode": 500,
    "error": "Internal Server Error",
    "message": "Failed output validation: [request body.items.0.name]: definition for this key is missing"
}
```
Example of an error where a field is mandatory in the schema, but not
provided in the response (missing `schema.maybe`)
```
{
    "statusCode": 500,
    "error": "Internal Server Error",
    "message": "Failed output validation: [request body.items.0.internal]: expected value of type [boolean] but got [undefined]"
}
```

There are a few places where the validation allows unknown fields. Used
it where some fields were not included in TS types or fields are more
dynamic, e.g. fields coming from packages or elasticsearch settings.

https://github.com/search?q=repo%3Aelastic%2Fkibana+extendsDeep+path%3A%2F%5Ex-pack%5C%2Fplugins%5C%2Ffleet%5C%2Fserver%5C%2Ftypes%5C%2F%2F&type=code
```
.extendsDeep({
  unknowns: 'allow',
 })
```

Changes in this pr:
Remove using old `bundled.yaml` to generate oas, fixed tags.
Removed old openapi files, updated readme.

Here is the new bundle in Swagger UI: 

[stateful](https://petstore.swagger.io/?url=https://raw.githubusercontent.com/elastic/kibana/31f8cfd6efc5e79255fec0dfbc1f735592736dad/oas_docs/bundle.json)

[serverless](https://petstore.swagger.io/?url=https://raw.githubusercontent.com/elastic/kibana/da72ee0093c5a1e164b4a24c5f94333c2376e7cc/oas_docs/bundle.serverless.json)

Updated serverless scripts too.

Updated Fleet readme:
https://github.com/elastic/kibana/blob/da72ee0093c5a1e164b4a24c5f94333c2376e7cc/x-pack/plugins/fleet/common/openapi/README.md

Generated the new bundle by running this script locally:
```
node scripts/capture_oas_snapshot --include-path /api/fleet --update
```

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:enhancement Team:Fleet Team label for Observability Data Collection Fleet team v9.0.0

7 participants