Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit a52eb57

Browse files
tmcwhanspagel
andauthored
fix(openapi-parser): add TypeScript discriminator strings (#159)
* fix: Add discriminator strings to OpenAPI.Document types * docs(changeset): Add literal versions to OpenAPI.Document types * chore: update comments, fix whitespace * chore: update changeset --------- Co-authored-by: Hans Pagel <[email protected]>
1 parent b8ac5c2 commit a52eb57

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

.changeset/beige-spiders-grin.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@scalar/openapi-parser': patch
3+
---
4+
5+
feat: add literal versions to OpenAPI.Document types

packages/openapi-parser/src/types/openapi-types.ts

+21-10
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,8 @@ export namespace OpenAPI {
1818
// any other attribute
1919
[key: string]: any
2020
} = {},
21-
> = (
22-
| OpenAPIV2.Document<T>
23-
| OpenAPIV3.Document<T>
24-
| OpenAPIV3_1.Document<T>
25-
) & {
26-
// any other attribute
27-
[key: string]: any
28-
}
21+
> = OpenAPIV2.Document<T> | OpenAPIV3.Document<T> | OpenAPIV3_1.Document<T>
22+
2923
export type Operation<T extends {} = {}> =
3024
| OpenAPIV2.OperationObject<T>
3125
| OpenAPIV3.OperationObject<T>
@@ -62,6 +56,11 @@ export namespace OpenAPIV3_1 {
6256
export type Document<T extends {} = {}> = Modify<
6357
Omit<OpenAPIV3.Document<T>, 'paths' | 'components'>,
6458
{
59+
/**
60+
* Version of the OpenAPI specification
61+
* @see https://github.com/OAI/OpenAPI-Specification/tree/main/versions
62+
*/
63+
openapi: '3.1.0'
6564
info?: InfoObject
6665
jsonSchemaDialect?: string
6766
servers?: ServerObject[]
@@ -284,7 +283,12 @@ export namespace OpenAPIV3_1 {
284283

285284
export namespace OpenAPIV3 {
286285
export interface Document<T extends {} = {}> {
287-
openapi?: string
286+
[propName: string]: any
287+
/**
288+
* Version of the OpenAPI specification
289+
* @see https://github.com/OAI/OpenAPI-Specification/tree/main/versions
290+
*/
291+
openapi?: '3.0.0' | '3.0.1' | '3.0.2' | '3.0.2'
288292
info?: InfoObject
289293
servers?: ServerObject[]
290294
paths?: PathsObject<T>
@@ -606,6 +610,9 @@ export namespace OpenAPIV3 {
606610

607611
export namespace OpenAPIV2 {
608612
export interface Document<T extends {} = {}> {
613+
[propName: string]: any
614+
/** To make it easier to use openapi as a type guard */
615+
openapi: undefined
609616
basePath?: string
610617
consumes?: MimeTypes
611618
definitions?: DefinitionsObject
@@ -619,7 +626,11 @@ export namespace OpenAPIV2 {
619626
schemes?: string[]
620627
security?: SecurityRequirementObject[]
621628
securityDefinitions?: SecurityDefinitionsObject
622-
swagger?: string
629+
/**
630+
* Version of the OpenAPI specification
631+
* @see https://github.com/OAI/OpenAPI-Specification/tree/main/versions
632+
*/
633+
swagger?: '2.0'
623634
tags?: TagObject[]
624635
}
625636

0 commit comments

Comments
 (0)