Skip to content

Commit

Permalink
[Fleet] remove old bundled.yaml from oas, fixed tags (elastic#194788)
Browse files Browse the repository at this point in the history
## 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 <[email protected]>
  • Loading branch information
2 people authored and tiansivive committed Oct 7, 2024
1 parent 6d1b6ae commit 3868414
Show file tree
Hide file tree
Showing 178 changed files with 191,998 additions and 75,156 deletions.
2 changes: 1 addition & 1 deletion .buildkite/scripts/steps/capture_oas_snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail
source .buildkite/scripts/common/util.sh

echo --- Capture OAS snapshot
cmd="node scripts/capture_oas_snapshot --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"
cmd="node scripts/capture_oas_snapshot --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"
if is_pr && ! is_auto_commit_disabled; then
cmd="$cmd --update"
fi
Expand Down
Loading

0 comments on commit 3868414

Please sign in to comment.