[swagger-jsdoc] Made declarations more detailed (#36977)

* update type definitions for swagger-jsdoc
* Made declarations more detailed
* Changed from ambient declarations to export
  - Interfaces are exported
  - Main function as default export

* Decrease minimum version of swagger-jsdoc to 3.0
This commit is contained in:
neilbryson 2019-07-23 03:37:25 +08:00 committed by Wesley Wigham
parent 36e86e6069
commit 4fc501737d
2 changed files with 49 additions and 19 deletions

View File

@ -1,16 +1,18 @@
// Type definitions for Swagger-JSDoc
// Type definitions for swagger-jsdoc 3.0
// Project: https://github.com/surnet/swagger-jsdoc
// Definitions by: Daniel Grove <https://github.com/drGrove>
// Neil Bryson Cargamento <https://github.com/neilbryson>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
// TypeScript Version: 2.8
/* =================== USAGE ===================
import * as express from "express"
import swaggerJSDoc = require('swagger-jsdoc');
const app = express()
import * as express from 'express';
import swaggerJSDoc, { Options } from 'swagger-jsdoc';
let options = {
const app = express();
const options: Options = {
swaggerDefinition: {
info: {
title: 'Hello World',
@ -27,7 +29,7 @@
}
};
var spec = swaggerJSDoc(options);
const spec = swaggerJSDoc(options);
app.get('/api-docs.json', function(req, res) {
res.setHeader('Content-Type', 'application/json');
@ -36,7 +38,30 @@
=============================================== */
declare module "swagger-jsdoc" {
function swaggerJSDoc(options?: any): any;
export = swaggerJSDoc;
export interface ApiInformation {
description?: string;
title: string;
version: string;
}
export interface ServerInformation {
url: string;
[key: string]: any;
}
export interface SwaggerDefinition {
basePath?: string;
host?: string;
info: ApiInformation;
openapi?: string;
servers?: ReadonlyArray<ServerInformation>;
[key: string]: any;
}
export interface Options {
apis?: ReadonlyArray<string>;
swaggerDefinition: SwaggerDefinition;
[key: string]: any;
}
export default function swaggerJSDoc(options?: Options): any;

View File

@ -1,21 +1,26 @@
import express = require('express');
import swaggerJSDoc = require('swagger-jsdoc');
import * as express from 'express';
import swaggerJSDoc, { Options } from 'swagger-jsdoc';
const app = express();
let options = {
const options: Options = {
swaggerDefinition: {
info: {
title: 'A test api',
version: '1.0.0'
}
}
version: '1.0.0',
},
host: 'localhost:3000',
basePath: '/',
openapi: '3.0.0',
servers: [{ url: '/api/v1' }, { url: '/api/v2' }],
},
apis: ['./example/routes*.js', './example/parameters.yaml'],
};
let swaggerSpec = swaggerJSDoc(options);
const swaggerSpec = swaggerJSDoc(options);
app.get('/api-docs.json', function(req, res) {
res.send(swaggerSpec);
})
});
app.listen(8888);