Skip to content

Don't include $ref definitions when path is relative #209

@alejandrofdiaz

Description

@alejandrofdiaz

I've stumble across a problem when splitting my huge openapi spec file in pieces.
We decided to take apart some definitions into different files and reference them from our main definition with $ref (as this guide recommends).

Turns out that output definition file does not include that schema, put any instead. I will show you an example:

openapi.yml

openapi: 3.0.0
info:
  title: Sample API
  description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
  version: 0.1.9
servers:
  - url: http://api.example.com/v1
    description: Optional server description, e.g. Main (production) server
  - url: http://staging-api.example.com
    description: Optional server description, e.g. Internal staging server for testing
paths:
  /users:
    get:
      summary: Returns a list of users.
      description: Optional extended description in CommonMark or HTML.
      responses:
        '200':    # status code
          description: A JSON array of user names
          content:
            application/json:
              schema: 
                type: array
                items: 
                  $ref: "reference.yaml#/account_base"
                  

reference.yaml

account_base:
  type: "object"
  properties:
    id:
      type: "string"
      description: "User's ID"
      example: "26345b2f-3125-11eb-87d8-801234232f4e"
    email:
      type: "string"
      description: "User's Email"
      example: "[email protected]"
      format: "email"

Run cli command: swagger-typescript-api -p ./openapi.yaml -n output.d.ts --no-client --route-types --responses --union-enums

output.d.ts

/* eslint-disable */
/* tslint:disable */
/*
 * ---------------------------------------------------------------
 * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API        ##
 * ##                                                           ##
 * ## AUTHOR: acacode                                           ##
 * ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
 * ---------------------------------------------------------------
 */

export namespace users {
  /**
   * @description Optional extended description in CommonMark or HTML.
   * @name UsersList
   * @summary Returns a list of users.
   * @request GET:/users
   * @response `200` `(any)[]` A JSON array of user names
   */
  export namespace UsersList {
    export type RequestParams = {};
    export type RequestQuery = {};
    export type RequestBody = never;
    export type RequestHeaders = {};
    export type ResponseBody = any[]; //<- this should be AccountBase
  }
}

Is this something i can fix by setting a parameter?

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestnext major releaseThis changes of code will added at next major release (*.0.0)

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions