acacode / acacode/swagger-typescript-api

Don't include $ref definitions when path is relative

未關閉
#209 4 則留言 2 個 reaction 已指派 1 人 已被 @js2me 認領 在 GitHub 檢視
enhancement
主要語言
TypeScript
星號
4.1k
分支
436
PR 合併指標
30 天內沒有已合併 PR

描述

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](https://swagger.io/docs/specification/using-ref/)).

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: "a@a.com"
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?

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。