Skip to content

Commit 23ee1e2

Browse files
FdawgsUzlopak
andauthored
build(deps-dev): replace standard with neostandard (#842)
* build(deps-dev): replace standard with neostandard * chore: add eslint.config.js * fix linting issue --------- Co-authored-by: Aras Abbasi <aras.abbasi@googlemail.com>
1 parent b663cb3 commit 23ee1e2

9 files changed

+206
-239
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![NPM version](https://img.shields.io/npm/v/@fastify/swagger.svg?style=flat)](https://www.npmjs.com/package/@fastify/swagger)
44
[![CI](https://github.com/fastify/fastify-swagger/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fastify-swagger/actions/workflows/ci.yml)
5-
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
5+
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)
66

77
A Fastify plugin for serving [Swagger (OpenAPI v2)](https://swagger.io/specification/v2/) or [OpenAPI v3](https://swagger.io/specification) schemas, which are automatically generated from your route schemas, or from an existing Swagger/OpenAPI schema.
88

eslint.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict'
2+
3+
module.exports = require('neostandard')({
4+
ignores: [
5+
...require('neostandard').resolveIgnoresFromGitignore(),
6+
'static',
7+
'tap-snapshots/*'
8+
],
9+
ts: true
10+
})

index.d.ts

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
import { FastifyPluginCallback, FastifySchema, RouteOptions, onRequestHookHandler, preHandlerHookHandler } from 'fastify';
2-
import { OpenAPI, OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
1+
import { FastifyPluginCallback, FastifySchema, RouteOptions } from 'fastify'
2+
import {
3+
OpenAPI,
4+
OpenAPIV2,
5+
OpenAPIV3,
6+
// eslint-disable-next-line camelcase
7+
OpenAPIV3_1
8+
} from 'openapi-types'
39

410
/**
511
* Swagger-UI Vendor Extensions
@@ -61,6 +67,7 @@ declare module 'fastify' {
6167
type SwaggerDocumentObject = {
6268
swaggerObject: Partial<OpenAPIV2.Document>;
6369
} | {
70+
// eslint-disable-next-line camelcase
6471
openapiObject: Partial<OpenAPIV3.Document | OpenAPIV3_1.Document>;
6572
}
6673

@@ -75,59 +82,24 @@ type SwaggerTransform = <S extends FastifySchema = FastifySchema>({
7582
route: RouteOptions;
7683
} & SwaggerDocumentObject) => { schema: FastifySchema; url: string }
7784

78-
type SwaggerTransformObject = (documentObject: SwaggerDocumentObject) => Partial<OpenAPIV2.Document> | Partial<OpenAPIV3.Document | OpenAPIV3_1.Document>;
85+
// eslint-disable-next-line camelcase
86+
type SwaggerTransformObject = (documentObject: SwaggerDocumentObject) => Partial<OpenAPIV2.Document> | Partial<OpenAPIV3.Document | OpenAPIV3_1.Document>
7987

8088
type FastifySwagger = FastifyPluginCallback<fastifySwagger.SwaggerOptions>
8189

8290
declare namespace fastifySwagger {
83-
export type SwaggerOptions = (FastifyStaticSwaggerOptions | FastifyDynamicSwaggerOptions);
91+
export type SwaggerOptions = (FastifyStaticSwaggerOptions | FastifyDynamicSwaggerOptions)
8492
export interface FastifySwaggerOptions {
8593
mode?: 'static' | 'dynamic';
8694
}
8795

88-
export type FastifySwaggerUiConfigOptions = Partial<{
89-
deepLinking: boolean
90-
displayOperationId: boolean
91-
defaultModelsExpandDepth: number
92-
defaultModelExpandDepth: number
93-
defaultModelRendering: string
94-
displayRequestDuration: boolean
95-
docExpansion: string
96-
filter: boolean | string
97-
layout: string
98-
maxDisplayedTags: number
99-
showExtensions: boolean
100-
showCommonExtensions: boolean
101-
useUnsafeMarkdown: boolean
102-
syntaxHighlight: {
103-
activate?: boolean
104-
theme?: string
105-
} | false
106-
tryItOutEnabled: boolean
107-
validatorUrl: string | null
108-
supportedSubmitMethods: Array<'get' | 'post' | 'put' | 'delete' | 'patch' | 'options'>
109-
persistAuthorization: boolean
110-
}>
111-
112-
export type FastifySwaggerInitOAuthOptions = Partial<{
113-
clientId: string,
114-
clientSecret: string,
115-
realm: string,
116-
appName: string,
117-
scopeSeparator: string,
118-
scopes: string | string[],
119-
additionalQueryStringParams: { [key: string]: any },
120-
useBasicAuthenticationWithAccessCodeGrant: boolean,
121-
usePkceWithAuthorizationCodeGrant: boolean
122-
}>
123-
12496
type JSONValue =
12597
| string
12698
| null
12799
| number
128100
| boolean
129101
| JSONObject
130-
| Array<JSONValue>;
102+
| Array<JSONValue>
131103

132104
export interface JSONObject {
133105
[key: string]: JSONValue;
@@ -136,6 +108,7 @@ declare namespace fastifySwagger {
136108
export interface FastifyDynamicSwaggerOptions extends FastifySwaggerOptions {
137109
mode?: 'dynamic';
138110
swagger?: Partial<OpenAPIV2.Document>;
111+
// eslint-disable-next-line camelcase
139112
openapi?: Partial<OpenAPIV3.Document | OpenAPIV3_1.Document>
140113
hiddenTag?: string;
141114
hideUntagged?: boolean;
@@ -195,17 +168,12 @@ declare namespace fastifySwagger {
195168
specification: StaticPathSpec | StaticDocumentSpec;
196169
}
197170

198-
export type FastifySwaggerUiHooksOptions = Partial<{
199-
onRequest?: onRequestHookHandler,
200-
preHandler?: preHandlerHookHandler,
201-
}>
202-
203171
export function formatParamUrl (paramUrl: string): string
204172

205173
export const fastifySwagger: FastifySwagger
206174
export { fastifySwagger as default }
207175
}
208176

209-
declare function fastifySwagger(...params: Parameters<FastifySwagger>): ReturnType<FastifySwagger>
177+
declare function fastifySwagger (...params: Parameters<FastifySwagger>): ReturnType<FastifySwagger>
210178

211-
export = fastifySwagger;
179+
export = fastifySwagger

package.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"type": "commonjs",
77
"types": "index.d.ts",
88
"scripts": {
9-
"lint": "standard",
10-
"lint:fix": "standard --fix",
9+
"lint": "eslint",
10+
"lint:fix": "eslint --fix",
1111
"test": "npm run test:unit && npm run test:typescript",
1212
"test:typescript": "tsd",
1313
"test:unit": "tap",
@@ -47,8 +47,8 @@
4747
"fluent-json-schema": "^5.0.0",
4848
"joi": "^17.13.1",
4949
"joi-to-json": "^4.2.1",
50+
"neostandard": "^0.11.9",
5051
"qs": "^6.12.1",
51-
"standard": "^17.1.0",
5252
"tap": "18.7.2",
5353
"tsd": "^0.31.0"
5454
},
@@ -59,12 +59,6 @@
5959
"rfdc": "^1.3.1",
6060
"yaml": "^2.4.2"
6161
},
62-
"standard": {
63-
"ignore": [
64-
"static",
65-
"tap-snapshots/*"
66-
]
67-
},
6862
"tsd": {
6963
"directory": "test/types"
7064
},

test/types/http2-types.test.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
1-
import fastify from 'fastify';
2-
import fastifySwagger from '../..';
3-
import { minimalOpenApiV3Document } from './minimal-openapiV3-document';
1+
import fastify from 'fastify'
2+
import fastifySwagger from '../..'
3+
import { minimalOpenApiV3Document } from './minimal-openapiV3-document'
44

55
const app = fastify({
66
http2: true
7-
});
7+
})
88

9-
app.register(fastifySwagger);
10-
app.register(fastifySwagger, {});
11-
app.register(fastifySwagger, { transform: ({schema, url}) => ({
12-
schema: schema,
13-
url: url,
14-
})});
9+
app.register(fastifySwagger)
10+
app.register(fastifySwagger, {})
11+
app.register(fastifySwagger, {
12+
transform: ({ schema, url }) => ({
13+
schema,
14+
url,
15+
})
16+
})
1517
app.register(fastifySwagger, {
1618
mode: 'static',
1719
specification: {
1820
document: minimalOpenApiV3Document
1921
}
20-
});
22+
})
2123

2224
app.put('/some-route/:id', {
2325
schema: {
2426
description: 'put me some data',
2527
tags: ['user', 'code'],
2628
summary: 'qwerty',
27-
security: [{ apiKey: []}]
29+
security: [{ apiKey: [] }]
2830
}
29-
}, (req, reply) => {});
31+
}, (req, reply) => {})
3032

3133
app.get('/public/route', {
3234
schema: {
3335
description: 'returns 200 OK',
3436
summary: 'qwerty',
3537
security: []
3638
}
37-
}, (req, reply) => {});
39+
}, (req, reply) => {})
3840

3941
app
4042
.register(fastifySwagger, {
@@ -65,6 +67,6 @@ app
6567
}
6668
}
6769
})
68-
.ready(err => {
69-
app.swagger();
70-
});
70+
.ready(() => {
71+
app.swagger()
72+
})

test/types/imports.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import fastify from "fastify";
1+
import fastify from 'fastify'
22

3-
import swaggerDefault, { fastifySwagger, SwaggerOptions } from "../..";
4-
import * as fastifySwaggerStar from "../..";
5-
import { minimalOpenApiV3Document } from './minimal-openapiV3-document';
3+
import swaggerDefault, { fastifySwagger, SwaggerOptions } from '../..'
4+
import * as fastifySwaggerStar from '../..'
5+
import { minimalOpenApiV3Document } from './minimal-openapiV3-document'
66

7-
const app = fastify();
7+
const app = fastify()
88
const fastifySwaggerOptions: SwaggerOptions = {
9-
mode: "static",
9+
mode: 'static',
1010
specification: {
1111
document: minimalOpenApiV3Document,
1212
}
13-
};
13+
}
1414

15-
app.register(swaggerDefault, fastifySwaggerOptions);
16-
app.register(fastifySwagger, fastifySwaggerOptions);
17-
app.register(fastifySwaggerStar.default, fastifySwaggerOptions);
18-
app.register(fastifySwaggerStar.fastifySwagger, fastifySwaggerOptions);
15+
app.register(swaggerDefault, fastifySwaggerOptions)
16+
app.register(fastifySwagger, fastifySwaggerOptions)
17+
app.register(fastifySwaggerStar.default, fastifySwaggerOptions)
18+
app.register(fastifySwaggerStar.fastifySwagger, fastifySwaggerOptions)
1919

20-
app.ready((err) => {
21-
app.swagger();
22-
});
20+
app.ready(() => {
21+
app.swagger()
22+
})

test/types/minimal-openapiV3-document.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { OpenAPIV3 } from 'openapi-types'
33
export const minimalOpenApiV3Document: OpenAPIV3.Document = {
44
openapi: '3.0.0',
55
info: {
6-
"version": "1.0.0",
7-
"title": "Test OpenApiv3 specification",
6+
version: '1.0.0',
7+
title: 'Test OpenApiv3 specification',
88
},
9-
"paths": {
9+
paths: {
1010
}
1111
}

0 commit comments

Comments
 (0)