Skip to content

Commit 817c881

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

5 files changed

Lines changed: 30 additions & 34 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 renamed to test-types/swagger-ui-vendor-extensions.tst.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { OpenAPIV2, OpenAPIV3 } from 'openapi-types'
2-
import { expectAssignable } from 'tsd'
1+
import { type OpenAPIV2, type OpenAPIV3 } from 'openapi-types'
2+
import { expect } from 'tstyche'
33

4-
expectAssignable<OpenAPIV3.Document>({
4+
expect({
55
openapi: '3.0.0',
66
info: {
77
version: '1.0.0',
8-
title: 'Test OpenApiv3 specification',
8+
title: 'Test OpenApiv3 specification'
99
},
1010
components: {
1111
securitySchemes: {
@@ -15,16 +15,16 @@ expectAssignable<OpenAPIV3.Document>({
1515
flows: {
1616
implicit: {
1717
authorizationUrl: 'http.../login/oauth/authorize',
18-
scopes: {},
19-
},
20-
},
21-
},
18+
scopes: {}
19+
}
20+
}
21+
}
2222
}
2323
},
2424
paths: {}
25-
})
25+
} as OpenAPIV3.Document).type.toBeAssignableTo<OpenAPIV3.Document>()
2626

27-
expectAssignable<OpenAPIV2.Document>({
27+
expect({
2828
swagger: '2.0.0',
2929
info: {
3030
title: 'Test OpenApiv2 specification',
@@ -37,34 +37,34 @@ expectAssignable<OpenAPIV2.Document>({
3737
authorizationUrl: 'https://example.com/oauth/authorize',
3838
tokenUrl: 'https://example.com/oauth/token',
3939
'x-tokenName': 'id_token',
40-
scopes: { }
40+
scopes: {}
4141
},
4242
OAuth2ApplicationFlow: {
4343
type: 'oauth2',
4444
flow: 'application',
4545
tokenUrl: 'https://example.com/oauth/token',
4646
'x-tokenName': 'id_token',
47-
scopes: { }
47+
scopes: {}
4848
},
4949
OAuth2ImplicitFlow: {
5050
type: 'oauth2',
5151
flow: 'implicit',
5252
authorizationUrl: 'https://example.com/oauth/authorize',
5353
'x-tokenName': 'id_token',
54-
scopes: { }
54+
scopes: {}
5555
},
5656
OAuth2PasswordFlow: {
5757
type: 'oauth2',
5858
flow: 'password',
5959
tokenUrl: 'https://example.com/oauth/token',
6060
'x-tokenName': 'id_token',
61-
scopes: { }
62-
},
61+
scopes: {}
62+
}
6363
},
6464
paths: {}
65-
})
65+
} as OpenAPIV2.Document).type.toBeAssignableTo<OpenAPIV2.Document>()
6666

67-
expectAssignable<OpenAPIV2.Document>({
67+
expect({
6868
swagger: '2.0.0',
6969
info: {
7070
title: 'Test OpenApiv2 specification',
@@ -74,8 +74,7 @@ expectAssignable<OpenAPIV2.Document>({
7474
'/users/{userId}': {
7575
get: {
7676
summary: 'Gets a user by ID.',
77-
responses: {
78-
},
77+
responses: {},
7978
parameters: [
8079
{
8180
in: 'path',
@@ -89,7 +88,8 @@ expectAssignable<OpenAPIV2.Document>({
8988
in: 'query',
9089
name: 'offset',
9190
type: 'integer',
92-
description: 'The number of items to skip before starting to collect the result set.',
91+
description:
92+
'The number of items to skip before starting to collect the result set.',
9393
'x-example': 1337
9494
},
9595
{
@@ -110,4 +110,4 @@ expectAssignable<OpenAPIV2.Document>({
110110
}
111111
}
112112
}
113-
})
113+
} as OpenAPIV2.Document).type.toBeAssignableTo<OpenAPIV2.Document>()
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)