acacode / acacode/swagger-typescript-api

API client with discriminators is generated incorrectly

オープン
#685 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
TypeScript
スター
4.1k
フォーク
436
PR マージ指標
30日以内にマージされた PR はありません

説明

Hi, here's an example schema:

Example schema

```yaml
openapi: 3.0.1
info:
title: Example API
version: v1
paths:
/pet:
post:
summary: Create pet
requestBody:
content:
application/json:
schema:
type: object
required:
- data
properties:
data:
type: object
required:
- type
- payload
discriminator:
propertyName: type
mapping:
CAT: '#/components/schemas/cat'
DOG: '#/components/schemas/dog'
properties:
type:
$ref: '#/components/schemas/pet_kind'
payload:
type: object
oneOf:
- $ref: '#/components/schemas/cat'
- $ref: '#/components/schemas/dog'
responses:
'204':
description: all good!

components:
schemas:
cat:
type: object
properties:
name:
type: string
breed:
type: string
dog:
type: object
properties:
name:
type: string
breed:
type: string
pet_kind:
type: string
description: type of animal
enum: [CAT, DOG]
```

it's a pretty simple schema with discriminator on the property `type` that determines the `payload` object. There's an enumb called `pet_kind` which has two options `CAT` and `DOG`.

## Expected behaviour

It's expected, that the `pet_kind` enum would be generated as `PetKind` in the data definition section and would be referenced in the API client.

## Actual begaviour

The `pet_kind` enum is generated correctly in the data definition secion:

```ts
/** type of animal */
export enum PetKind {
CAT = "CAT",
DOG = "DOG",
}
```

but is *not* referenced correctly in the API client, it is referenced as *`pet_kind`* which gives runtime and type errors:

```ts
postPet: (
data: {
data: BaseNull & (BaseNullTypeMapping | BaseNullTypeMapping);
},
params: RequestParams = {},
) =>
this.request({
path: `/pet`,
method: "POST",
body: data,
type: ContentType.Json,
...params,
}),
};
}

```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。