acacode / acacode/swagger-typescript-api

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

Offen
#689 3 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
TypeScript
Sterne
4.1k
Forks
436
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.