Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/en/ingest-management/fleet/api-generated/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
OpenAPI (Experimental)

The process described here is a Fleet-specific instance of the process described for generating Kibana OpenAPI documentation in general. Refer to the Kibana OpenAPI [readme file](https://github.com/elastic/kibana/tree/main/docs/api-generated) for details.

Open API specifications (OAS) exist in JSON for Fleet, though they are experimental and may be incomplete or change later.

A preview of the API specifications can be added to the Fleet and Elastic Agent Guide by using the following process:

. Create a local clone of the [elastic/kibana](https://github.com/elastic/kibana) and [elastic/observability-docs](https://github.com/elastic/observability-docs) repositories in your `$GIT_PATH` directory.

. Install [OpenAPI Generator](https://openapi-generator.tech/docs/installation),
or a similar tool that can generate HTML output from OAS.

. Optionally validate the specifications by using the commands listed in the appropriate readmes.

. Generate HTML output. For example:

```
openapi-generator generate -g html -i $GIT_HOME/kibana/x-pack/plugins/fleet/common/openapi/bundled.json -o $GIT_HOME/observability-docs/docs/en/ingest-management/fleet/api-generated/rules -t $GIT_HOME/observability-docs/docs/en/ingest-management/fleet/api-generated/template
```

. Rename the output files. For example:
```
mv $GIT_HOME/observability-docs/docs/en/ingest-management/fleet/api-generated/rules/index.html $GIT_HOME/observability-docs/docs/en/ingest-management/fleet/api-generated/rules/fleet-apis-passthru.asciidoc
```

. If you're creating a new set of API output, you will need to have a page that incorporates the output by using passthrough blocks. For more information, refer to [Asciidoctor docs](https://docs.asciidoctor.org/asciidoc/latest/pass/pass-block/)

. Verify the output by building the Kibana documentation. At this time, the output is added as a technical preview in the appendix.

## Known issues

- Some OAS 3.0 features such as `anyOf`, `oneOf`, and `allOf` might not display properly in the preview. These are on the [Short-term roadmap](https://openapi-generator.tech/docs/roadmap/) at this time.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.4.0

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[[fleet-apis]]
== Fleet APIs

preview::[]

////
This file includes content that has been generated from https://github.com/elastic/kibana/tree/main/x-pack/plugins/fleet/common/openapi. Any modifications required must be done in that open API specification.
////

include::fleet-apis-passthru.asciidoc[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
////
This content is generated from the open API specification.
Any modifications made to this file will be overwritten.
////

++++
<div class="openapi">

<!--
<h2>Access</h2>
{{#hasAuthMethods}}
<ol>
{{#authMethods}}
<li>{{#isBasic}}HTTP Basic Authentication{{/isBasic}}{{#isOAuth}}OAuth AuthorizationUrl:{{authorizationUrl}}TokenUrl:{{tokenUrl}}{{/isOAuth}}{{#isApiKey}}APIKey KeyParamName:{{keyParamName}} KeyInQuery:{{isKeyInQuery}} KeyInHeader:{{isKeyInHeader}}{{/isApiKey}}</li>
{{/authMethods}}
</ol>
{{/hasAuthMethods}}
Comment on lines +10 to +17
Copy link
Member

Choose a reason for hiding this comment

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

The "access" block seems to render a bit strangely, but maybe this is intentional? Seems like this might just be debugging info for now 🙂

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That does look strange! It turns out that we can edit the index.mustache file directly (the warning at the top of the file says that it's generated, but my changes aren't overwritten when I regenerate the API docs). So, I just removed this section, or if we want it seems we can add anything we want here. I've pushed a new commit so the preview should refresh soon.

-->

<h2><a name="__Methods">Methods</a></h2>
[ Jump to <a href="#__Models">Models</a> ]

{{! for the tables of content, I cheat and don't use CSS styles.... }}
<h3>Table of Contents </h3>
<div class="method-summary">{{access}}</div>
{{#apiInfo}}
{{#apis}}
{{#operations}}
<h4><a href="#{{baseName}}">{{baseName}}</a></h4>
Copy link
Member

Choose a reason for hiding this comment

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

Is this baseName variable where this Default string in the preview comes from?

image

If so, what controls this? Can the OpenAPI spec Fleet provides define something more meaningful that'll get rendered here?

Copy link
Contributor Author

@kilfoyle kilfoyle Feb 27, 2023

Choose a reason for hiding this comment

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

Similar to the above, it looks like we can just update the index.mustache file directly to adjust most of the formatting. I first changed the line <h4><a href="#{{baseName}}">{{baseName}}</a></h4> and confirmed that it does control that "Default" text. Then, I tried changing the text to something meaningful. But then, after adding tags to control the ordering (see comment) that text appeared above every endpoint. So, instead I just commented it out.

<ul>
{{#operation}}
<li><a href="#{{nickname}}"><code><span class="http-method">{{httpMethod}}</span> {{path}}</code></a></li>
{{/operation}}
</ul>
{{/operations}}
{{/apis}}
{{/apiInfo}}

{{#apiInfo}}
{{#apis}}
{{#operations}}
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way Fleet can control the order in which operations are rendered? It'd be great to order them the same way they appear in the spec file as we group endpoints by "namespace" - e.g. all routes prefixed with /epm are colocated, /setup appears first, all /agent_policy routes are colocated, etc.

image

Here's the order in the spec, for reference: https://github.com/elastic/kibana/blob/main/x-pack/plugins/fleet/common/openapi/entrypoint.yaml#L15-L153. Making this a predictably ordered list that aligns with the spec file would be awesome, so happy to do anything we can on Fleet's side to make that work.

Copy link
Contributor Author

@kilfoyle kilfoyle Feb 27, 2023

Choose a reason for hiding this comment

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

Happily, I have discovered that the output order is controlled by the tags in bundled.json. For example, I added "0001" to /setup, "0002" to /settings and and so on for the first ten or so endpoints (if that's the right term). Like this:

  "paths": {
    "/setup": {
      "post": {
        "summary": "Setup",
        "tags": ["0001"],
        "responses": {
          "200": {

The output now renders like this:
Screenshot 2023-02-27 at 4 01 32 PM

A couple of things I noticed:

  1. The post /health_check endpoint appears in the Fleet API docs if I give it a tag, and if I remove that tag, it disappears. Since I don't see that endpoint in the Swagger docs, I assume it's meant to be hidden. So, I guess we need to be careful about which endpoints have or don't have tags, assuming at least some aren't intended to be exposed in the docs.

  2. Some endpoints, such as "/agents/action_status" don't have a tag field at all, so perhaps one can be added.

@kpollich If you don't mind adjusting the spec to add tags I'd be very happy to retest.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for digging into this @kilfoyle - I think we can add some tags to group everything. Realistically, I don't care much about alphabetical order or anything as much as I care about grouping related endpoints together, which should be easily achievable by doing things like tags: ['agent-policies'] for each /agent_policies/* endpoint and so forth.

The post /health_check endpoint appears in the Fleet API docs if I give it a tag, and if I remove that tag, it disappears. Since I don't see that endpoint in the Swagger docs, I assume it's meant to be hidden.

Regarding /health_check - we probably don't want this documented in the public facing API spec, you're right. I'll probably just remove its path value from the spec.

I'll get a PR together with these changes and provide you a new spec file shortly. Many thanks!

Copy link
Member

Choose a reason for hiding this comment

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

@kilfoyle - Here's that PR: elastic/kibana#152386 - please find the updated bundled.yaml or bundled.json attached to that PR and feel free to make a pass here with the updated spec. I took some time to clean up tags, descriptions, etc to hopefully group things consistently.

Here's an example with the official Swagger UI tool: https://petstore.swagger.io/?url=https://raw.githubusercontent.com/elastic/kibana/27b14796ddb26a390614396bfac1ba9190511786/x-pack/plugins/fleet/common/openapi/bundled.yaml#/. I'm sure we can go further in organizing here, but hopefully this represents a solid first step forward 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kpollich - Thanks for the terrific changes! I think the docs are looking great. I added the headers back in and they display the groups quite nicely.

I tested bundled.json and bundled.yaml. Both work nicely with exactly the same results.

One thing remaining would be to hide the "FleetInternals" section, but otherwise I think we're in pretty good shape now.

<h1><a name="{{baseName}}">{{baseName}}</a></h1>
{{#operation}}
<div class="method"><a name="{{nickname}}"/>
<div class="method-path">
<a class="up" href="#__Methods">Up</a>
<pre class="{{httpMethod}}"><code class="huge"><span class="http-method">{{httpMethod}}</span> {{path}}</code></pre></div>
<div class="method-summary">{{summary}} (<span class="nickname">{{nickname}}</span>)</div>
{{! notes is operation.description. So why rename it and make it super confusing???? }}
<div class="method-notes">{{notes}}</div>

{{#hasPathParams}}
<h3 class="field-label">Path parameters</h3>
<div class="field-items">
{{#pathParams}}{{>pathParam}}{{/pathParams}}
</div> <!-- field-items -->
{{/hasPathParams}}

{{#hasConsumes}}
<h3 class="field-label">Consumes</h3>
This API call consumes the following media types via the <span class="header">Content-Type</span> request header:
<ul>
{{#consumes}}
<li><code>{{{mediaType}}}</code></li>
{{/consumes}}
</ul>
{{/hasConsumes}}

{{#hasBodyParam}}
<h3 class="field-label">Request body</h3>
<div class="field-items">
{{#bodyParams}}{{>bodyParam}}{{/bodyParams}}
</div> <!-- field-items -->
{{/hasBodyParam}}

{{#hasHeaderParams}}
<h3 class="field-label">Request headers</h3>
<div class="field-items">
{{#headerParams}}{{>headerParam}}{{/headerParams}}
</div> <!-- field-items -->
{{/hasHeaderParams}}

{{#hasQueryParams}}
<h3 class="field-label">Query parameters</h3>
<div class="field-items">
{{#queryParams}}{{>queryParam}}{{/queryParams}}
</div> <!-- field-items -->
{{/hasQueryParams}}

{{#hasFormParams}}
<h3 class="field-label">Form parameters</h3>
<div class="field-items">
{{#formParams}}{{>formParam}}{{/formParams}}
</div> <!-- field-items -->
{{/hasFormParams}}

{{#returnType}}
<h3 class="field-label">Return type</h3>
<div class="return-type">
{{#hasReference}}{{^returnSimpleType}}{{returnContainer}}[{{/returnSimpleType}}<a href="#{{returnBaseType}}">{{returnBaseType}}</a>{{^returnSimpleType}}]{{/returnSimpleType}}{{/hasReference}}
{{^hasReference}}{{returnType}}{{/hasReference}}
</div>
{{/returnType}}

<!--Todo: process Response Object and its headers, schema, examples -->

{{#hasExamples}}
{{#examples}}
<h3 class="field-label">Example data</h3>
<div class="example-data-content-type">Content-Type: {{{contentType}}}</div>
<pre class="example"><code>{{{example}}}</code></pre>
{{/examples}}
{{/hasExamples}}

{{#hasProduces}}
<h3 class="field-label">Produces</h3>
This API call produces the following media types according to the <span class="header">Accept</span> request header;
the media type will be conveyed by the <span class="header">Content-Type</span> response header.
<ul>
{{#produces}}
<li><code>{{{mediaType}}}</code></li>
{{/produces}}
</ul>
{{/hasProduces}}

<h3 class="field-label">Responses</h3>
{{#responses}}
<h4 class="field-label">{{code}}</h4>
{{message}}
{{^containerType}}<a href="#{{dataType}}">{{dataType}}</a>{{/containerType}}
{{#examples}}
<h3 class="field-label">Example data</h3>
<div class="example-data-content-type">Content-Type: {{{contentType}}}</div>
<pre class="example"><code>{{example}}</code></pre>
{{/examples}}
{{/responses}}
</div> <!-- method -->
<hr/>
{{/operation}}
{{/operations}}
{{/apis}}
{{/apiInfo}}

<h2><a name="__Models">Models</a></h2>
[ Jump to <a href="#__Methods">Methods</a> ]

<h3>Table of Contents</h3>
<ol>
{{#models}}
{{#model}}
<li><a href="#{{name}}"><code>{{name}}</code>{{#title}} - {{.}}{{/title}}</a></li>
{{/model}}
{{/models}}
</ol>

{{#models}}
{{#model}}
<div class="model">
<h3><a name="{{name}}"><code>{{name}}</code>{{#title}} - {{.}}{{/title}}</a> <a class="up" href="#__Models">Up</a></h3>
{{#unescapedDescription}}<div class='model-description'>{{.}}</div>{{/unescapedDescription}}
<div class="field-items">
{{#vars}}<div class="param">{{name}} {{^required}}(optional){{/required}}</div><div class="param-desc"><span class="param-type">{{^isPrimitiveType}}<a href="#{{complexType}}">{{dataType}}</a>{{/isPrimitiveType}}</span> {{unescapedDescription}} {{#dataFormat}}format: {{{.}}}{{/dataFormat}}</div>
{{#isEnum}}
<div class="param-enum-header">Enum:</div>
{{#_enum}}<div class="param-enum">{{this}}</div>{{/_enum}}
{{/isEnum}}
{{/vars}}
</div> <!-- field-items -->
</div>
{{/model}}
{{/models}}
</div>
++++
14 changes: 14 additions & 0 deletions docs/en/ingest-management/fleet/apis.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[role="exclude",id="apis"]
= API

[partintro]
--

preview::[]

The {fleet} API is documented using the OpenAPI specification. The current supported
version of the specification is 3.0. For more information, go to https://openapi-generator.tech/[OpenAPI Generator]

--

include::api-generated/rules/fleet-apis.asciidoc[]
21 changes: 15 additions & 6 deletions docs/en/ingest-management/fleet/fleet-api-docs.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@

experimental[]

The official {fleet} API documentation is not yet available in the Elastic docs.
However we do provide a self-contained spec file that you can
https://petstore.swagger.io/?url=https://raw.githubusercontent.com/elastic/kibana/{branch}/x-pack/plugins/fleet/common/openapi/bundled.json[view in Swagger]
(or a similar tool) to explore our Fleet APIs.
You can find details for all available {fleet} API endpoints in our generated
<<fleet-apis,{fleet} API docs>>. This documentation is experimental and may be
incomplete or change later.

The main source of truth for the {fleet} API can be found in the
https://github.com/elastic/kibana/blob/main/x-pack/plugins/fleet/common/openapi/bundled.json[self-contained spec file]
that you can use to generate docs using Swagger or a similar tool.
For more information, refer to the
https://github.com/elastic/kibana/blob/{branch}/x-pack/plugins/fleet/common/openapi/README.md[{fleet} OpenAPI file]
in the {kib} repository.
https://github.com/elastic/kibana/tree/main/x-pack/plugins/fleet/common/openapi/README.md[{fleet} OpenAPI readme].

//However we do provide a self-contained spec file that you can
//https://petstore.swagger.io/?url=https://raw.githubusercontent.com/elastic/kibana/{branch}/x-pack/plugins/fleet/common/openapi/bundled.json[view in Swagger]
//(or a similar tool) to explore our Fleet APIs.

//For more information, refer to the
//https://github.com/elastic/kibana/blob/{branch}/x-pack/plugins/fleet/common/openapi/README.md[{fleet} OpenAPI file]
//in the {kib} repository.

In this section, we provide examples of some commonly used {fleet} APIs.

Expand Down
2 changes: 2 additions & 0 deletions docs/en/ingest-management/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,6 @@ include::release-notes/release-notes-8.6.asciidoc[leveloffset=+1]

include::elastic-agent/install-fleet-managed-agent.asciidoc[leveloffset=+2]

include::fleet/apis.asciidoc[]

include::redirects.asciidoc[]