acacode / acacode/swagger-typescript-api

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

Aberta
#689 3 comentários 1 reação 0 responsáveis Ver no GitHub
Linguagem predominante
TypeScript
Estrelas
4.1k
Forks
436
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

## 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;
```

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.