Skip to content

Commit 22e9ca7

Browse files
committed
chore: Updated dependencies and linted code.
1 parent dfe89f8 commit 22e9ca7

File tree

6 files changed

+22
-31
lines changed

6 files changed

+22
-31
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@
4545
"swagger-ui-dist": "^4.0.0-beta.4"
4646
},
4747
"devDependencies": {
48-
"@cowtech/eslint-config": "^7.14.5",
49-
"@cowtech/esm-package-utils": "^0.9.1",
48+
"@cowtech/eslint-config": "^8.0.1",
49+
"@cowtech/esm-package-utils": "^0.9.3",
5050
"@types/js-yaml": "^4.0.2",
51-
"@types/node": "^16.6.1",
51+
"@types/node": "^17.0.2",
5252
"@types/swagger-ui-dist": "^3.30.1",
5353
"@types/tap": "^15.0.5",
5454
"c8": "^7.8.0",

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ export const plugin = fastifyPlugin(
4747
})
4848

4949
// Utility to track all the RouteOptions we add
50-
instance.addHook('onRoute', (route: RouteOptions) => {
50+
instance.addHook('onRoute', route => {
5151
routes.push(route)
5252
})
5353

5454
// When the server starts, add all schemas and routes to the spec
55-
instance.addHook('onReady', (done: () => void) => {
55+
instance.addHook('onReady', done => {
5656
spec = buildSpec(instance, spec, instance.getSchemas() as { [key: string]: Schema }, routes)
5757
done()
5858
})

src/spec.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-floating-promises */
21
import { FastifyInstance, FastifySchema, RouteOptions } from 'fastify'
32

43
interface RouteConfig {
@@ -118,14 +117,14 @@ function cleanSpec(object: Schema): Schema {
118117

119118
// Check if there is a multiple type defined - Replace with anyOf since OpenAPI does not support type arrays
120119
if (Array.isArray(cleanedValue.type)) {
121-
cleanedValue.anyOf = cleanedValue.type.map((t: string) => ({ type: t }))
120+
cleanedValue.anyOf = cleanedValue.type.map(t => ({ type: t }))
122121
delete cleanedValue.type
123122
}
124123

125124
cleaned[key] = cleanedValue
126125
} else if (Array.isArray(value)) {
127126
// Recurse into array
128-
cleaned[key] = value.map((item: Schema) => (typeof item === 'object' ? cleanSpec(item) : item))
127+
cleaned[key] = value.map(item => (typeof item === 'object' ? cleanSpec(item) : item))
129128
} else {
130129
// Return other properties unchanged
131130
cleaned[key] = value
@@ -160,9 +159,7 @@ export function buildSpec(
160159
}
161160

162161
// Get the visible routes and sort them
163-
const apiRoutes = routes
164-
.filter((r: RouteOptions) => getRouteConfig(r).hide !== true)
165-
.sort((a: RouteOptions, b: RouteOptions) => a.url.localeCompare(b.url))
162+
const apiRoutes = routes.filter(r => getRouteConfig(r).hide !== true).sort((a, b) => a.url.localeCompare(b.url))
166163

167164
// For each route
168165
for (const route of apiRoutes) {
@@ -176,7 +173,7 @@ export function buildSpec(
176173

177174
// Sort available methods
178175
const methods = (Array.isArray(route.method) ? route.method : [route.method]).sort(
179-
(a: string, b: string) => methodsOrder.indexOf(a) - methodsOrder.indexOf(b)
176+
(a, b) => methodsOrder.indexOf(a) - methodsOrder.indexOf(b)
180177
)
181178

182179
// Get OpenAPI supported tags

src/ui.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function addUI(instance: FastifyInstance, prefix: string): void {
3333
// This hook is required because we have to serve the patched index file in order to point to the local documentation
3434
// eslint-disable-next-line no-useless-escape
3535
const indexUrl = new RegExp(`^(?:${prefix.replace(/\//g, '\\/')}\/(?:index\.html)?)$`)
36-
instance.addHook('preHandler', (request: FastifyRequest, reply: FastifyReply, done: () => void) => {
36+
instance.addHook('preHandler', (request, reply, done) => {
3737
if (request.raw.url!.match(indexUrl)) {
3838
reply.header('Content-Type', 'text/html; charset=UTF-8')
3939
reply.send(swaggerUIRootIndex)

test/spec.test.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
/* eslint-disable no-useless-escape */
21
/* eslint-disable @typescript-eslint/no-floating-promises */
32

43
import fastify, { FastifyReply, FastifyRequest } from 'fastify'
54
import t from 'tap'
65
import { plugin as fastifyOpenApiDocs } from '../src'
76

8-
type Test = typeof t
9-
107
const openapi = {
118
// All these fields are optional, but they should be provided to satisfy OpenAPI specification.
129
openapi: '3.0.3',
@@ -40,8 +37,8 @@ const openapi = {
4037
}
4138
}
4239

43-
t.test('Spec generation', (t: Test) => {
44-
t.test('should correctly generate a OpenAPI spec in JSON and YAML format', async (t: Test) => {
40+
t.test('Spec generation', t => {
41+
t.test('should correctly generate a OpenAPI spec in JSON and YAML format', async t => {
4542
const server = fastify()
4643

4744
server.register(fastifyOpenApiDocs, { openapi })
@@ -274,7 +271,7 @@ paths:
274271
})
275272
})
276273

277-
t.test('should accept routes with no OpenAPI annotations and hide routes', async (t: Test) => {
274+
t.test('should accept routes with no OpenAPI annotations and hide routes', async t => {
278275
const server = fastify()
279276

280277
server.register(fastifyOpenApiDocs, {
@@ -442,7 +439,7 @@ paths:
442439
})
443440
})
444441

445-
t.test('should accept routes with no schema', async (t: Test) => {
442+
t.test('should accept routes with no schema', async t => {
446443
const server = fastify()
447444

448445
server.register(fastifyOpenApiDocs, {})
@@ -479,7 +476,7 @@ paths:
479476
})
480477
})
481478

482-
t.test('should resolve $ref in params', async (t: Test) => {
479+
t.test('should resolve $ref in params', async t => {
483480
const server = fastify()
484481

485482
server.register(fastifyOpenApiDocs, {})
@@ -520,7 +517,7 @@ paths:
520517
})
521518
})
522519

523-
t.test('should recognized $raw and $empty', async (t: Test) => {
520+
t.test('should recognized $raw and $empty', async t => {
524521
const server = fastify()
525522

526523
server.register(fastifyOpenApiDocs, {})
@@ -569,7 +566,7 @@ paths:
569566
})
570567
})
571568

572-
t.test('should replace multiple types with anyOf', async (t: Test) => {
569+
t.test('should replace multiple types with anyOf', async t => {
573570
const server = fastify()
574571

575572
server.register(fastifyOpenApiDocs, {})

test/ui.test.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
/* eslint-disable no-useless-escape */
21
/* eslint-disable @typescript-eslint/no-floating-promises */
32

43
import fastify from 'fastify'
54
import t from 'tap'
65
import { plugin as fastifyOpenApiDocs } from '../src'
76

8-
type Test = typeof t
9-
10-
t.test('UI serving', (t: Test) => {
11-
t.test('should serve the UI by default', async (t: Test) => {
7+
t.test('UI serving', t => {
8+
t.test('should serve the UI by default', async t => {
129
const server = fastify()
1310

1411
server.register(fastifyOpenApiDocs, {})
@@ -24,7 +21,7 @@ t.test('UI serving', (t: Test) => {
2421
t.equal(defaultBody, indexBody)
2522
})
2623

27-
t.test('should not serve the UI if requested to', async (t: Test) => {
24+
t.test('should not serve the UI if requested to', async t => {
2825
const server = fastify()
2926

3027
server.register(fastifyOpenApiDocs, { skipUI: true })
@@ -41,7 +38,7 @@ t.test('UI serving', (t: Test) => {
4138
t.equal(indexBody, '{"message":"Route GET:/docs/index.html not found","error":"Not Found","statusCode":404}')
4239
})
4340

44-
t.test('should respect the right prefix', async (t: Test) => {
41+
t.test('should respect the right prefix', async t => {
4542
const server = fastify()
4643

4744
server.register(fastifyOpenApiDocs, { prefix: 'another' })
@@ -57,7 +54,7 @@ t.test('UI serving', (t: Test) => {
5754
t.equal(defaultBody, indexBody)
5855
})
5956

60-
t.test('should allow multiple instances', async (t: Test) => {
57+
t.test('should allow multiple instances', async t => {
6158
const server = fastify()
6259

6360
server.register(fastifyOpenApiDocs, { prefix: 'v1' })

0 commit comments

Comments
 (0)