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

[OAS] Add saved objects openAPI folder #162522

Merged
merged 11 commits into from
Aug 16, 2023
6 changes: 6 additions & 0 deletions docs/api/saved-objects/export.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

experimental[] Retrieve sets of saved objects that you want to import into {kib}.

[NOTE]
====
For the most up-to-date API details, refer to the
{kib-repo}/tree/{branch}/packages/core/saved-objects/docs/openapi[open API specification].
====

[[saved-objects-api-export-request]]
==== Request

Expand Down
6 changes: 6 additions & 0 deletions docs/api/saved-objects/import.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

experimental[] Create sets of {kib} saved objects from a file created by the export API.

[NOTE]
====
For the most up-to-date API details, refer to the
{kib-repo}/tree/{branch}/packages/core/saved-objects/docs/openapi[open API specification].
====

==== Compatibility across versions
Saved objects can only be imported into the same version, a newer minor on the same major, or the next major. Exported saved objects are not backwards compatible and cannot be imported into an older version of {kib}. See the table below for compatibility examples:

Expand Down
34 changes: 34 additions & 0 deletions packages/core/saved-objects/docs/openapi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# OpenAPI (Experimental)

The current self-contained spec file is `bundled.json` or `bundled.yaml` and can be used for online tools like those found at <https://openapi.tools/>.
This spec is experimental and may be incomplete or change later.

