Skip to content

Commit 0d71ee0

Browse files
committed
refactor(types): migrate from tsd to tstyche
1 parent bb477e2 commit 0d71ee0

6 files changed

Lines changed: 125 additions & 126 deletions

File tree

package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"lint": "eslint",
1010
"lint:fix": "eslint --fix",
1111
"test": "npm run test:unit && npm run test:typescript",
12-
"test:typescript": "tsd",
12+
"test:typescript": "tstyche",
1313
"test:unit": "c8 --100 node --test"
1414
},
1515
"repository": {
@@ -71,7 +71,7 @@
7171
"joi-to-json": "^5.0.0",
7272
"neostandard": "^0.13.0",
7373
"qs": "^6.12.1",
74-
"tsd": "^0.33.0"
74+
"tstyche": "^7.0.0"
7575
},
7676
"dependencies": {
7777
"fastify-plugin": "^5.0.0",
@@ -80,10 +80,7 @@
8080
"rfdc": "^1.3.1",
8181
"yaml": "^2.4.2"
8282
},
83-
"tsd": {
84-
"directory": "test-types"
85-
},
8683
"publishConfig": {
8784
"access": "public"
8885
}
89-
}
86+
}

test-types/swagger-ui-vendor-extensions.test-d.ts

Lines changed: 0 additions & 113 deletions
This file was deleted.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import { type OpenAPIV2, type OpenAPIV3 } from 'openapi-types'
2+
import { expect } from 'tstyche'
3+
import '..'
4+
5+
expect<OpenAPIV3.Document>()
6+
.type.toBeAssignableFrom({
7+
openapi: '3.0.0',
8+
info: {
9+
version: '1.0.0',
10+
title: 'Test OpenApiv3 specification'
11+
},
12+
components: {
13+
securitySchemes: {
14+
myAuth: {
15+
type: 'oauth2' as const,
16+
'x-tokenName': 'id_token',
17+
flows: {
18+
implicit: {
19+
authorizationUrl: 'http.../login/oauth/authorize',
20+
scopes: {}
21+
}
22+
}
23+
}
24+
}
25+
},
26+
paths: {}
27+
})
28+
29+
expect<OpenAPIV2.Document>().type.toBeAssignableFrom({
30+
swagger: '2.0.0',
31+
info: {
32+
title: 'Test OpenApiv2 specification',
33+
version: '2.0.0'
34+
},
35+
securityDefinitions: {
36+
OAuth2AccessCodeFlow: {
37+
type: 'oauth2' as const,
38+
flow: 'accessCode' as const,
39+
authorizationUrl: 'https://example.com/oauth/authorize',
40+
tokenUrl: 'https://example.com/oauth/token',
41+
'x-tokenName': 'id_token',
42+
scopes: {}
43+
},
44+
OAuth2ApplicationFlow: {
45+
type: 'oauth2' as const,
46+
flow: 'application' as const,
47+
tokenUrl: 'https://example.com/oauth/token',
48+
'x-tokenName': 'id_token',
49+
scopes: {}
50+
},
51+
OAuth2ImplicitFlow: {
52+
type: 'oauth2' as const,
53+
flow: 'implicit' as const,
54+
authorizationUrl: 'https://example.com/oauth/authorize',
55+
'x-tokenName': 'id_token',
56+
scopes: {}
57+
},
58+
OAuth2PasswordFlow: {
59+
type: 'oauth2' as const,
60+
flow: 'password' as const,
61+
tokenUrl: 'https://example.com/oauth/token',
62+
'x-tokenName': 'id_token',
63+
scopes: {}
64+
}
65+
},
66+
paths: {}
67+
})
68+
69+
expect<OpenAPIV2.Document>()
70+
.type.toBeAssignableFrom({
71+
swagger: '2.0.0',
72+
info: {
73+
title: 'Test OpenApiv2 specification',
74+
version: '2.0.0'
75+
},
76+
paths: {
77+
'/users/{userId}': {
78+
get: {
79+
summary: 'Gets a user by ID.',
80+
responses: {},
81+
parameters: [
82+
{
83+
in: 'path',
84+
name: 'userId',
85+
type: 'integer',
86+
required: true,
87+
description: 'Numeric ID of the user to get.',
88+
'x-example': 'BADC0FFEE'
89+
},
90+
{
91+
in: 'query',
92+
name: 'offset',
93+
type: 'integer',
94+
description:
95+
'The number of items to skip before starting to collect the result set.',
96+
'x-example': 1337
97+
},
98+
{
99+
in: 'header',
100+
name: 'X-Request-ID',
101+
type: 'string',
102+
required: true,
103+
'x-example': 'wget'
104+
},
105+
{
106+
in: 'formData',
107+
name: 'name',
108+
type: 'string',
109+
description: "A person's name.",
110+
'x-example': 'John Doe'
111+
}
112+
]
113+
}
114+
}
115+
}
116+
})
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import fastifySwagger, {
44
SwaggerOptions,
55
} from '..'
66
import { minimalOpenApiV3Document } from './minimal-openapiV3-document'
7-
import { expectType } from 'tsd'
8-
7+
import { expect } from 'tstyche'
98
import {
109
OpenAPI,
1110
OpenAPIV2,
@@ -236,12 +235,12 @@ app.get(
236235
() => {}
237236
)
238237

239-
expectType<OpenAPI.Document>(app.swagger())
240-
expectType<OpenAPI.Document>(app.swagger({ yaml: false }))
241-
expectType<string>(app.swagger({ yaml: true }))
242-
expectType<OpenAPI.Document | string>(app.swagger({ yaml: Boolean(process.env.YAML) }))
238+
expect(app.swagger()).type.toBe<OpenAPI.Document>()
239+
expect(app.swagger({ yaml: false })).type.toBe<OpenAPI.Document>()
240+
expect(app.swagger({ yaml: true })).type.toBe<string>()
241+
expect(app.swagger({ yaml: Boolean(process.env.YAML) })).type.toBe<OpenAPI.Document | string>()
243242

244-
expectType<(arg: string)=>string>(formatParamUrl)
243+
expect(formatParamUrl).type.toBe<(arg: string) => string>()
245244

246245
app.register(fastifySwagger, {
247246
decorator: 'swagger'

0 commit comments

Comments
 (0)