Skip to content

Commit

Permalink
Add json format docs for crdhub
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Oct 19, 2023
1 parent 76c06a1 commit a9f7b06
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cmd/gen-docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func GenDescriptor(dir string) error {

if rd.Spec.Validation != nil && rd.Spec.Validation.OpenAPIV3Schema != nil {
schema := rd.Spec.Validation.OpenAPIV3Schema
schema.Schema = "http://json-schema.org/schema#"
if prop, ok := schema.Properties["apiVersion"]; ok {
prop.Enum = []crdv1.JSON{
{[]byte(fmt.Sprintf("%q", rd.Spec.Resource.GroupVersion()))},

Check failure on line 76 in cmd/gen-docs/main.go

View workflow job for this annotation

GitHub Actions / k8s (v1.27.1)

composites: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1.JSON struct literal uses unkeyed fields (govet)
Expand All @@ -88,6 +89,12 @@ func GenDescriptor(dir string) error {
return err
}
os.WriteFile(filepath.Join(vdir, "openapiv3_schema.yaml"), data, 0o644)

Check failure on line 91 in cmd/gen-docs/main.go

View workflow job for this annotation

GitHub Actions / k8s (v1.27.1)

Error return value of `os.WriteFile` is not checked (errcheck)

data, err = json.MarshalIndent(schema, "", " ")
if err != nil {
return err
}
os.WriteFile(filepath.Join(vdir, "openapiv3_schema.json"), data, 0o644)

Check failure on line 97 in cmd/gen-docs/main.go

View workflow job for this annotation

GitHub Actions / k8s (v1.27.1)

Error return value of `os.WriteFile` is not checked (errcheck)
}
}
return nil
Expand All @@ -114,6 +121,12 @@ func GenResourceEditor(dir string) error {
return err
}
os.WriteFile(filepath.Join(vdir, "resourceeditor.yaml"), data, 0o644)

data, err = json.MarshalIndent(rd, "", " ")
if err != nil {
return err
}
os.WriteFile(filepath.Join(vdir, "resourceeditor.json"), data, 0o644)
}
return nil
}
Expand Down Expand Up @@ -295,5 +308,11 @@ func WriteDescriptor(dir string, crd *crdv1.CustomResourceDefinition) error {
return err
}
os.WriteFile(filepath.Join(rdir, "crd.yaml"), data, 0o644)

data, err = json.MarshalIndent(crd, "", " ")
if err != nil {
return err
}
os.WriteFile(filepath.Join(rdir, "crd.json"), data, 0o644)
return nil
}

0 comments on commit a9f7b06

Please sign in to comment.