A guide about the openApi specification can be found at [https://swagger.io/docs/specification/about/](https://swagger.io/docs/specification/about/).
Copy link
Contributor

Choose a reason for hiding this comment

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

AFAIK, every api that has an openApi spec will have a README. That's a lot of duplication and adds to the bundle size. The original intent of moving kibana to packages was to keep Kibana small (codes size wise) and fast.

For now, it's probably ok but we need to watch that. @elastic/kibana-operations are we at all concerned about bundle size increasing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, if there are any space savings that can occur that's worth doing. Once we get to the point where the specs are being generated from the code there will hopefully be a lot less overhead too.

Copy link
Member

Choose a reason for hiding this comment

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

We can keep an eye on it, thanks for the heads up. We're removing most documentation from the distribution currently, unless it's referenced in kibana itself.


## The `openapi` folder

* `entrypoint.yaml` is the overview file which pulls together all the paths and components.
* [Paths](paths/README.md): this defines each endpoint. A path can have one operation per http method.

## Tools

To validate and bundle the docs, you can use [Redocly](https://redocly.com/docs/cli/) and [Swagger/OpenAPI CLI](https://www.npmjs.com/package/swagger-cli).

For example, run the following commands from the `packages/core/saved-objects/docs/openapi/` folder:

```bash
npx swagger-cli validate entrypoint.yaml
```

Then you can generate the `bundled` files by running the following commands:

```bash
npx @redocly/cli bundle entrypoint.yaml --output bundled.yaml --ext yaml
npx @redocly/cli bundle entrypoint.yaml --output bundled.json --ext json
```

After generating the json bundle ensure that it is also valid by running the following command:

```bash
npx @redocly/cli lint bundled.json
```
326 changes: 326 additions & 0 deletions packages/core/saved-objects/docs/openapi/bundled.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,326 @@
{
"openapi": "3.1.0",
"info": {
"title": "Saved objects",
"description": "OpenAPI schema for saved object endpoints",
"version": "0.1",
"contact": {
"name": "Kibana Core Team"
},
"license": {
"name": "Elastic License 2.0",
"url": "https://www.elastic.co/licensing/elastic-license"
}
},
"servers": [
{
"url": "http://localhost:5601",
"description": "local"
}
],
"security": [
{
"basicAuth": []
},
{
"apiKeyAuth": []
}
],
"tags": [
{
"name": "saved objects",
"description": "Manage Kibana saved objects, including dashboards, visualizations, and more."
}
],
"paths": {
"/api/saved_objects/_export": {
"post": {
"summary": "Retrieve sets of saved objects that you want to import into Kibana.",
"operationId": "exportSavedObjects",
"description": "This functionality is in technical preview and may be changed or removed in a future release. Elastic will apply best effort to fix any issues, but features in technical preview are not subject to the support SLA of official GA features. NOTE: The `savedObjects.maxImportExportSize` configuration setting limits the number of saved objects which may be exported.\n",
"tags": [
"saved objects"
],
"parameters": [
{
"$ref": "#/components/parameters/kbn_xsrf"
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"anyOf": [
{
"required": [
"type"
]
},
{
"required": [
"objects"
]
}
],
"properties": {
"excludeExportDetails": {
"description": "Do not add export details entry at the end of the stream.",
"type": "boolean",
"default": false
},
"includeReferencesDeep": {
"description": "Includes all of the referenced objects in the exported objects.",
"type": "boolean"
},
"objects": {
"description": "A list of objects to export.",
"type": "array",
"items": {
"type": "object"
}
},
"type": {
"description": "The saved object types to include in the export.",
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
}
}
},
"examples": {
"exportSavedObjectsRequest": {
"$ref": "#/components/examples/export_objects_request"
}
}
}
}
},
"responses": {
"200": {
"description": "Indicates a successful call.",
"content": {
"multipart/form-data": {
"schema": {
"type": "string"
},
"examples": {
"exportSavedObjectsResponse": {
"$ref": "#/components/examples/export_objects_response"
}
}
}
}
},
"400": {
"description": "Bad request.",
"content": {
"application/json": {
"schema": {
"type": "object",
"additionalProperties": true
}
}
}
}
},
"servers": [
{
"url": "https://localhost:5601"
}
]
},
"servers": [
{
"url": "https://localhost:5601"
}
]
},
"/api/saved_objects/_import": {
"post": {
"summary": "Create sets of Kibana saved objects from a file created by the export API.",
"operationId": "importSavedObjects",
"description": "This functionality is in technical preview and may be changed or removed in a future release. Elastic will apply best effort to fix any issues, but features in technical preview are not subject to the support SLA of official GA features. Saved objects can be imported only into the same version, a newer minor on the same major, or the next major. Exported saved objects are not backwards compatible and cannot be imported into an older version of Kibana.\n",
"tags": [
"saved objects"
],
"parameters": [
{
"$ref": "#/components/parameters/kbn_xsrf"
},
{
"in": "query",
"name": "compatibilityMode",
"schema": {
"type": "boolean"
},
"required": false,
"description": "Applies various adjustments to the saved objects that are being imported to maintain compatibility between different Kibana versions. Use this option only if you encounter issues with imported saved objects. NOTE: This option cannot be used with the `createNewCopies` option.\n"
},
{
"in": "query",
"name": "createNewCopies",
"schema": {
"type": "boolean"
},
"required": false,
"description": "Creates copies of saved objects, regenerates each object ID, and resets the origin. When used, potential conflict errors are avoided. NOTE: This option cannot be used with the `overwrite` and `compatibilityMode` options.\n"
},
{
"in": "query",
"name": "overwrite",
"schema": {
"type": "boolean"
},
"required": false,
"description": "Overwrites saved objects when they already exist. When used, potential conflict errors are automatically resolved by overwriting the destination object. NOTE: This option cannot be used with the `createNewCopies` option.\n"
}
],
"requestBody": {
"required": true,
"content": {
"multipart/form-data": {
"schema": {
"type": "object",
"description": "A file exported using the export API. NOTE: The `savedObjects.maxImportExportSize` configuration setting limits the number of saved objects which may be included in this file. Similarly, the `savedObjects.maxImportPayloadBytes` setting limits the overall size of the file that can be imported.\n"
}
}
}
},
"responses": {
"200": {
"description": "Indicates a successful call.",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"errors": {
"type": "array",
"description": "Indicates the import was unsuccessful and specifies the objects that failed to import. One object may result in multiple errors, which requires separate steps to resolve. For instance, a `missing_references` error and conflict error.\n"
},
"success": {
"type": "boolean",
"description": "Indicates when the import was successfully completed. When set to false, some objects may not have been created. For additional information, refer to the `errors` and `successResults` properties.\n"
},
"successCount": {
"type": "integer",
"description": "Indicates the number of successfully imported records."
},
"successResults": {
"type": "array",
"items": {
"type": "object"
},
"description": "Indicates the objects that are successfully imported, with any metadata if applicable. Objects are created only when all resolvable errors are addressed, including conflicts and missing references. If objects are created as new copies, each entry in the `successResults` array includes a `destinationId` attribute.\n"
},
"warnings": {
"type": "array"
}
}
},
"examples": {
"importObjectsResponse": {
"$ref": "#/components/examples/import_objects_response"
}
}
}
}
},
"400": {
"description": "Bad request.",
"content": {
"application/json": {
"schema": {
"type": "object",
"additionalProperties": true
}
}
}
}
},
"servers": [
{
"url": "https://localhost:5601"
}
]
},
"servers": [
{
"url": "https://localhost:5601"
}
]
}
},
"components": {
"securitySchemes": {
"basicAuth": {
"type": "http",
"scheme": "basic"
},
"apiKeyAuth": {
"type": "apiKey",
"in": "header",
"name": "ApiKey"
}
},
"parameters": {
"kbn_xsrf": {
"schema": {
"type": "string"
},
"in": "header",
"name": "kbn-xsrf",
"description": "Cross-site request forgery protection",
"required": true
}
},
"examples": {
"export_objects_request": {
"summary": "Export a specific saved object.",
"value": {
"objects": [
{
"type": "index-pattern",
"id": "90943e30-9a47-11e8-b64d-95841ca0b247"
}
],
"includeReferencesDeep": false
}
},
"export_objects_response": {
"summary": "The export objects API response contains a JSON record for each exported object and an export result details record.",
"value": "{\"attributes\":{\"fieldFormatMap\":\"{\\\"hour_of_day\\\":{}}\",\"name\":\"Kibana Sample Data Logs\",\"runtimeFieldMap\":\"{\\\"hour_of_day\\\":{\\\"type\\\":\\\"long\\\",\\\"script\\\":{\\\"source\\\":\\\"emit(doc['timestamp'].value.getHour());\\\"}}}\",\"timeFieldName\":\"timestamp\",\"title\":\"kibana_sample_data_logs\"},\"coreMigrationVersion\":\"8.8.0\",\"created_at\":\"2023-07-25T19:36:36.695Z\",\"id\":\"90943e30-9a47-11e8-b64d-95841ca0b247\",\"managed\":false,\"references\":[],\"type\":\"index-pattern\",\"typeMigrationVersion\":\"8.0.0\",\"updated_at\":\"2023-07-25T19:36:36.695Z\",\"version\":\"WzM5LDJd\"}\n{\"excludedObjects\":[],\"excludedObjectsCount\":0,\"exportedCount\":1,\"missingRefCount\":0,\"missingReferences\":[]}\n"
},
"import_objects_response": {
"summary": "The import objects API response indicates a successful import and the objects are created. Since these objects are created as new copies, each entry in the successResults array includes a destinationId attribute.",
"value": {
"successCount": 1,
"success": true,
"warnings": [],
"successResults": [
{
"type": "index-pattern",
"id": "90943e30-9a47-11e8-b64d-95841ca0b247",
"meta": {
"title": "Kibana Sample Data Logs",
"icon": "indexPatternApp"
},
"managed": false,
"destinationId": "82d2760c-468f-49cf-83aa-b9a35b6a8943"
}
]
}
}
}
}
}
Loading