Skip to content

Json requestBody cannot be optional #1354

@orelmaliach

Description

@orelmaliach

Describe the bug
Generating an endpoint from an operation where requestBody has required: false (or required is unspecified) and an application/json content, still requires a body, despite it being optional.
Providing a None body with ...sync_detailed(body=None) will result in nil dereference in _kwargs["json"] = body.to_dict().
Providing an 'empty' body such as ...sync_detailed(body=RequestBody()) will result in an empty json object. i.e. {}, which is not desirable.

OpenAPI Spec File

openapi: 3.1.1
info:
  title: ""
  version: ""
paths:
  /request:
    post:
      operationId: request
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
      responses:
        "201":
          description: ""

Desktop (please complete the following information):

  • OS: macOS 15.7.1
  • Python version: 3.13.3
  • openapi-python-client version: 0.25.1

Additional context
I've described the bug for application/json request bodies, but it may exist for other content types as well.
Similarly, I provided an example using openAPI spec version 3.1.1, but it might be relevant for other versions as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐞bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions