acacode / acacode/swagger-typescript-api

`not: {}` generates `any` instead of `never`

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

Beschreibung

## Description

An empty JSON Schema accepts every possible value, so negating it with `not: {}` produces an impossible schema. The corresponding TypeScript type is `never`.

`swagger-typescript-api` currently generates `any` for this schema.

Version: 13.12.6.

## Example
```yaml
openapi: 3.0.3
info:
title: not schema reproduction
version: 1.0.0

paths: {}

components:
schemas:
Identifier:
oneOf:
- type: object
additionalProperties: false
required:
- internalId
properties:
internalId:
type: string
externalId:
not: {}

- type: object
additionalProperties: false
required:
- externalId
properties:
internalId:
not: {}
externalId:
type: string
```

### Actual Output

```ts
type Identifier =
| {
internalId: string
externalId?: any
}
| {
internalId?: any
externalId: string
}
```

### Expected Output

```ts
type Identifier =
| {
internalId: string
externalId?: never
}
| {
internalId?: never
externalId: string
}
```

### Source Problem

https://github.com/acacode/swagger-typescript-api/blob/v13.12.6/src/schema-parser/complex-schema-parsers/not.ts
The relevant parser currently returns `any` for every `not` schema:

```ts
export class NotSchemaParser extends MonoSchemaParser {
override parse() {
return this.config.Ts.Keyword.Any
}
}
```

#1798 addressed the generation crash for object-valued `not` schemas. The crash is fixed, but the generated type for `not: {}` remains `any`.

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.