Python: make_instance generates syntax error for optional nullable fields with default null in nested objects

Author: sieiraCreated Sep 29, 2026Updated Sep 29, 2026

Bug

When an optional nullable field with anyOf: [type: object, type: null] appears as the 4th field in an object, the Python test generator produces invalid syntax:

python
prop4 = ,

instead of:

python
prop4 = None,

Reproduction

Minimal OpenAPI spec:

yaml
openapi: 3.1.0
info:
  title: Minimal reproduction
  description: Minimal reproduction spec
  version: "1.0"
paths:
  /a:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                object1:
                  type: object
                  properties:
                    prop1:
                      type: object
                      properties:
                        prop: 
                          type: string
                    prop2:
                      type: object
                      properties:
                        prop:
                          type: string
                    prop3:
                      type: object
                      properties:
                        prop:
                          type: string
                    prop4:
                      anyOf:
                        - type: object
                          properties:
                            prop:
                              type: string
                        - type: null

Generate Python client: openapi-generator-cli generate -i spec.yaml -g python -o out

The generated test file contains prop4 = , -- a syntax error.

Source: OpenAPITools/openapi-generator