instrumenta / openapi2jsonschema

Convert OpenAPI definitions into JSON schemas for all types in the API
Other
226 stars 87 forks source link

remove integer type from oneof #28

Closed brendanjryan closed 5 years ago

brendanjryan commented 5 years ago

Removes the integer schema from the io.k8s.apimachinery.pkg.api.resource.Quantity patch.

The jsonschema spec denotes that the number type is a superset of integer. Thus, this oneOf will always fail if given an integer, as it satisfies two types.

Verified by running kubeval against the schemas generated by this patch:

./bin/kubeval service.yaml --schema-location file:///Users/brendanjryan/projects/kubernetes-json-schema
The file service.yaml contains a valid CronJob
apiVersion: batch/v2alpha1
kind: CronJob
metadata:
  name: "sample-cron"
spec:
  schedule: "0 1 * * *" # daily at 1am pacific time
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 3
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: "my_app"
              resources:
                requests:
                  cpu: 0.1
                  memory: "1500Mi"
                limits:
                  cpu: 2
                  memory: "2000Mi"
garethr commented 5 years ago

Thanks. I'll regenerate the master schemas now and test out.

garethr commented 5 years ago

Confirmed this should be fixed now. Thanks.

$ kubeval job.yaml 
The file bob.yaml contains an invalid CronJob
---> spec.jobTemplate.spec.template.spec.containers.0.resources.limits: Must validate one and only one schema (oneOf)
# Publish new schemas
$ kubeval job.yaml
The file bob.yaml contains a valid CronJo