acacode / acacode/swagger-typescript-api

`XxMapping` for `discriminator` doesn’t account for `generateUnionEnums`

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

説明

## Issue

When setting `generateUnionEnums` to true, the mapping `Key` generics should be set explicitly as strings rather than using the enum mapping.

Found on version `13.0.3`

### Setup

That is, in the following situation:

```yaml
BranchName:
type: string
enum:
- one
- two

Root:
type: object
discriminator:
propertyName: branch
mapping:
one: '#/components/schemas/BranchA'
two: '#/components/schemas/BranchB'
properties:
branch:
$ref: '#/components/schemas/BranchName'
```

### Expected output

```ts
export type BranchName = 'one' | 'two';
export type Root = BaseRoot &
(
| BaseRootBranchMapping<'one', BranchA>
| BaseRootBranchMapping<'two', BranchB>
);
```

### Current output

```ts
export type BranchName = 'one' | 'two';
export type Root = BaseRoot &
(
| BaseRootBranchMapping
| BaseRootBranchMapping
);
```

Minimal full yaml to reproduce

```yaml
openapi: 3.0.0
info:
title: Broken branches
version: 0.0.0

paths: {}

components:
schemas:
BranchName:
type: string
enum:
- one
- two

Root:
type: object
discriminator:
propertyName: branch
mapping:
one: '#/components/schemas/BranchA'
two: '#/components/schemas/BranchB'
properties:
branch:
$ref: '#/components/schemas/BranchName'

BranchA:
type: object

BranchB:
type: object
```

Expected output:

```ts
export type BranchName = 'one' | 'two';

export type Root = BaseRoot & (BaseRootBranchMapping<'one', BranchA> | BaseRootBranchMapping<'two', BranchB>);

export type BranchA = object;

export type BranchB = object;

interface BaseRoot {
branch?: BranchName;
}

type BaseRootBranchMapping = {
branch: Key;
} & Type;
```

Current output:

```ts
export type BranchName = 'one' | 'two';

export type Root = BaseRoot &
(BaseRootBranchMapping | BaseRootBranchMapping);

export type BranchA = object;

export type BranchB = object;

interface BaseRoot {
branch?: BranchName;
}

type BaseRootBranchMapping = {
branch: Key;
} & Type;
```

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

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

評価

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

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

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