diff --git a/.dependabot/config.yml b/.dependabot/config.yml new file mode 100644 index 00000000..c35198c6 --- /dev/null +++ b/.dependabot/config.yml @@ -0,0 +1,5 @@ +version: 1 +update_configs: + - package_manager: "javascript" + directory: "/" + update_schedule: "daily" \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..d6911085 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,20 @@ +name: CI workflow +on: [push, pull_request] +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [10.x, 12.x, 14.x] + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: Install Dependencies + run: npm install --ignore-scripts + - name: Prepare + run: npm run prepare + - name: Test + run: npm test diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1a875d13..00000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -language: node_js -node_js: - - "6" - - "8" - - "10" - - "11" - -before_script: - - npm run prepare - -notifications: - email: - on_success: never - on_failure: always diff --git a/README.md b/README.md index 98d4e810..a3b2b3b8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # fastify-swagger -[![Greenkeeper badge](https://badges.greenkeeper.io/fastify/fastify-swagger.svg)](https://greenkeeper.io/) -[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) [![Build Status](https://travis-ci.org/fastify/fastify-swagger.svg?branch=master)](https://travis-ci.org/fastify/fastify-swagger) +[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) ![CI workflow](https://github.com/fastify/fastify-swagger/workflows/CI%20workflow/badge.svg) [Swagger](https://swagger.io/) documentation generator for Fastify. It uses the schemas you declare in your routes to generate a swagger compliant doc. diff --git a/index.d.ts b/index.d.ts index edc85167..587d2555 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,54 +1,46 @@ -import * as http from 'http'; -import * as fastify from 'fastify'; +import { FastifyPlugin } from 'fastify'; import * as SwaggerSchema from 'swagger-schema-official'; -import * as http2 from 'http2'; -declare namespace fastifySwagger { - interface FastifySwaggerOptions { - mode?: 'static' | 'dynamic'; - /** - * Overwrite the swagger url end-point - * @default /documentation - */ - routePrefix?: string; - /** - * To expose the documentation api - * @default false - */ - exposeRoute?: boolean; - } +interface FastifySwaggerOptions { + mode?: 'static' | 'dynamic'; + /** + * Overwrite the swagger url end-point + * @default /documentation + */ + routePrefix?: string; + /** + * To expose the documentation api + * @default false + */ + exposeRoute?: boolean; +} - interface FastifyDynamicSwaggerOptions extends FastifySwaggerOptions { - mode?: 'dynamic'; - swagger?: Partial; - /** - * Overwrite the route schema - */ - transform?: Function; - } +interface FastifyDynamicSwaggerOptions extends FastifySwaggerOptions { + mode?: 'dynamic'; + swagger?: Partial; + /** + * Overwrite the route schema + */ + transform?: Function; +} - interface StaticPathSpec { - path: string; - postProcessor?: (spec: SwaggerSchema.Spec) => SwaggerSchema.Spec; - baseDir: string; - } +interface StaticPathSpec { + path: string; + postProcessor?: (spec: SwaggerSchema.Spec) => SwaggerSchema.Spec; + baseDir: string; +} - interface StaticDocumentSpec { - document: string; - } +interface StaticDocumentSpec { + document: string; +} - interface FastifyStaticSwaggerOptions extends FastifySwaggerOptions { - mode: 'static'; - specification: StaticPathSpec | StaticDocumentSpec; - } +interface FastifyStaticSwaggerOptions extends FastifySwaggerOptions { + mode: 'static'; + specification: StaticPathSpec | StaticDocumentSpec; } declare module 'fastify' { - interface FastifyInstance< - HttpServer, - HttpRequest, - HttpResponse - > { + interface FastifyInstance { swagger: ( opts?: { yaml?: boolean; @@ -56,7 +48,7 @@ declare module 'fastify' { ) => SwaggerSchema.Spec; } - interface RouteSchema { + interface FastifySchema { hide?: boolean; tags?: string[]; description?: string; @@ -66,14 +58,8 @@ declare module 'fastify' { } } -declare function fastifySwagger< - HttpServer extends (http.Server | http2.Http2Server), - HttpRequest extends (http.IncomingMessage | http2.Http2ServerRequest), - HttpResponse extends (http.ServerResponse | http2.Http2ServerResponse), - SwaggerOptions = (fastifySwagger.FastifyStaticSwaggerOptions | fastifySwagger.FastifyDynamicSwaggerOptions) ->( - fastify : fastify.FastifyInstance, - opts : SwaggerOptions -) : void; +type SwaggerOptions = (FastifyStaticSwaggerOptions | FastifyDynamicSwaggerOptions) + +declare const fastifySwagger: FastifyPlugin -export = fastifySwagger; +export default fastifySwagger; diff --git a/index.js b/index.js index 77d60ade..f4a02438 100644 --- a/index.js +++ b/index.js @@ -23,6 +23,6 @@ function fastifySwagger (fastify, opts, next) { } module.exports = fp(fastifySwagger, { - fastify: '>=2.0.0', + fastify: '>=3.x', name: 'fastify-swagger' }) diff --git a/package.json b/package.json index 60a5cd8c..a2e0b154 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "prepare": "node prepare-swagger-ui", "test": "standard && tap test/*.js && npm run typescript", "prepublishOnly": "npm run prepare", - "typescript": "tsc --project ./tsconfig.json" + "typescript": "tsd" }, "repository": { "type": "git", @@ -31,7 +31,7 @@ "homepage": "https://github.com/fastify/fastify-swagger#readme", "devDependencies": { "@types/node": "^12.11.7", - "fastify": "^2.10.0", + "fastify": "^3.0.0-rc.1", "fs-extra": "^8.0.1", "joi": "^14.3.1", "joi-to-json-schema": "^5.1.0", @@ -40,12 +40,12 @@ "swagger-parser": "^6.0.3", "swagger-ui-dist": "3.24.3", "tap": "^12.7.0", - "typescript": "^3.7.2" + "tsd": "^0.11.0" }, "dependencies": { "@types/swagger-schema-official": "^2.0.20", - "fastify-plugin": "^1.6.0", - "fastify-static": "^2.5.1", + "fastify-plugin": "^2.0.0", + "fastify-static": "^3.0.0", "js-yaml": "^3.12.1" }, "standard": { @@ -58,5 +58,8 @@ "ignore": [ "tap" ] + }, + "tsd": { + "directory": "test/types" } } diff --git a/test/transform.js b/test/transform.js index 6a5bd377..62aecb81 100644 --- a/test/transform.js +++ b/test/transform.js @@ -34,7 +34,7 @@ test('transform should fail with a value other than Function', t => { fastify.register(fastifySwagger, invalid) - fastify.setSchemaCompiler(schema => Joi.validate(schema)) + fastify.setValidatorCompiler(({ schema }) => Joi.validate(schema)) fastify.get('/example', opts, () => {}) fastify.ready(err => { @@ -48,7 +48,7 @@ test('transform should work with a Function', t => { fastify.register(fastifySwagger, valid) - fastify.setSchemaCompiler(schema => Joi.validate(schema)) + fastify.setValidatorCompiler(({ schema }) => Joi.validate(schema)) fastify.get('/example', opts, () => {}) fastify.ready(err => { diff --git a/http2-types.test.ts b/test/types/http2-types.test.ts similarity index 84% rename from http2-types.test.ts rename to test/types/http2-types.test.ts index 8fbe88d1..813676f2 100644 --- a/http2-types.test.ts +++ b/test/types/http2-types.test.ts @@ -1,5 +1,5 @@ -import fastify = require('fastify'); -import fastifySwagger = require('.'); +import fastify from 'fastify'; +import fastifySwagger from '../..'; const app = fastify({ http2: true @@ -18,13 +18,13 @@ app.register(fastifySwagger, { }); app.put('/some-route/:id', { - schema: { - description: 'put me some data', - tags: ['user', 'code'], - summary: 'qwerty', - security: [{ apiKey: []}] - } - }, (req, reply) => {}); + schema: { + description: 'put me some data', + tags: ['user', 'code'], + summary: 'qwerty', + security: [{ apiKey: []}] + } +}, (req, reply) => {}); app.get('/public/route', { schema: { diff --git a/types.test.ts b/test/types/types.test.ts similarity index 94% rename from types.test.ts rename to test/types/types.test.ts index 2b155821..838b7cd3 100644 --- a/types.test.ts +++ b/test/types/types.test.ts @@ -1,5 +1,5 @@ -import fastify = require('fastify'); -import fastifySwagger = require('../fastify-swagger'); +import fastify from 'fastify'; +import fastifySwagger from '../..'; const app = fastify(); diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index ed258ee7..00000000 --- a/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "compilerOptions": { - "target": "es6", - "module": "commonjs", - "noEmit": true, - "strict": true, - "noImplicitAny": true - }, - "files": ["./types.test.ts", "./http2-types.test.ts"] -}