generated from stijnvanhulle/template
-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly construct LiteralTypes for properties that are "const" (#559)
* Added tests to check defintion of const properties * fixed typo * Added first draft of "const" assertion detection in TypeGenerator * Correctly define LiteralType for const properties --------- Co-authored-by: Hendrik Lücke-Tieke <[email protected]>
- Loading branch information
Showing
4 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
info: | ||
title: Swagger Petstore | ||
openapi: 3.1.0 | ||
components: | ||
schemas: | ||
Cat: | ||
title: Cat | ||
type: object | ||
properties: | ||
id: | ||
format: uuid | ||
title: Id | ||
type: string | ||
type: | ||
const: Cat | ||
title: Type | ||
meow: | ||
type: boolean | ||
title: Meowing prevalence | ||
required: | ||
- id | ||
- type | ||
Dog: | ||
title: Dog | ||
type: object | ||
properties: | ||
id: | ||
format: uuid | ||
title: Id | ||
type: string | ||
bark: | ||
type: number | ||
title: Barking frequency | ||
type: | ||
const: Dog | ||
title: Type | ||
required: | ||
- id | ||
- type | ||
Petstore: | ||
title: Petstore | ||
type: object | ||
description: A project is an analysis project. It has a name, an id, and has | ||
a dataset | ||
properties: | ||
id: | ||
title: Id | ||
type: integer | ||
pets: | ||
default: [] | ||
items: | ||
discriminator: | ||
mapping: | ||
Cat: "#/components/schemas/Cat" | ||
Dog: "#/components/schemas/Dog" | ||
propertyName: type | ||
oneOf: | ||
- "$ref": "#/components/schemas/Cat" | ||
- "$ref": "#/components/schemas/Dog" | ||
title: Pets | ||
type: array | ||
required: | ||
- id | ||
|
||
paths: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/swagger-ts/src/generators/__snapshots__/TypeGenerator.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`TypeGenerator with discriminators > Cat.type defined as const 1`] = ` | ||
"export type Cat = { | ||
id: string; | ||
type: \\"Cat\\"; | ||
meow?: boolean; | ||
}; | ||
" | ||
`; | ||
|
||
exports[`TypeGenerator with discriminators > Dog.type defined as const 1`] = ` | ||
"export type Dog = { | ||
id: string; | ||
bark?: number; | ||
type: \\"Dog\\"; | ||
}; | ||
" | ||
`; | ||
|
||
exports[`TypeGenerator with discriminators > PetStore defined as array with type union 1`] = ` | ||
"export type Petstore = { | ||
id: number; | ||
pets?: (Cat | Dog)[]; | ||
}; | ||
" | ||
`; |
bd3939b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
kubb – ./
kubb-kubb.vercel.app
kubb-git-main-kubb.vercel.app
kubb.dev
www.kubb.dev