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
  • #4690
Closed
Open
Issue created Dec 03, 2019 by Administrator@rootContributor

[BUG] Ruby models order in inheritance case

Created by: gigaga

Description

By generating a ruby client, the models order defined in openapi_client.rb is incorrect in case where there is some inheritance.

openapi-generator version
$ openapi-generator version
4.2.2
OpenAPI declaration file content or url

petstore.yaml

openapi: 3.0.0
info:
  version: 1.0.0-SNAPSHOT
  title: petstore
  description: |
    This is the specification of Petstore with the following resources:

    - Pet
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets:
    get:
      tags:
        - pets
      responses:
        "200":
          description: A paged array of pets
          content:
            application/json:
              schema:
                type: object
                description: 1.0.0
                required:
                  - pet_type
                properties:
                  pet_type:
                    type: string
                discriminator:
                  propertyName: pet_type
                  mapping:
                    dog: "#/components/schemas/Dog"
                    cat: "#/components/schemas/Cat"
                    lizard: "#/components/schemas/Lizard"
components:
  schemas:
    Pet:
      type: object
      required:
        - pet_type
      properties:
        pet_type:
          type: string
        startDate:
          type: string
          example: "2019-11-08"
        num:
          type: integer
          example: 1
      discriminator:
        propertyName: pet_type
        mapping:
          dog: "#/components/schemas/Dog"
          cat: "#/components/schemas/Cat"
          lizard: "#/components/schemas/Lizard"
    Dog:
      allOf:
        - $ref: "#/components/schemas/Pet"
        - type: object
          properties:
            bark:
              type: string
    Cat:
      allOf:
        - $ref: "#/components/schemas/Pet"
        - type: object
          properties:
            name:
              type: string
    Lizard:
      allOf:
        - $ref: "#/components/schemas/Pet"
        - type: object
          properties:
            lovesRocks:
              type: boolean
Command line used for generation
openapi-generator generate --generator-name ruby -i petstore.yaml
Steps to reproduce
  1. After generating, build gem gem build openapi_client.gemspec
  2. Install it gem install openapi_client-1.0.0.gem
  3. Use it in your ruby code in test.py file for example: `require 'openapi_client'
  4. Execute it ruby test.py

The following error has occured: uninitialized constant OpenapiClient::Pet (NameError)

The problem is due to openapi_client.rb file where Cat, Dogs and Lizard modules are loaded before Pet.

Suggest a fix

Rather to generate the model list from alphabetic order, generate it in the same order of OpenAPI specs file.

Assignee
Assign to
Time tracking