yaacov / crdtoapi

Use kubernetes CRD definitions to create OpenAPI schema file
Apache License 2.0
3 stars 1 forks source link

Required fields are sometimes not marked as such #1

Closed rotty3000 closed 4 months ago

rotty3000 commented 4 months ago

I have a CRD with:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  ...
spec:
  ...
  versions:
    - name: v1alpha1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            apiVersion:
              type: string
            kind:
              type: string
            metadata:
              type: object
            spec:
             ...
          required:
            - apiVersion
            - kind
            - metadata
            - spec

After running:

npx crdtoapi -i ./crds/ -o ./openapi.yaml
npx crdtotypes -i ./openapi.yaml -o ./src/crd/

I get a type having:

  ...
  /** metadata
   *
   * @required {false}
   * @originalType {FooMetadata}
   */
  metadata?: IoK8sApimachineryPkgApisMetaV1ObjectMeta;
  /** spec
   *
   * @required {false}
   */
  spec?: FooSpec

PR forthcoming.

yaacov commented 4 months ago

PR forthcoming.

Nice

rotty3000 commented 4 months ago

very nice tool @yaacov ! It's going to save me lots of pain and suffering 😅

yaacov commented 4 months ago

https://www.npmjs.com/package/crdtoapi/v/0.0.16 - :tada: