Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing import statement when using "oneOf" #52

Closed
Shihta opened this issue Nov 12, 2019 · 2 comments
Closed

Missing import statement when using "oneOf" #52

Shihta opened this issue Nov 12, 2019 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@Shihta
Copy link

Shihta commented Nov 12, 2019

In version 0.6.0, if I use "oneOf" in openapi spec., the import statement will gone.
Any idea?

@luisfpg
Copy link
Contributor

luisfpg commented Nov 12, 2019

Can you, please, provide an example openapi definition and the generated TS file?

@Shihta
Copy link
Author

Shihta commented Nov 13, 2019

My openapi definition (named openapi-backend.yml):

openapi: "3.0.2"
info:
  description: "This is qwer Director"
  version: "0.3.0"
  title: "qwer Director"
servers:
- url: http://{host}:{port}{basePath}
  description: The production API server
  variables:
    host:
      default: qwer-swagger.abc.def
    port:
      default: '8000'
    basePath:
      default: /b
externalDocs:
  description: "Find out more about Swagger"
  url: "https://swagger.io"


paths:
  /room_info/{roomId}:
    get:
      summary: "Finds room information by roomId"
      description: "Multiple values can be provided"
      operationId: routes.get_room_info
      parameters:
        - name: "roomId"
          in: "path"
          description: "ID of room to return"
          required: true
          schema:
            type: "integer"
            format: "int32"
      responses:
        200:
          description: "successful operation"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Res_room_info"
        400:
          description: "Invalid request"

  /import_json:
    post:
      summary: "Import json" 
      operationId: routes.post_import_json
      requestBody:
        description: "Json object to be sent"
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Room'
      responses:
        200:
          description: "successful operation"
        400:
          description: "Invalid status value"


components:
  schemas:
    Room:
      type: object
      properties:
        room_name:
          type: "string"
          minLength: 1
          maxLength: 100
          example: TokyoDC Room1
        floor_wiring:
          type: boolean
          default: true
        rack_rows:
          type: "array"
          items:
            $ref: "#/components/schemas/Rack_row"
      required:
        - room_name
        - floor_wiring
        - rack_rows
        
    Rack_row:
      type: object
      properties:
        rack_row_name:
          type: "string"
          minLength: 1
          maxLength: 100
          example: East Rack Row 1
        row_index_in_room:
          type: "integer"
          format: "int32"
          example: 1
        maximum_rack_in_this_row:
          type: "integer"
          format: "int32"
          example: 16
        racks:
          type: "array"
          items:
            oneOf:
              - $ref: "#/components/schemas/Rack"
              - $ref: "#/components/schemas/Ru_info_of_rackrow_info"
      required:
        - rack_row_name
        - row_index_in_room
        - maximum_rack_in_this_row
        - racks
        
    Rack:
      type: object
      properties:
        rack_name:
          type: "string"
          minLength: 1
          maxLength: 100
          example: QCT NGCO Rack 1
        rack_index_in_row:
          type: "integer"
          format: "int32"
          example: 1
        rack_type_name:
          type: "string"
          minLength: 1
          maxLength: 50
          example: QCT 2019 Type 1
      required:
        - rack_name
        - rack_index_in_row
        - rack_type_name
        
    Res_room_info:
      type: object
      properties:
        rack_rows:
          type: "array"
          items:
            $ref: "#/components/schemas/Rack_row"

    Ru_info_of_rackrow_info:
      type: object
      properties:
        rack_index_in_row:
          type: "integer"
          format: "int32"
          example: 1
        rack_id:
          type: "integer"
          format: "int32"
          example: 1
        rack_name:
          type: "string"
          minLength: 1
          maxLength: 150
          example: Rack One
        ru_total:
          type: "integer"
          format: "int32"
          example: 300
        ru_free:
          type: "integer"
          format: "int32"
          example: 120

My command: ng-openapi-gen --input openapi-backend.yml --output myapp --modelPrefix be
The file myapp/models/be-rack-row.ts would be:

/* tslint:disable */
export interface beRack_row  {
  maximum_rack_in_this_row: number;
  rack_row_name: string;
  racks: Array<beRack | beRu_info_of_rackrow_info>;
  row_index_in_room: number;
}

@luisfpg luisfpg added the bug Something isn't working label Dec 3, 2019
@luisfpg luisfpg added this to the 0.7.0 milestone Dec 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants