Files
Davanum Srinivas 2a7c3fb2cc docs(api): generate the REST API Reference from openapi.yaml (#1172)
* chore(api): lint openapi.yaml and mark the internal surface for Fern

Fern builds the REST API Reference tab of the documentation site from
controller/api/openapi.yaml, and the docs team is about to move the prose
of the "NKE REST API Reference" into that file. This is the tooling that
has to be in place first.

Lint gate. `make -C controller/api lint` now also runs `lint-spec`, which
lints openapi.yaml with vacuum against openapi-lint.yaml. vacuum is a
Spectral-compatible linter written in Go, so `go run` pins it the way
generate.go pins gofumpt, with no install step; the version lives in
make/tool-versions.mk with the other tools. Errors fail the gate: every
example matches its schema, no component is unused, operationIds are
unique. Warnings measure the prose the spec still lacks (16 operations
and 40 properties without a description, 31 schemas, no tags) and fail
nothing yet; each is raised to error once the prose port lands, so that
coverage cannot regress afterwards. Rules the API breaks on purpose
(camelCase paths and properties, a DELETE with a body, extensions beside
`$ref`) are off, with the reason beside each.

The one error it found is fixed here: the `nodePools` example on
CreateClusterRequest named a `namePrefix` field that does not exist and
had neither `name` nor `nodeNamePrefix`, both required.

Internal surface. The `infra` provider, `teleportEnabled`, the legacy
`controlPlane` node-pool flag, the `/osProfiles` and `/configProfiles`
endpoints, and the schemas only they reach now carry `x-fern-ignore:
true`. Fern leaves them out of the published reference; Swagger UI at
/api/docs/ and the generated Go are unchanged. `x-fern-audiences` was the
first choice and does not fit: `fern ir --audience public` returns an
empty API unless every element is tagged, so a new endpoint would vanish
from the customer docs by default. The ignore marker is opt-out, and the
IR confirms it removes exactly the listed items.

The two "exactly one of `nico` or `infra`" sentences move from the schema
descriptions onto the `infra` properties, so the published reference,
which does not show `infra`, no longer refers to it. Only comments change
in the generated Go.

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>

* fix(api): keep `infra` out of the text the customer reference shows

The previous commit moved the "exactly one of `nico` or `infra`" sentences
onto the `infra` properties and said the published reference no longer
refers to `infra`. That was wrong on two counts, found by rendering the
spec with Redoc and dumping Fern's intermediate representation.

A description written beside a `$ref` is read by Fern and ignored by
Redoc, Swagger UI and oapi-codegen, which show the referenced schema's
description instead. So is `x-go-type-skip-optional-pointer` beside a
`$ref`: the generated field was a pointer all along. And six schema
descriptions that Fern does show still named `infra`: the control-plane
create and update configs, the node pool update request, and the three
NICo provider schemas.

Those six no longer mention the other provider. The exclusivity rule now
lives on the Infra* schemas, which the published reference omits and
Swagger UI shows. The four `nico` and `infra` properties touched before
wrap their `$ref` in `allOf`, so every reader applies the description, and
drop the pointer extension that was never in effect; the generated Go
changes only in comments. no-$ref-siblings moves from off to warn, with
an accurate note, so the docs port can work the remaining 28 down.

Verified: Fern IR has 0 docs strings mentioning `infra`; Redoc shows the
new `nico` text and none of the old sentences; make -C controller/api
lint passes with 0 errors.

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>

* docs(api): port the REST API Reference prose into openapi.yaml

The docs team wrote "NKE REST API Reference (Alpha) - Customer Edition"
by hand. This moves its language into the spec, so the reference is
generated from the file the code is generated from. The text is taken
as written; claims the code contradicts are corrected in the commits
that follow, each with its evidence, so the review can see both.

What moved: the info block (title, version, and the conventions: base
URL, authentication, errors, asynchronous operations, PATCH merge
semantics, lists, unauthenticated endpoints); tags carrying the concept
text (infrastructure provider, Kubernetes versions, networking, control
plane, OS releases); a summary, a description and the documented 400
and 409 rules for each of the 22 operations; request examples for the
five writes and response examples for the error cases the PDF shows;
path and query parameter text; and a description for every schema and
property.

Structure is unchanged: no required list, enum, pattern or bound moved,
no schema was renamed, and the health endpoints stay out of `paths`.
They are described in the info block instead, because the generated
router would mount them under /api. Every property whose `$ref` had
sibling keys now wraps the `$ref` in `allOf`: Redoc, Swagger UI and
oapi-codegen ignore the siblings and Fern reads them, so this is the
only form all four render. The `x-order` and
`x-go-type-skip-optional-pointer` keys beside those `$ref`s are dropped,
since neither ever applied there. The generated Go changes only in
comments; struct fields keep their order.

vacuum reports no warnings left. Its coverage rules are raised to
errors in a later commit.

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>

* docs(api): configProfile is required, the PDF left it out

The PDF never mentions `nico.configProfile`, and its create examples omit
it. The server requires it: a NICo node pool without one is rejected
("nico.configProfile is required when creating a nico node pool",
controller/internal/server/node_pools.go:298), and so is a control plane
("controlPlaneConfig.nico.configProfile is required for a nico cluster
control plane", cluster_control_plane_config.go:206 and :239). Every
example in the PDF would have failed with 400.

The field is now described as required on the node pool and control-plane
create schemas, the two create operations list it among their 400 causes,
and the three request examples carry it.

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>

* docs(api): describe OS profiles as the controller resolves them today

The PDF describes `osProfile` as the name of a release in an Operator
curated catalog of MachineImage, ClusterRelease and NodePoolRelease
entries, managed with nkectl. Those kinds exist as CRDs in
management-engine/ (#1085, 2026-09-29), but nothing consumes them yet:
management-engine/README.md says lifecycle reconciliation and the public
API are not implemented, and the controller still reads OS profiles from
its profiles directory (controller/internal/server/os_profiles.go:35),
supplied by the Operator as described in controller/profiles/README.md.

The reference now says what the API does today: `osProfile` and
`configProfile` name profiles the Operator supplies to the management
plane, and changing `osProfile` rolls the affected nodes. The catalog
text returns when the controller resolves names against it. Example
names follow the example bundle in controller/profiles/example.

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>

* docs(api): use the server's real error messages in the examples

Three error examples in the PDF are paraphrases. The server says:
"cluster update rejected: <op> in progress since <time>"
(controller/internal/server/clusters.go:67), "Cannot create node pool
when parent cluster is deleting" (node_pools.go:173), and for a
control-plane delete that would breach the minimum, the sentence in
controller/internal/nodes/control_plane_delete_request.go:57.

ClusterConditions also listed `upgrading` as required, a property the
schema does not define. The PDF's required list (provisioning,
provisioned, deleting) is the correct one. Nothing in the generated Go
refers to it, so only the spec changes.

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>

* chore(api): make the OpenAPI prose coverage rules errors

With the REST API Reference prose in the spec, vacuum reports nothing.
The coverage rules that were warnings so the gate could land first now
fail the gate: every operation, parameter, schema and property has a
description, and no description sits beside a bare `$ref`.

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>

* docs(api): quote the node-name pattern so renderers do not eat the angle brackets

Redoc rendered "Node names are <cluster>-<prefix>-<NNNN>" as "Node names are --":
markdown treats the angle brackets as HTML tags. Backticks keep them.

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>

* docs: make fern check pass and pin the Fern CLI

`fern check` could not run: fern/docs.yml named a `components` directory
that does not exist in the repository, so the checker failed to
initialize. With that line gone it ran, and reported three broken links,
all pointing at repository directories the documentation site cannot
serve. They now point at the directories on GitHub.

fern/fern.config.json pinned the CLI to `latest`; it now pins the version
CI runs, which make/tool-versions.mk carries as FERN_VERSION. Related:

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>
#330.

* ci(api): render the REST API Reference with Redocly and check the docs site

`make -C controller/api docs` renders openapi.yaml into one self-contained
HTML page with Redocly. It bundles first, because `build-docs` applies no
decorators, and redocly.yaml's `remove-x-internal` decorator is pointed at
`x-fern-ignore`, so the page drops the same surface the Fern site drops.
The output lands in controller/.local/, which git ignores. Node is
required; npx fetches the pinned CLI.

The new `API docs` workflow is advisory: it builds that page on every pull
request that touches the spec or the docs and uploads it as the
`api-reference` artifact, runs `fern check`, and on main publishes the
Fern site when FERN_TOKEN is set. The secret is not configured yet, so
that step is skipped and says so. Publishing needs a secret, which the
workflow design guide keeps out of the required gate; that is why this is
not a merge-gate member.

Both CLIs are pinned in make/tool-versions.mk. The runner's preinstalled
Node is used rather than a new pinned setup action.

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>

* fix(api): keep request-schema $ref properties bare

Wrapping a request property's `$ref` in `allOf` changed the 400 body.
kin-openapi reports a failure inside an `allOf` as a raw schema error,
"Error at \"/controlPlaneConfig\": Doesn't match schema \"not\"" followed
by a dump of the schema, instead of the one-line "request body has an
error: ..." message, and the middleware passes it through whole.
TestOpenAPIValidator_CreateRequiresExactlyOneProvider caught it: the
control-plane cases no longer carried the request-body prefix the test
uses to tell a schema rejection from a handler rejection.

The fifteen `$ref` properties in request schemas are bare again, with
their prose on the referenced schemas, which every renderer shows. The
response schemas keep the `allOf` form; nothing validates responses.
The sibling rule is an error, with the five deliberate `x-fern-ignore`
siblings on the `infra` properties listed in openapi-lint-ignore.yaml.
The generated Go changes only in comments.

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>

* build(api): regenerate with the Go toolchain api/go.mod declares

generate-check failed on the pull request while passing locally and on
the Linux box. The embedded copy of openapi.yaml in server.gen.go is
gzip-compressed, and compress/flate output differs between Go releases:
the workspace asks for Go 1.27.1, so a developer regenerating in the
workspace produces one blob, while generate-check.yml installs the
1.26.5 that controller/api/go.mod declares and produces another.

`make -C controller generate-api` now runs the generator with GOWORK=off,
since the api module is self-contained, and GOTOOLCHAIN pinned to the
version api/go.mod declares, so every developer regenerates the bytes
the gate expects. server.gen.go is regenerated that way here; only the
embedded blob changes.

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>

* docs: render the tag descriptions in the Fern API tab

controller/api/openapi.yaml now carries the concept text on its tags.
`tag-description-pages: true` makes Fern render each tag description as
the intro of its section in the REST API Reference, so that text ships
with the reference instead of only in Swagger UI.

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>

* ci(api): publish a Fern preview of the site for pull requests

The `API docs` workflow now publishes a Fern preview, API Reference tab
included, on every pull request and manual run that has FERN_TOKEN, and
writes the preview URL to the job summary and as a notice. A stable id,
pr-<number>, makes a later push overwrite the same preview, and a cleanup
job deletes it when the pull request closes.

FERN_TOKEN is an organization secret, but GitHub withholds secrets from
`pull_request` runs of fork pull requests, so those runs say why no
preview was published instead. Push the branch to this repository and
dispatch the workflow to preview a fork pull request.

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>

* docs(api): give Fern an absolute server and order the reference sections

The spec's only server was the relative `/api`, which is right for the
embedded Swagger UI and the request validator but left Fern rendering
request examples against `https:/https://api/...`. A second server with
the placeholder host the PDF uses, `https://nke.acme.example/api`, now
carries the examples; the relative one stays first, so Swagger UI's
default and the validator's routing are unchanged, and is marked
`x-fern-ignore`, so Fern and the Redocly page show only the absolute one.
The validator still accepts requests on any host through the relative
server; the server tests cover it.

In docs/index.yml the API tab is flattened, so the path no longer repeats
`rest-api-reference`, and the sections are laid out in reading order,
Clusters first, instead of in order of first appearance, which put the
one-endpoint Catalog section at the top.

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>

* docs: do not repeat rest-api-reference in the API tab's URL

The tab slug and the api item's slug were both derived from the same
title, so every reference page lived under
/nke/rest-api-reference/rest-api-reference/. skip-slug on the tab keeps
one segment.

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>

* docs: skip the api item's slug, not the tab's

skip-slug on the tab left the path unchanged on the preview; the
duplicated segment comes from the api item, so skip that one.

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>

---------

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>
2026-10-02 08:28:37 -04:00

67 lines
2.9 KiB
YAML

# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Lint rules for openapi.yaml. `make lint-spec` (part of `make lint`, so the
# merge gate runs it) applies them with vacuum, a Spectral-compatible linter
# pinned in make/tool-versions.mk.
#
# Everything here is an error: the file must be valid for the generator, the
# request validator, Swagger UI and Fern, and every operation, parameter,
# schema and property must carry a description, so the REST API Reference
# cannot lose coverage once it is complete.
extends: [[spectral:oas, recommended]]
rules:
# Errors: the file must be valid for oapi-codegen, the request validator,
# Swagger UI and Fern alike. The server loads the spec without checking
# examples, so this is the only place a bad example is caught.
oas3-valid-schema-example: error
oas3-unused-component: error
operation-operationId: error
operation-operationId-unique: error
# Prose coverage.
#
# A description beside a bare `$ref` is read by Fern and ignored by Redoc,
# Swagger UI and oapi-codegen, so it is an error here. Put the text on the
# referenced schema, or, in a response schema only, wrap the `$ref` in
# `allOf`. Request schemas keep bare `$ref`s: kin-openapi reports a failure
# inside an `allOf` as a raw schema error with a schema dump instead of the
# one-line request-body error, which changes the 400 body clients see.
# `x-fern-ignore` beside a `$ref` is deliberate, Fern reads it there; the
# five places that do it are listed in openapi-lint-ignore.yaml.
no-$ref-siblings: error
operation-tags: error
component-description: error
oas3-parameter-description: error
operation-description-present:
description: Every operation has a description. The summary is a title, not an explanation.
message: operation has no description
severity: error
given: "$.paths[*][get,put,post,patch,delete]"
then:
field: description
function: truthy
property-description-present:
description: Every schema property has a description.
message: property has no description
severity: error
given: "$.components.schemas[*].properties[*]"
then:
field: description
function: truthy
# Off: rules this API breaks on purpose.
# Paths and properties are camelCase (`/nodePools`, `podCIDR`). The wire
# format is fixed.
paths-kebab-case: off
camel-case-properties: off
# DELETE /nodes/{nodeID} takes an optional body (`machineHealthIssue`).
no-request-body: off
# `not:` subschemas carry no type on purpose, and create/response/update
# twins repeat their descriptions on purpose.
oas-missing-type: off
description-duplication: off
# Examples arrive with the docs port. Until then this rule, which wants one
# on every media type, would drown the report.
oas3-missing-example: off