OpenAPITools / OpenAPITools/openapi-generator

[BUG][Python] Object with ref in additionalProperties without property present raises an AttributeError

Open
#20,021 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When there is optional property defined that is a map (= object with additionalProperties that points to a ref/enum), then Python will not be able to decode the json data if the property is not present.
It fails with: AttributeError: 'NoneType' object has no attribute 'items'

openapi-generator version

7.9.0

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Test
  description: Test
  version: 0.1.0
servers:
  - url: "http://localhost:8080"
paths:
  /status:
    get:
      operationId: getStatus
      responses:
        '200':
          description: ok
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Status"
components:
  schemas:
    Status:
      type: object
      properties:
        incorrect:
          type: object
          additionalProperties:
            $ref: "#/components/schemas/State"
    State:
      type: string
      enum: ["disabled","enabled","unknown"]
Generation Details
docker run --rm \
    -v "$(pwd):/local" \
    openapitools/openapi-generator-cli:v7.9.0 generate \
    -i /local/rc23-api.yaml \
    -g python \
    -o /local/out \
    --additional-properties=packageVersion=1.0.0,packageName=my_client,projectName=my-api
Steps to reproduce

Call getStatus where the server omits the "incorrect" property in the json value.
This is interpreted as the property being "None" by Python.

Related issues/PRs

Looks related to #18628.

Suggest a fix

I created a PR (soon) to refer to this bug.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Use the supplied OpenAPI YAML and Docker generation command to reproduce the getStatus response with the optional "incorrect" property omitted. Trace the generated Python client's decoding path for that response; done means the response decodes without the reported AttributeError when the map property is absent.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, python
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.