acacode / acacode/swagger-typescript-api

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

Ouverte
#689 3 commentaires 1 réaction 0 personnes assignées Voir sur GitHub
Langage dominant
TypeScript
Étoiles
4.1k
Forks
436
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.