OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.57k stars 6.52k forks source link

[BUG] Object with additionalProperties detected as "free-form" #7241

Open chrylis opened 4 years ago

chrylis commented 4 years ago
Description

I have a type Money and a type MoneyTuple, which simply has additionalProperties: $ref: '#/Money'. Despite that the properties are all typed, the Java generator decides that this is a "free-form object" and doesn't output a DTO for it. Other types ref'ing MoneyTuple then fail.

The equivalent code NumberTuple where the values are numbers works as expected.

openapi-generator version

I'm using OpenAPI Generator 4.3.1 from the Maven plugin.

OpenAPI declaration file content or url
components:
  schemas:
    Money:
      type: object
      required: [currency, amount]
      properties:
        currency:
          type: string
        amount:
          type: string

    MoneyTuple: # ignored as "free-form object"
      type: object
      additionalProperties:
        $ref: '#/components/schemas/Money'

    MoneyTupleSeries: # fails on compilation because MoneyTuple isn't generated
      type: array
      items:
        type: object
        required: [label, values]
        properties:
          label:
            type: string
          values:
            $ref: '#/components/schemas/MoneyTuple'

    NumericTuple: # extends HashMap<String, Double>
      type: object
      additionalProperties:
        type: number
        format: double
Generation Details

I am using the Maven plugin with <generateAliasAsModel>true</generateAliasAsModel>.

TomaszRumpca commented 4 years ago

I have exaclty the same problem while migrating from swagger-codegen to openapi-generator. Swagger codegen is able to handle that and generate an alias for HashMap<String, Money>.

jennie-sfdc commented 1 year ago

same here. have been thinking how to have a workaround :( I dont think this is fixed in v6 either