kubernetes / kube-openapi

Kubernetes OpenAPI spec generation & serving
Apache License 2.0
317 stars 205 forks source link

OpenAPI V3 specifications do not mark requestBody as "required" #427

Closed tanmaykm closed 1 year ago

tanmaykm commented 1 year ago

This is an example of this issue in the OpenAPI V3 specification of createBatchV1NamespacedCronJob

"requestBody": {
  "content": {
    "*/*": {
      "schema": {
        "$ref": "#/components/schemas/io.k8s.api.batch.v1.CronJob"
      }
    }
  }
},

The same in the OpenAPI V2 specification is marked as required.

...
  "post": {
    "consumes": [
      "*/*"
    ],
    "description": "create a CronJob",
    "operationId": "createBatchV1NamespacedCronJob",
    "parameters": [
      {
        "in": "body",
        "name": "body",
        "required": true,
        "schema": {
          "$ref": "#/definitions/io.k8s.api.batch.v1.CronJob"
        }
      },
...

From what the specfication mentions here, requestBody must be marked with "required": true, otherwise they are considered optional - "Request bodies are optional by default. To mark the body as required, use required: true."

For the kubernetes requests that accept a request body, the body does seem a mandatory parameter. So looks like the specification generation for OpenAPI v3 needs to address this.

Jefftree commented 1 year ago

Thanks for pointing this out, opened https://github.com/kubernetes/kube-openapi/pull/428 to address it.

apelisse commented 1 year ago

Nice catch, thank you!