Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps-dev): replace standard with neostandard #842

Merged
merged 3 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
10 changes: 10 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict'

module.exports = require('neostandard')({
ignores: [
...require('neostandard').resolveIgnoresFromGitignore(),
'static',
'tap-snapshots/*'
],
ts: true
})
64 changes: 16 additions & 48 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { FastifyPluginCallback, FastifySchema, RouteOptions, onRequestHookHandler, preHandlerHookHandler } from 'fastify';
import { OpenAPI, OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
import { FastifyPluginCallback, FastifySchema, RouteOptions } from 'fastify'
import {
OpenAPI,
OpenAPIV2,
OpenAPIV3,
// eslint-disable-next-line camelcase
OpenAPIV3_1
} from 'openapi-types'

/**
* Swagger-UI Vendor Extensions
Expand Down Expand Up @@ -61,6 +67,7 @@ declare module 'fastify' {
type SwaggerDocumentObject = {
swaggerObject: Partial<OpenAPIV2.Document>;
} | {
// eslint-disable-next-line camelcase
openapiObject: Partial<OpenAPIV3.Document | OpenAPIV3_1.Document>;
}

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

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

type FastifySwagger = FastifyPluginCallback<fastifySwagger.SwaggerOptions>

declare namespace fastifySwagger {
export type SwaggerOptions = (FastifyStaticSwaggerOptions | FastifyDynamicSwaggerOptions);
export type SwaggerOptions = (FastifyStaticSwaggerOptions | FastifyDynamicSwaggerOptions)
export interface FastifySwaggerOptions {
mode?: 'static' | 'dynamic';
}

export type FastifySwaggerUiConfigOptions = Partial<{
deepLinking: boolean
displayOperationId: boolean
defaultModelsExpandDepth: number
defaultModelExpandDepth: number
defaultModelRendering: string
displayRequestDuration: boolean
docExpansion: string
filter: boolean | string
layout: string
maxDisplayedTags: number
showExtensions: boolean
showCommonExtensions: boolean
useUnsafeMarkdown: boolean
syntaxHighlight: {
activate?: boolean
theme?: string
} | false
tryItOutEnabled: boolean
validatorUrl: string | null
supportedSubmitMethods: Array<'get' | 'post' | 'put' | 'delete' | 'patch' | 'options'>
persistAuthorization: boolean
}>

export type FastifySwaggerInitOAuthOptions = Partial<{
clientId: string,
clientSecret: string,
realm: string,
appName: string,
scopeSeparator: string,
scopes: string | string[],
additionalQueryStringParams: { [key: string]: any },
useBasicAuthenticationWithAccessCodeGrant: boolean,
usePkceWithAuthorizationCodeGrant: boolean
}>

type JSONValue =
| string
| null
| number
| boolean
| JSONObject
| Array<JSONValue>;
| Array<JSONValue>

export interface JSONObject {
[key: string]: JSONValue;
Expand All @@ -136,6 +108,7 @@ declare namespace fastifySwagger {
export interface FastifyDynamicSwaggerOptions extends FastifySwaggerOptions {
mode?: 'dynamic';
swagger?: Partial<OpenAPIV2.Document>;
// eslint-disable-next-line camelcase
openapi?: Partial<OpenAPIV3.Document | OpenAPIV3_1.Document>
hiddenTag?: string;
hideUntagged?: boolean;
Expand Down Expand Up @@ -195,17 +168,12 @@ declare namespace fastifySwagger {
specification: StaticPathSpec | StaticDocumentSpec;
}

export type FastifySwaggerUiHooksOptions = Partial<{
onRequest?: onRequestHookHandler,
preHandler?: preHandlerHookHandler,
}>

export function formatParamUrl (paramUrl: string): string

export const fastifySwagger: FastifySwagger
export { fastifySwagger as default }
}

declare function fastifySwagger(...params: Parameters<FastifySwagger>): ReturnType<FastifySwagger>
declare function fastifySwagger (...params: Parameters<FastifySwagger>): ReturnType<FastifySwagger>

export = fastifySwagger;
export = fastifySwagger
12 changes: 3 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
},
Expand All @@ -59,12 +59,6 @@
"rfdc": "^1.3.1",
"yaml": "^2.4.2"
},
"standard": {
"ignore": [
"static",
"tap-snapshots/*"
]
},
"tsd": {
"directory": "test/types"
},
Expand Down
36 changes: 19 additions & 17 deletions test/types/http2-types.test.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
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: {
description: 'returns 200 OK',
summary: 'qwerty',
security: []
}
}, (req, reply) => {});
}, (req, reply) => {})

app
.register(fastifySwagger, {
Expand Down Expand Up @@ -65,6 +67,6 @@ app
}
}
})
.ready(err => {
app.swagger();
});
.ready(() => {
app.swagger()
})
28 changes: 14 additions & 14 deletions test/types/imports.test.ts
Original file line number Diff line number Diff line change
@@ -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.ready(() => {
app.swagger()
})
6 changes: 3 additions & 3 deletions test/types/minimal-openapiV3-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
}
}
Loading
Loading