openapi-generator: [BUG] Using `allOf` and `$ref` generates an `object` in the python model when it should be a `string`

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?
Description
openapi-generator version

Docker CLI latest

OpenAPI declaration file content or url

BankTransferCreateRequest:
  title: BankTransferCreateRequest
  type: object
  description: BankTransferCreateRequest defines the request schema for `/bank_transfer/create`
  properties:
    access_token:
      description: Some Description
      allOf:
        - $ref: '#/components/schemas/AccessToken'
 
AccessToken:
  title: AccessToken
  type: string
  description: The access token associated with the Item data is being requested for.

/bank_transfer/create:
  post:
    operationId: bankTransferCreate
    requestBody:
      required: true
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/BankTransferCreateRequest'

Generation Details

$(OPENAPI_GENERATOR_LATEST) -g python -i local/$(OPENAPI_FILE) -o local/$(OUTPUT_FOLDER)/generated-python

Steps to reproduce

Run the generator, try accessing the BankTransferCreateRequest model. See that access_token is object instead of string.

return {
    'access_token': (object,),  # noqa: E501
}
Related issues/PRs
Suggest a fix

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 21 (19 by maintainers)

Most upvoted comments

Re-opening this until examples have been added in python-experimental verifying that this is working at levels deeper than a root component with composition. Tests are needed of:

  1. component property with composition
  2. parameter with composition
  3. request body with composition
  4. response body with composition
  5. parameter property with composition
  6. request body property with composition
  7. response body property with composition

If you define patient as its own component and then $ref to patient in PatientScanDto does this work? I suspect that this is an openapi inline schema issue and is not specific to the python generator. Does you allOf define the value in patient? If so should allOf be indented?

I think we have a workaround for now. Thanks for talking through it @spacether!! Hoping to get a sponsorship going here soon for you all.

It is a valid spec, our tooling just isn’t there yet. The main composed schema use case that the generator supports is a component object schema that contains allOf or oneOf or anyOf. Additionally, python supports the use cases where:

  • oneOf can have mixed types
  • allOf is combined with oneOf or anyOf

Oh I see. Yep that does fix my problem 😄!