[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
- After generating, build gem
gem build openapi_client.gemspec
- Install it
gem install openapi_client-1.0.0.gem
- Use it in your ruby code in
test.py
file for example: `require 'openapi_client' - 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.