From 3599578e59b0f33a75454cf3ef1ac0150082affb Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 8 Dec 2024 10:45:13 +0000 Subject: [PATCH] build(deps-dev): replace standard with neostandard --- README.md | 2 +- index.d.ts | 14 +- package.json | 12 +- test/types/http2-types.test.ts | 34 ++-- test/types/imports.test.ts | 26 +-- test/types/minimal-openapiV3-document.ts | 6 +- .../swagger-ui-vendor-extensions.test.ts | 76 ++++---- test/types/types.test.ts | 169 +++++++++--------- 8 files changed, 169 insertions(+), 170 deletions(-) diff --git a/README.md b/README.md index 2841f979..c60dd374 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![NPM version](https://img.shields.io/npm/v/@fastify/swagger.svg?style=flat)](https://www.npmjs.com/package/@fastify/swagger) [![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) -[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/) +[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard) 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. diff --git a/index.d.ts b/index.d.ts index b8cc66dd..a4cb69d1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,5 +1,5 @@ -import { FastifyPluginCallback, FastifySchema, RouteOptions, onRequestHookHandler, preHandlerHookHandler } from 'fastify'; -import { OpenAPI, OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'; +import { FastifyPluginCallback, FastifySchema, RouteOptions, onRequestHookHandler, preHandlerHookHandler } from 'fastify' +import { OpenAPI, OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types' /** * Swagger-UI Vendor Extensions @@ -75,12 +75,12 @@ type SwaggerTransform = ({ route: RouteOptions; } & SwaggerDocumentObject) => { schema: FastifySchema; url: string } -type SwaggerTransformObject = (documentObject: SwaggerDocumentObject) => Partial | Partial; +type SwaggerTransformObject = (documentObject: SwaggerDocumentObject) => Partial | Partial type FastifySwagger = FastifyPluginCallback declare namespace fastifySwagger { - export type SwaggerOptions = (FastifyStaticSwaggerOptions | FastifyDynamicSwaggerOptions); + export type SwaggerOptions = (FastifyStaticSwaggerOptions | FastifyDynamicSwaggerOptions) export interface FastifySwaggerOptions { mode?: 'static' | 'dynamic'; } @@ -127,7 +127,7 @@ declare namespace fastifySwagger { | number | boolean | JSONObject - | Array; + | Array export interface JSONObject { [key: string]: JSONValue; @@ -206,6 +206,6 @@ declare namespace fastifySwagger { export { fastifySwagger as default } } -declare function fastifySwagger(...params: Parameters): ReturnType +declare function fastifySwagger (...params: Parameters): ReturnType -export = fastifySwagger; +export = fastifySwagger diff --git a/package.json b/package.json index 31f6421b..466b5736 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "type": "commonjs", "types": "index.d.ts", "scripts": { - "lint": "standard", - "lint:fix": "standard --fix", + "lint": "eslint", + "lint:fix": "eslint --fix", "test": "npm run test:unit && npm run test:typescript", "test:typescript": "tsd", "test:unit": "tap", @@ -47,8 +47,8 @@ "fluent-json-schema": "^5.0.0", "joi": "^17.13.1", "joi-to-json": "^4.2.1", + "neostandard": "^0.11.9", "qs": "^6.12.1", - "standard": "^17.1.0", "tap": "18.7.2", "tsd": "^0.31.0" }, @@ -59,12 +59,6 @@ "rfdc": "^1.3.1", "yaml": "^2.4.2" }, - "standard": { - "ignore": [ - "static", - "tap-snapshots/*" - ] - }, "tsd": { "directory": "test/types" }, diff --git a/test/types/http2-types.test.ts b/test/types/http2-types.test.ts index c0da4a27..24ced61b 100644 --- a/test/types/http2-types.test.ts +++ b/test/types/http2-types.test.ts @@ -1,32 +1,34 @@ -import fastify from 'fastify'; -import fastifySwagger from '../..'; -import { minimalOpenApiV3Document } from './minimal-openapiV3-document'; +import fastify from 'fastify' +import fastifySwagger from '../..' +import { minimalOpenApiV3Document } from './minimal-openapiV3-document' const app = fastify({ http2: true -}); +}) -app.register(fastifySwagger); -app.register(fastifySwagger, {}); -app.register(fastifySwagger, { transform: ({schema, url}) => ({ - schema: schema, - url: url, -})}); +app.register(fastifySwagger) +app.register(fastifySwagger, {}) +app.register(fastifySwagger, { + transform: ({ schema, url }) => ({ + schema, + url, + }) +}) app.register(fastifySwagger, { mode: 'static', specification: { document: minimalOpenApiV3Document } -}); +}) app.put('/some-route/:id', { schema: { description: 'put me some data', tags: ['user', 'code'], summary: 'qwerty', - security: [{ apiKey: []}] + security: [{ apiKey: [] }] } -}, (req, reply) => {}); +}, (req, reply) => {}) app.get('/public/route', { schema: { @@ -34,7 +36,7 @@ app.get('/public/route', { summary: 'qwerty', security: [] } -}, (req, reply) => {}); +}, (req, reply) => {}) app .register(fastifySwagger, { @@ -66,5 +68,5 @@ app } }) .ready(err => { - app.swagger(); - }); + app.swagger() + }) diff --git a/test/types/imports.test.ts b/test/types/imports.test.ts index 38378951..11dd7774 100644 --- a/test/types/imports.test.ts +++ b/test/types/imports.test.ts @@ -1,22 +1,22 @@ -import fastify from "fastify"; +import fastify from 'fastify' -import swaggerDefault, { fastifySwagger, SwaggerOptions } from "../.."; -import * as fastifySwaggerStar from "../.."; -import { minimalOpenApiV3Document } from './minimal-openapiV3-document'; +import swaggerDefault, { fastifySwagger, SwaggerOptions } from '../..' +import * as fastifySwaggerStar from '../..' +import { minimalOpenApiV3Document } from './minimal-openapiV3-document' -const app = fastify(); +const app = fastify() const fastifySwaggerOptions: SwaggerOptions = { - mode: "static", + mode: 'static', specification: { document: minimalOpenApiV3Document, } -}; +} -app.register(swaggerDefault, fastifySwaggerOptions); -app.register(fastifySwagger, fastifySwaggerOptions); -app.register(fastifySwaggerStar.default, fastifySwaggerOptions); -app.register(fastifySwaggerStar.fastifySwagger, fastifySwaggerOptions); +app.register(swaggerDefault, fastifySwaggerOptions) +app.register(fastifySwagger, fastifySwaggerOptions) +app.register(fastifySwaggerStar.default, fastifySwaggerOptions) +app.register(fastifySwaggerStar.fastifySwagger, fastifySwaggerOptions) app.ready((err) => { - app.swagger(); -}); + app.swagger() +}) diff --git a/test/types/minimal-openapiV3-document.ts b/test/types/minimal-openapiV3-document.ts index dd94e296..ae517e7e 100644 --- a/test/types/minimal-openapiV3-document.ts +++ b/test/types/minimal-openapiV3-document.ts @@ -3,9 +3,9 @@ import { OpenAPIV3 } from 'openapi-types' export const minimalOpenApiV3Document: OpenAPIV3.Document = { openapi: '3.0.0', info: { - "version": "1.0.0", - "title": "Test OpenApiv3 specification", + version: '1.0.0', + title: 'Test OpenApiv3 specification', }, - "paths": { + paths: { } } diff --git a/test/types/swagger-ui-vendor-extensions.test.ts b/test/types/swagger-ui-vendor-extensions.test.ts index 5e92b2d2..e6615d0f 100644 --- a/test/types/swagger-ui-vendor-extensions.test.ts +++ b/test/types/swagger-ui-vendor-extensions.test.ts @@ -3,8 +3,8 @@ import { OpenAPIV2, OpenAPIV3 } from 'openapi-types' const xTokenNameOpenAPIv3: OpenAPIV3.Document = { openapi: '3.0.0', info: { - 'version': '1.0.0', - 'title': 'Test OpenApiv3 specification', + version: '1.0.0', + title: 'Test OpenApiv3 specification', }, components: { securitySchemes: { @@ -13,7 +13,7 @@ const xTokenNameOpenAPIv3: OpenAPIV3.Document = { 'x-tokenName': 'id_token', flows: { implicit: { - authorizationUrl: `http.../login/oauth/authorize`, + authorizationUrl: 'http.../login/oauth/authorize', scopes: {}, }, }, @@ -31,32 +31,32 @@ const xTokenNameOpenAPIv2: OpenAPIV2.Document = { }, securityDefinitions: { OAuth2AccessCodeFlow: { - type: "oauth2", - flow: "accessCode", - authorizationUrl: "https://example.com/oauth/authorize", - tokenUrl: "https://example.com/oauth/token", - "x-tokenName": 'id_token', + type: 'oauth2', + flow: 'accessCode', + authorizationUrl: 'https://example.com/oauth/authorize', + tokenUrl: 'https://example.com/oauth/token', + 'x-tokenName': 'id_token', scopes: { } }, OAuth2ApplicationFlow: { - type: "oauth2", - flow: "application", - tokenUrl: "https://example.com/oauth/token", - "x-tokenName": 'id_token', + type: 'oauth2', + flow: 'application', + tokenUrl: 'https://example.com/oauth/token', + 'x-tokenName': 'id_token', scopes: { } }, OAuth2ImplicitFlow: { - type: "oauth2", - flow: "implicit", - authorizationUrl: "https://example.com/oauth/authorize", - "x-tokenName": 'id_token', + type: 'oauth2', + flow: 'implicit', + authorizationUrl: 'https://example.com/oauth/authorize', + 'x-tokenName': 'id_token', scopes: { } }, OAuth2PasswordFlow: { - type: "oauth2", - flow: "password", - tokenUrl: "https://example.com/oauth/token", - "x-tokenName": 'id_token', + type: 'oauth2', + flow: 'password', + tokenUrl: 'https://example.com/oauth/token', + 'x-tokenName': 'id_token', scopes: { } }, }, @@ -70,38 +70,38 @@ const xExampleOpenAPIv2: OpenAPIV2.Document = { version: '2.0.0' }, paths: { - "/users/{userId}": { - 'get': { - summary: "Gets a user by ID.", + '/users/{userId}': { + get: { + summary: 'Gets a user by ID.', responses: { }, parameters: [ { - in: "path", - name: "userId", - type: "integer", + in: 'path', + name: 'userId', + type: 'integer', required: true, - description: "Numeric ID of the user to get.", + description: 'Numeric ID of the user to get.', 'x-example': 'BADC0FFEE' }, { - in: "query", - name: "offset", - type: "integer", - description: "The number of items to skip before starting to collect the result set.", + in: 'query', + name: 'offset', + type: 'integer', + description: 'The number of items to skip before starting to collect the result set.', 'x-example': 1337 }, { - in: "header", - name: "X-Request-ID", - type: "string", + in: 'header', + name: 'X-Request-ID', + type: 'string', required: true, 'x-example': 'wget' }, { - in: "formData", - name: "name", - type: "string", + in: 'formData', + name: 'name', + type: 'string', description: "A person's name.", 'x-example': 'John Doe' } @@ -109,4 +109,4 @@ const xExampleOpenAPIv2: OpenAPIV2.Document = { } } } -} \ No newline at end of file +} diff --git a/test/types/types.test.ts b/test/types/types.test.ts index 85393bf4..7b4f7e5e 100644 --- a/test/types/types.test.ts +++ b/test/types/types.test.ts @@ -1,16 +1,16 @@ -import fastify, { FastifySchema, RouteOptions } from 'fastify'; +import fastify, { FastifySchema, RouteOptions } from 'fastify' import fastifySwagger, { formatParamUrl, SwaggerOptions, FastifySwaggerInitOAuthOptions, FastifySwaggerUiConfigOptions, FastifySwaggerUiHooksOptions, -} from "../.." -import { minimalOpenApiV3Document } from './minimal-openapiV3-document'; -import { expectType } from "tsd"; -import { OpenAPI, OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from "openapi-types"; +} from '../..' +import { minimalOpenApiV3Document } from './minimal-openapiV3-document' +import { expectType } from 'tsd' +import { OpenAPI, OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types' -const app = fastify(); +const app = fastify() const uiConfig: FastifySwaggerUiConfigOptions = { deepLinking: true, defaultModelsExpandDepth: -1, @@ -19,27 +19,29 @@ const uiConfig: FastifySwaggerUiConfigOptions = { layout: 'BaseLayout', supportedSubmitMethods: ['get'], persistAuthorization: false, -}; +} const initOAuth: FastifySwaggerInitOAuthOptions = { scopes: ['openid', 'profile', 'email', 'offline_access'], -}; +} const uiHooks: FastifySwaggerUiHooksOptions = { - onRequest: (request, reply, done) => {done()}, - preHandler: (request, reply, done) => {done()}, + onRequest: (request, reply, done) => { done() }, + preHandler: (request, reply, done) => { done() }, } -app.register(fastifySwagger); -app.register(fastifySwagger, {}); -app.register(fastifySwagger, { transform: ({schema, url}) => ({ - schema: schema, - url: url, -})}); +app.register(fastifySwagger) +app.register(fastifySwagger, {}) +app.register(fastifySwagger, { + transform: ({ schema, url }) => ({ + schema, + url, + }) +}) app.register(fastifySwagger, { mode: 'static', specification: { document: minimalOpenApiV3Document } -}); +}) const fastifySwaggerOptions: SwaggerOptions = { mode: 'static', @@ -47,7 +49,7 @@ const fastifySwaggerOptions: SwaggerOptions = { document: minimalOpenApiV3Document } } -app.register(fastifySwagger, fastifySwaggerOptions); +app.register(fastifySwagger, fastifySwaggerOptions) const fastifyDynamicSwaggerOptions: SwaggerOptions = { mode: 'dynamic', @@ -58,29 +60,29 @@ const fastifyDynamicSwaggerOptions: SwaggerOptions = { buildLocalReference: (json, baseUri, fragment, i) => `${fragment}-${i}` } } -app.register(fastifySwagger, fastifyDynamicSwaggerOptions); +app.register(fastifySwagger, fastifyDynamicSwaggerOptions) app.get('/deprecated', { schema: { deprecated: true, hide: true } -}, (req, reply) => {}); +}, (req, reply) => {}) app.put('/some-route/:id', { - schema: { - description: 'put me some data', - tags: ['user', 'code'], - summary: 'qwerty', - consumes: ['application/json', 'multipart/form-data'], - security: [{ apiKey: []}], - operationId: 'opeId', - externalDocs: { - url: 'https://swagger.io', - description: 'Find more info here' - }, - } - }, (req, reply) => {}); + schema: { + description: 'put me some data', + tags: ['user', 'code'], + summary: 'qwerty', + consumes: ['application/json', 'multipart/form-data'], + security: [{ apiKey: [] }], + operationId: 'opeId', + externalDocs: { + url: 'https://swagger.io', + description: 'Find more info here' + }, + } +}, (req, reply) => {}) app.put('/image.png', { schema: { @@ -95,35 +97,36 @@ app.put('/image.png', { } } } -}, async (req, reply) => { reply +}, async (req, reply) => { + reply .type('image/png') - .send(Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAAgSURBVBhXY/iPCkB8BgYkEiSIBICiCCEoB0SBwf///wGHRzXLSklJLQAAAABJRU5ErkJggg==', 'base64')); -}); + .send(Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAAgSURBVBhXY/iPCkB8BgYkEiSIBICiCCEoB0SBwf///wGHRzXLSklJLQAAAABJRU5ErkJggg==', 'base64')) +}) app.get('/public/route', { - schema: { - description: 'returns 200 OK', - summary: 'qwerty', - security: [], - response: { 200: {} } - }, - links: { - 200: {'some-route': { operationId: 'opeId'}} - } - }, (req, reply) => {}); + schema: { + description: 'returns 200 OK', + summary: 'qwerty', + security: [], + response: { 200: {} } + }, + links: { + 200: { 'some-route': { operationId: 'opeId' } } + } +}, (req, reply) => {}) app.get('/public/readonly-schema-route', { - schema: { - description: 'returns 200 OK', - tags: ['foo'], - summary: 'qwerty', - security: [], - response: { 200: {} } - }, - links: { - 200: {'some-route': { operationId: 'opeId'}} - } - } as const, (req, reply) => {}); + schema: { + description: 'returns 200 OK', + tags: ['foo'], + summary: 'qwerty', + security: [], + response: { 200: {} } + }, + links: { + 200: { 'some-route': { operationId: 'opeId' } } + } +} as const, (req, reply) => {}) app .register(fastifySwagger, { @@ -155,46 +158,46 @@ app } }) .ready(err => { - app.swagger(); - }); + app.swagger() + }) app .register(fastifySwagger, { openapi: { info: { - title: "Test openapi", - description: "testing the fastify swagger api", - version: "0.1.0", + title: 'Test openapi', + description: 'testing the fastify swagger api', + version: '0.1.0', }, - servers: [{ url: "http://localhost" }], + servers: [{ url: 'http://localhost' }], externalDocs: { - url: "https://swagger.io", - description: "Find more info here", + url: 'https://swagger.io', + description: 'Find more info here', }, components: { schemas: {}, securitySchemes: { apiKey: { - type: "apiKey", - name: "apiKey", - in: "header", + type: 'apiKey', + name: 'apiKey', + in: 'header', }, }, }, } }) .ready((err) => { - app.swagger(); - }); + app.swagger() + }) app.register(fastifySwagger, { openapi: { components: { schemas: { Model: { - type: "object", + type: 'object', properties: { - name: { type: "null" }, + name: { type: 'null' }, }, required: ['name'] } @@ -203,17 +206,17 @@ app.register(fastifySwagger, { }, }) .ready((err) => { - app.swagger(); + app.swagger() }) app.register(fastifySwagger, { }) .ready((err) => { - app.swagger(); + app.swagger() }) app.get( - "/endpoint-transform-function", + '/endpoint-transform-function', { config: { swaggerTransform: ({ @@ -222,26 +225,26 @@ app.get( route, ...documentObject }) => { - schema satisfies FastifySchema; - url satisfies string; - route satisfies RouteOptions; - documentObject satisfies { swaggerObject: Partial } | { openapiObject: Partial }; - return { schema, url }; + schema satisfies FastifySchema + url satisfies string + route satisfies RouteOptions + documentObject satisfies { swaggerObject: Partial } | { openapiObject: Partial } + return { schema, url } }, }, }, () => {} -); +) app.get( - "/endpoint-transform-false", + '/endpoint-transform-false', { config: { swaggerTransform: false, }, }, () => {} -); +) expectType(app.swagger()) expectType(app.swagger({ yaml: false }))