Skip to content

Commit

Permalink
HTTP2 Support added (#169)
Browse files Browse the repository at this point in the history
changed types to support http2
added a http2 types testfile
  • Loading branch information
RSWilli authored and mcollina committed Apr 14, 2019
1 parent f5ac48d commit c41d37c
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 10 deletions.
62 changes: 62 additions & 0 deletions http2-types.test.ts
@@ -0,0 +1,62 @@
import fastify = require('fastify');
import fastifySwagger = require('.');

const app = fastify({
http2: true
});

app.register(fastifySwagger);
app.register(fastifySwagger, {});
app.register(fastifySwagger, { transform: (schema : any) => schema });
app.register(fastifySwagger, {
mode: 'static',
specification: {
document: 'path'
},
routePrefix: '/documentation',
exposeRoute: true,
});

app.put('/some-route/:id', {
schema: {
description: 'put me some data',
tags: ['user', 'code'],
summary: 'qwerty',
security: [{ apiKey: []}]
}
}, (req, reply) => {});

app
.register(fastifySwagger, {
routePrefix: '/documentation',
exposeRoute: true,
swagger: {
info: {
title: 'Test swagger',
description: 'testing the fastify swagger api',
version: '0.1.0'
},
externalDocs: {
url: 'https://swagger.io',
description: 'Find more info here'
},
host: 'localhost',
schemes: ['http'],
consumes: ['application/json'],
produces: ['application/json'],
tags: [
{ name: 'user', description: 'User related end-points' },
{ name: 'code', description: 'Code related end-points' }
],
securityDefinitions: {
apiKey: {
type: 'apiKey',
name: 'apiKey',
in: 'header'
}
}
}
})
.ready(err => {
app.swagger();
});
22 changes: 13 additions & 9 deletions index.d.ts
@@ -1,6 +1,7 @@
import * as http from 'http';
import * as fastify from 'fastify';
import * as SwaggerSchema from 'swagger-schema-official';
import * as http2 from 'http2';

declare namespace fastifySwagger {
interface FastifySwaggerOptions {
Expand Down Expand Up @@ -44,9 +45,9 @@ declare namespace fastifySwagger {

declare module 'fastify' {
interface FastifyInstance<
HttpServer = http.Server,
HttpRequest = http.IncomingMessage,
HttpResponse = http.ServerResponse
HttpServer,
HttpRequest,
HttpResponse
> {
swagger: (
opts?: {
Expand All @@ -63,11 +64,14 @@ declare module 'fastify' {
}
}

declare let fastifySwagger: fastify.Plugin<
http.Server,
http.IncomingMessage,
http.ServerResponse,
fastifySwagger.FastifyStaticSwaggerOptions | fastifySwagger.FastifyDynamicSwaggerOptions
>;
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;

export = fastifySwagger;
2 changes: 1 addition & 1 deletion tsconfig.json
Expand Up @@ -6,5 +6,5 @@
"strict": true,
"noImplicitAny": true
},
"files": ["./types.test.ts"]
"files": ["./types.test.ts", "./http2-types.test.ts"]
}

0 comments on commit c41d37c

Please sign in to comment.