Skip to content

[BUG] [Python] Models with only additionalProperties are not generated #2078

@spacether

Description

@spacether

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

When one wants to create a model that accepts any string variable name and assigns a value of type string/number/integer/boolean/array/object one must use the additionalProperties class.
But when one runs that spec through generation, models with only additionalProperties are omitted.
These models should be generated to allow map models where one can go from an arbitrary key to a type checked value.

openapi-generator version

4.0.0-SNAPSHOT

OpenAPI declaration file content or url
swagger: '2.0'
info:
  description: "some text"
  version: 1.0.0
  title: other text
host: fake.com
basePath: /v1
schemes:
  - http
paths:
  /route:
    post:
      summary: Create a AdditionalPropertiesClass
      description: ''
      operationId: createAdditionalPropertiesClass
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - in: body
          name: additionalPropertiesClass
          description: object that needs to be created
          required: true
          schema:
            $ref: '#/definitions/AdditionalPropertiesClass'
      responses:
        200:
          description: Success
definitions:
  AdditionalPropertiesClass:
    type: object
    properties:
      string_value:
        type: object
        additionalProperties:
          type: string
      number_value:
        type: object
        additionalProperties:
          type: number
      integer_value:
        type: object
        additionalProperties:
          type: integer
      boolean_value:
        type: object
        additionalProperties:
          type: boolean
      array_value:
        type: object
        additionalProperties:
          type: array
          items:
            type: object
      map_value:
        type: object
        additionalProperties:
          type: object
          additionalProperties:
            type: object
  StringAdditionalPropertiesClass:
    type: object
    additionalProperties:
      type: string
  NumberAdditionalPropertiesClass:
    type: object
    additionalProperties:
      type: number
  IntegerAdditionalPropertiesClass:
    type: object
    additionalProperties:
      type: integer
  BooleanAdditionalPropertiesClass:
    type: object
    additionalProperties:
      type: boolean
  ArrayAdditionalPropertiesClass:
    type: object
    additionalProperties:
      type: array
      items:
        type: object
  MapAdditionalPropertiesClass:
    type: object
    additionalProperties:
      type: object
      additionalProperties:
        type: object
Command line used for generation

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i client.yaml -g python -o client -DpackageName=client

Steps to reproduce
  • Run the above command to generate the files
    Note the terminal logging:
[main] INFO  o.o.codegen.DefaultGenerator - Model StringAdditionalPropertiesClass not generated since it's an alias to map (without property)
[main] INFO  o.o.codegen.DefaultGenerator - Model NumberAdditionalPropertiesClass not generated since it's an alias to map (without property)
[main] INFO  o.o.codegen.DefaultGenerator - Model IntegerAdditionalPropertiesClass not generated since it's an alias to map (without property)
[main] INFO  o.o.codegen.DefaultGenerator - Model BooleanAdditionalPropertiesClass not generated since it's an alias to map (without property)
[main] INFO  o.o.codegen.DefaultGenerator - Model ArrayAdditionalPropertiesClass not generated since it's an alias to map (without property)
[main] INFO  o.o.codegen.DefaultGenerator - Model MapAdditionalPropertiesClass not generated since it's an alias to map (without property)

Inspecting the models generated we see only:
client/client/models/additional_properties_class.py

Related issues/PRs

#2028
#2049

Suggest a fix

Generate the models to allow map models where one can go from an arbitrary key to a type checked value.

Note: I am the author of the above pull request.
For the above first pull request, I will focus on getting additionalProperties work on models that have properties + additionalProperties set. A later PR should address this issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions