Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #453
Closed
Open
Issue created Jul 04, 2018 by Administrator@rootContributor

[Python] Generated model for component with "allOf" has no attributes

Created by: ghost

Description

Given below is a snippet of the input YAML file I am using. I have several components in the original file that are all have the same structure as "AddEmailContactRequest". All of these components' classes are generated without any attributes, although the YAML file is read correctly. Here is the relevant snippet of the generated code for "AddEmailContactRequest":

`class AddEmailContactRequest(object):
    openapi_types = {
    }
    attribute_map = {
    }

    def __init__(self):
        self.discriminator = None`

While what it should generate is the below code (I manually fixed it because, well, I need to keep working :) ):

`class AddEmailContactRequest(object):
    openapi_types = {
        'type': 'str',
        'attributes': 'EmailContact'
    }
    attribute_map = {
        'type': 'type',
        'attributes': 'attributes'
    }

    def __init__(self, type=None, attributes=None):  # noqa: E501
        self._type = None
        self._attributes = None
        self.discriminator = None

        self.type = type
        self.attributes = attributes`

NOTE - I am also getting several warnings as follows during generation: [main] WARN o.o.codegen.DefaultCodegen - Unknown type found in the schema: object

openapi-generator version

I'm building from branch 4.0.x, but have encountered this problem with tag v3.0.3 as well.

OpenAPI declaration file content or url
openapi: "3.0.1"
servers:
  - url: 'http://www.myserver.com/api'
info:
  version: '1.0'
  title: MYSERVER


paths:
  '/email-contacts':
    post:
      summary: addEmailContact
      tags:
        - sometag
      operationId: addEmailContact
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:              
                    $ref: '#/components/schemas/AddEmailContactResponse'
      security: []
      x-unitTests: []
      x-operation-settings:
        CollectParameters: false
        AllowDynamicQueryParameters: false
        AllowDynamicFormParameters: false
        IsMultiContentStreaming: false
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:            
                  $ref: '#/components/schemas/AddEmailContactRequest'
        required: true


components:
  schemas:
    AddEmailContactRequest:
      allOf:
        - $ref: '#/components/schemas/JsonAPIPostRequestWrapper'
      title: addEmailContactRequest
      type: object
      properties:
        attributes:
          $ref: '#/components/schemas/EmailContact'
      required:
        - attributes
        
    AddEmailContactResponse:
      title: addEmailContactResponse
      type: object
      properties:
        type:
          description: ''
          type: string
        id:
          description: ''
          type: string
        attributes:
          $ref: '#/components/schemas/EmailContact'
      required:
        - type
        - id
        - attributes
   
    EmailContact:
      title: EmailContact
      description: ''
      type: object
      properties:
        name:
          description: ''
          type: string
        address:
          description: ''
          type: string
      required:
        - name
        - address

    JsonAPIPostRequestWrapper:
      title: JsonAPIPostRequestWrapper
      type: object
      properties:
        type:
          description: ''
          type: string
      required:
        - type
Command line used for generation

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i path_to_yaml_file_as_seen_above.yaml -g python -o /outputdir -v

Steps to reproduce
  1. Clone the project
  2. Checkout branch 4.0.x
  3. Build with "mvn clean install"
  4. Run the generation command as shown in previous section with given YAML file
  5. Under the "models" directory, go to add_email_contact_request.py --> The attributes will be missing.
Related issues/PRs

I think this might be related to an issue I saw for JAVA generation - https://github.com/OpenAPITools/openapi-generator/issues/340

Suggest a fix/enhancement

I wish I knew.. I would fix it myself :)

Assignee
Assign to
Time tracking