question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
spacethercommented, Jan 11, 2022

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
1reaction
spacethercommented, Jul 8, 2021

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[BUG] Python client code generation with allOf and discriminator
I am trying to generate python client code from yaml that uses allOf with a discriminator property, generated code in 4.3.1 is not...
Read more >
swagger codegen missing attributes with allOf - Stack Overflow
When generating a python client we notice that model classes generated seem to be missing any attributes defined in the first allOf reference....
Read more >
Using $ref - Swagger
According to RFC3986, the $ref string value (JSON Reference) should contain a URI, which identifies the location of the JSON value you are...
Read more >
Language Guide (proto3) | Protocol Buffers - Google Developers
This is a reference guide – for a step by step example that uses many of ... Python is a little different —...
Read more >
Understanding JSON Schema 2020-12 documentation
Schema Composition¶ ; allOf ·, the given data must be valid against all of the given subschemas. · "allOf" · "string" }, ;...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found