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

[Demo][Dashboard] Public create API #181950

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

jloleysens
Copy link
Contributor

@jloleysens jloleysens commented Apr 29, 2024

Summary

A demo showing how with the current code we can get public APIs for dashboards with OpenAPI spec generation.

How to get OAS:

  1. Add server.oas.enabled: true to kibana.dev.yml
  2. Start Kibana with yarn start --no-base-path
  3. curl -uelastic:changeme http://localhost:5601/api/oas\?pathStartsWith\=/api/dashboard
{
  "openapi": "3.0.0",
  "info": {
    "title": "Kibana HTTP APIs",
    "version": "0.0.0"
  },
  "servers": [
    {
      "url": "http://localhost:5601"
    }
  ],
  "paths": {
    "/api/dashboard": {
      "post": {
        "requestBody": {
          "content": {
            "application/json; Elastic-Api-Version=2023-10-31": {
              "schema": {
                "$ref": "#/components/schemas/dashboard.create"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Create a dashboard",
            "content": {
              "application/json; Elastic-Api-Version=2023-10-31": {
                "schema": {
                  "$ref": "#/components/schemas/dashboard"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "elastic-api-version",
            "schema": {
              "type": "string",
              "enum": [
                "2023-10-31"
              ],
              "default": "2023-10-31"
            }
          }
        ],
        "operationId": "/api/dashboard#0"
      }
    }
  },
  "components": {
    "schemas": {
      "dashboard.create": {
        "type": "object",
        "properties": {
          "title": {
            "description": "A human-readable title for the dashboard",
            "type": "string"
          },
          "description": {
            "description": "A short description.",
            "default": "",
            "type": "string"
          },
          "kibanaSavedObjectMeta": {
            "description": "A container for various metadata",
            "type": "object",
            "properties": {
              "searchSourceJSON": {
                "description": "A string containing search source",
                "type": "string"
              }
            },
            "additionalProperties": false,
            "required": []
          },
          "timeRestore": {
            "description": "Whether to restore time upon viewing this dashboard",
            "type": "boolean"
          },
          "timeFrom": {
            "description": "An ISO string indicating when to restore time from",
            "type": "string"
          },
          "timeTo": {
            "description": "An ISO string indicating when to restore time from",
            "type": "string"
          },
          "refreshInterval": {
            "description": "A container for various refresh interval settings",
            "type": "object",
            "properties": {
              "pause": {
                "description": "Whether the refresh interval is set to be paused while viewing the dashboard.",
                "type": "boolean"
              },
              "value": {
                "description": "A numeric value indicating refresh frequency expressed as, for example, 30s.",
                "type": "number"
              },
              "display": {
                "description": "Lorem ipsum",
                "type": "string"
              },
              "section": {
                "description": "Lorem ipsum",
                "type": "number"
              }
            },
            "additionalProperties": false,
            "required": [
              "pause",
              "value"
            ]
          },
          "controlGroupInput": {
            "type": "object",
            "properties": {
              "panelsJSON": {
                "description": "Lorem ipsum",
                "type": "string"
              },
              "controlStyle": {
                "description": "Lorem ipsum",
                "type": "string"
              },
              "chainingSystem": {
                "description": "Lorem ipsum",
                "type": "string"
              },
              "ignoreParentSettingsJSON": {
                "description": "Lorem ipsum",
                "type": "string"
              }
            },
            "additionalProperties": false,
            "required": []
          },
          "panelsJSON": {
            "description": "Lorem ipsum",
            "default": "[]",
            "type": "string"
          },
          "optionsJSON": {
            "description": "Lorem ipsum",
            "default": "{}",
            "type": "string"
          },
          "id": {
            "description": "The ID of the dashboard",
            "type": "string"
          }
        },
        "additionalProperties": false,
        "required": [
          "title",
          "kibanaSavedObjectMeta"
        ]
      },
      "dashboard": {
        "type": "object",
        "properties": {
          "title": {
            "description": "A human-readable title for the dashboard",
            "type": "string"
          },
          "description": {
            "description": "A short description.",
            "default": "",
            "type": "string"
          },
          "kibanaSavedObjectMeta": {
            "description": "A container for various metadata",
            "type": "object",
            "properties": {
              "searchSourceJSON": {
                "description": "A string containing search source",
                "type": "string"
              }
            },
            "additionalProperties": false,
            "required": []
          },
          "timeRestore": {
            "description": "Whether to restore time upon viewing this dashboard",
            "type": "boolean"
          },
          "timeFrom": {
            "description": "An ISO string indicating when to restore time from",
            "type": "string"
          },
          "timeTo": {
            "description": "An ISO string indicating when to restore time from",
            "type": "string"
          },
          "refreshInterval": {
            "description": "A container for various refresh interval settings",
            "type": "object",
            "properties": {
              "pause": {
                "description": "Whether the refresh interval is set to be paused while viewing the dashboard.",
                "type": "boolean"
              },
              "value": {
                "description": "A numeric value indicating refresh frequency expressed as, for example, 30s.",
                "type": "number"
              },
              "display": {
                "description": "Lorem ipsum",
                "type": "string"
              },
              "section": {
                "description": "Lorem ipsum",
                "type": "number"
              }
            },
            "additionalProperties": false,
            "required": [
              "pause",
              "value"
            ]
          },
          "controlGroupInput": {
            "type": "object",
            "properties": {
              "panelsJSON": {
                "description": "Lorem ipsum",
                "type": "string"
              },
              "controlStyle": {
                "description": "Lorem ipsum",
                "type": "string"
              },
              "chainingSystem": {
                "description": "Lorem ipsum",
                "type": "string"
              },
              "ignoreParentSettingsJSON": {
                "description": "Lorem ipsum",
                "type": "string"
              }
            },
            "additionalProperties": false,
            "required": []
          },
          "panelsJSON": {
            "description": "Lorem ipsum",
            "default": "[]",
            "type": "string"
          },
          "optionsJSON": {
            "description": "Lorem ipsum",
            "default": "{}",
            "type": "string"
          },
          "id": {
            "description": "The ID of the dashboard",
            "type": "string"
          }
        },
        "additionalProperties": false,
        "required": [
          "title",
          "kibanaSavedObjectMeta",
          "id"
        ]
      }
    },
    "securitySchemes": {
      "basicAuth": {
        "type": "http",
        "scheme": "basic"
      },
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "Authorization"
      }
    }
  },
  "security": [
    {
      "basicAuth": []
    }
  ]
}

@jloleysens jloleysens changed the title [Dashboard] Public create API [Demo][Dashboard] Public create API Apr 30, 2024
let result: Dashboard;
try {
const cmResult = await client.create(req.body);
result = cmResult.result as unknown as Dashboard;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like there is a gap in the Dashboard type being passed through so I was getting object.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

To be investigated, in the code it looks like we are forwarding the type in CreateItemResponse<T>

Screenshot 2024-05-07 at 11 33 17

Copy link
Contributor Author

@jloleysens jloleysens May 8, 2024

Choose a reason for hiding this comment

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

I think the problem is data: object does not let the return type infer the type of the generic to something other than object

Copy link
Contributor

@sebelga sebelga May 8, 2024

Choose a reason for hiding this comment

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

But here we are talking about the response right? You might be right but it is strange the the input type affects the output type. Although I've seen weirder things with TS 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants