Skip to content

Commit

Permalink
Update fastify to v3 (#238)
Browse files Browse the repository at this point in the history
* update fastify to v3

* add dependabot config

* add github actions config

* Add CI status badge to readme

* update dependabot config

* Update test/transform.js

Co-authored-by: Manuel Spigolon <[email protected]>

* Update test/transform.js

Co-authored-by: Manuel Spigolon <[email protected]>

Co-authored-by: Manuel Spigolon <[email protected]>
  • Loading branch information
frikille and Eomm authored May 16, 2020
1 parent 8187bd0 commit 433fd05
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 98 deletions.
5 changes: 5 additions & 0 deletions .dependabot/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: 1
update_configs:
- package_manager: "javascript"
directory: "/"
update_schedule: "daily"
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
92 changes: 39 additions & 53 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,54 @@
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<SwaggerSchema.Spec>;
/**
* Overwrite the route schema
*/
transform?: Function;
}
interface FastifyDynamicSwaggerOptions extends FastifySwaggerOptions {
mode?: 'dynamic';
swagger?: Partial<SwaggerSchema.Spec>;
/**
* 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;
}
) => SwaggerSchema.Spec;
}

interface RouteSchema {
interface FastifySchema {
hide?: boolean;
tags?: string[];
description?: string;
Expand All @@ -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<HttpServer, HttpRequest, HttpResponse>,
opts : SwaggerOptions
) : void;
type SwaggerOptions = (FastifyStaticSwaggerOptions | FastifyDynamicSwaggerOptions)

declare const fastifySwagger: FastifyPlugin<SwaggerOptions>

export = fastifySwagger;
export default fastifySwagger;
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ function fastifySwagger (fastify, opts, next) {
}

module.exports = fp(fastifySwagger, {
fastify: '>=2.0.0',
fastify: '>=3.x',
name: 'fastify-swagger'
})
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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": {
Expand All @@ -58,5 +58,8 @@
"ignore": [
"tap"
]
},
"tsd": {
"directory": "test/types"
}
}
4 changes: 2 additions & 2 deletions test/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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 => {
Expand Down
18 changes: 9 additions & 9 deletions http2-types.test.ts → test/types/http2-types.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fastify = require('fastify');
import fastifySwagger = require('.');
import fastify from 'fastify';
import fastifySwagger from '../..';

const app = fastify({
http2: true
Expand All @@ -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: {
Expand Down
4 changes: 2 additions & 2 deletions types.test.ts → test/types/types.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fastify = require('fastify');
import fastifySwagger = require('../fastify-swagger');
import fastify from 'fastify';
import fastifySwagger from '../..';

const app = fastify();

Expand Down
10 changes: 0 additions & 10 deletions tsconfig.json

This file was deleted.

0 comments on commit 433fd05

Please sign in to comment.