From 530514a394c58fa8d26b5084a813de2b49a42d17 Mon Sep 17 00:00:00 2001 From: Peter Balazs Date: Tue, 5 May 2020 11:50:00 +0100 Subject: [PATCH 1/7] update fastify to v3 --- index.d.ts | 92 ++++++++----------- index.js | 2 +- package.json | 13 ++- test/transform.js | 4 +- .../types/http2-types.test.ts | 18 ++-- types.test.ts => test/types/types.test.ts | 4 +- tsconfig.json | 10 -- 7 files changed, 61 insertions(+), 82 deletions(-) rename http2-types.test.ts => test/types/http2-types.test.ts (84%) rename types.test.ts => test/types/types.test.ts (94%) delete mode 100644 tsconfig.json 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..bc1ccbe8 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"] -} From f522696408a2ca5effb2e1e77b008dd72c9ad1ab Mon Sep 17 00:00:00 2001 From: Peter Balazs Date: Tue, 5 May 2020 11:50:50 +0100 Subject: [PATCH 2/7] add dependabot config --- .dependabot/config.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .dependabot/config.yml diff --git a/.dependabot/config.yml b/.dependabot/config.yml new file mode 100644 index 00000000..816b7638 --- /dev/null +++ b/.dependabot/config.yml @@ -0,0 +1,5 @@ +version: 1 +update_conigs: + package_manager: "javascript" + directory: "/" + update_schedule: "daily" \ No newline at end of file From de5d0718d2b494c641e82b8a1cf603f88ba81bf3 Mon Sep 17 00:00:00 2001 From: Peter Balazs Date: Tue, 5 May 2020 11:54:13 +0100 Subject: [PATCH 3/7] add github actions config --- .github/workflows/ci.yml | 20 ++++++++++++++++++++ .travis.yml | 14 -------------- 2 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml 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 From a6a5f0087dbfd6a7b1f808644e24e6700eb242ea Mon Sep 17 00:00:00 2001 From: Peter Balazs Date: Tue, 5 May 2020 11:57:20 +0100 Subject: [PATCH 4/7] Add CI status badge to readme --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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. From 1ecfc7283b8befc4613f910418462ef23865b12c Mon Sep 17 00:00:00 2001 From: Peter Balazs Date: Tue, 5 May 2020 12:15:12 +0100 Subject: [PATCH 5/7] update dependabot config --- .dependabot/config.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.dependabot/config.yml b/.dependabot/config.yml index 816b7638..c35198c6 100644 --- a/.dependabot/config.yml +++ b/.dependabot/config.yml @@ -1,5 +1,5 @@ version: 1 -update_conigs: - package_manager: "javascript" - directory: "/" - update_schedule: "daily" \ No newline at end of file +update_configs: + - package_manager: "javascript" + directory: "/" + update_schedule: "daily" \ No newline at end of file From 37df011e2c8b0fb77e515bd7c179bbaa64da2556 Mon Sep 17 00:00:00 2001 From: Peter Balazs Date: Thu, 7 May 2020 09:06:52 +0100 Subject: [PATCH 6/7] Update test/transform.js Co-authored-by: Manuel Spigolon --- test/transform.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/transform.js b/test/transform.js index bc1ccbe8..97cedc42 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.setValidatorCompiler(schema => Joi.validate(schema)) + fastify.setValidatorCompiler(({ schema }) => Joi.validate(schema)) fastify.get('/example', opts, () => {}) fastify.ready(err => { From 083bc0cbb532e4734f7b306573b5e86278a3d788 Mon Sep 17 00:00:00 2001 From: Peter Balazs Date: Thu, 7 May 2020 09:07:00 +0100 Subject: [PATCH 7/7] Update test/transform.js Co-authored-by: Manuel Spigolon --- test/transform.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/transform.js b/test/transform.js index 97cedc42..62aecb81 100644 --- a/test/transform.js +++ b/test/transform.js @@ -48,7 +48,7 @@ test('transform should work with a Function', t => { fastify.register(fastifySwagger, valid) - fastify.setValidatorCompiler(schema => Joi.validate(schema)) + fastify.setValidatorCompiler(({ schema }) => Joi.validate(schema)) fastify.get('/example', opts, () => {}) fastify.ready(err => {