-
Notifications
You must be signed in to change notification settings - Fork 173
Add generated Fleet API docs #2715
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
Changes from all commits
561d769
68b76f1
b61312c
497028b
f1300c6
729bf23
8b2334a
9d8bac4
962ed2d
6a65b54
7afe76c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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}} | ||
| --> | ||
|
|
||
| <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> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| <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}} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 The output now renders like this: A couple of things I noticed:
@kpollich If you don't mind adjusting the spec to add tags I'd be very happy to retest.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Regarding I'll get a PR together with these changes and provide you a new spec file shortly. Many thanks!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kilfoyle - Here's that PR: elastic/kibana#152386 - please find the updated 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 🙂
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
| ++++ | ||
| 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[] |



There was a problem hiding this comment.
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 🙂
There was a problem hiding this comment.
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.mustachefile 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.