Skip to content

Commit

Permalink
feat: generate a single JSON schema for multidoc config
Browse files Browse the repository at this point in the history
Rework docgen to scan a whole directory for multidoc config types recursively and generate a single schema for all of them.

Annotate the files which need to be scanned by docgen while generating a schema by `//docgen:jsonschema`.

Move and rename the schema.

Bring back schema tests.

Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com>
  • Loading branch information
utkuozdemir committed Jan 16, 2024
1 parent f70b47d commit 6c5a0c2
Show file tree
Hide file tree
Showing 19 changed files with 6,786 additions and 88 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Expand Up @@ -979,7 +979,7 @@ WORKDIR /src
COPY --from=talosctl-targetarch /talosctl-${TARGETOS}-${TARGETARCH} /bin/talosctl
RUN env HOME=/home/user TAG=latest /bin/talosctl docs --config /tmp/configuration \
&& env HOME=/home/user TAG=latest /bin/talosctl docs --cli /tmp
COPY ./pkg/machinery/config/types/v1alpha1/schemas/ /tmp/schemas/
COPY ./pkg/machinery/config/schemas/*.schema.json /tmp/schemas/

FROM pseudomuto/protoc-gen-doc as proto-docs-build
COPY --from=generate-build /api /protos
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -635,6 +635,8 @@ github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkB
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
github.com/safchain/ethtool v0.3.0 h1:gimQJpsI6sc1yIqP/y8GYgiXn/NjgvpM0RNoWLVVmP0=
github.com/safchain/ethtool v0.3.0/go.mod h1:SA9BwrgyAqNo7M+uaL6IYbxpm5wk3L7Mm6ocLW+CJUs=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b h1:gQZ0qzfKHQIybLANtM3mBXNUtOfsCFXeTsnBqCsx1KM=
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.22 h1:wJrcTdddKOI8TFxs8cemnhKP2EmKy3yfUKHj3ZdfzYo=
Expand Down
155 changes: 121 additions & 34 deletions hack/docgen/main.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions hack/docgen/main_test.go
Expand Up @@ -9,11 +9,11 @@ import (
"testing"
)

// This test mainly exist for easier debugging with debugger.
// This test exists mainly for easier debugging with debugger.
func TestProcessFile(t *testing.T) {
inputFile := filepath.Join("..", "..", "pkg", "machinery", "config", "types", "v1alpha1", "v1alpha1_types.go")
outputFile := filepath.Join(t.TempDir(), "out.go")
schemaOutputFile := filepath.Join(t.TempDir(), "out.schema.json")
versionTagFile := filepath.Join("..", "..", "pkg", "machinery", "gendata", "data", "tag")
processFile([]string{inputFile}, outputFile, schemaOutputFile, versionTagFile)
processFiles([]string{inputFile}, outputFile, schemaOutputFile, versionTagFile)
}

0 comments on commit 6c5a0c2

Please sign in to comment.