Skip to content

Commit 2df5f45

Browse files
committed
Uplift
- lint - build - travis - jest - other deps Skipping servlerless as it needs compatibility changes
1 parent 1d43de2 commit 2df5f45

File tree

12 files changed

+764
-1525
lines changed

12 files changed

+764
-1525
lines changed

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: node_js
2+
3+
node_js:
4+
- "6"
5+
6+
install:
7+
- yarn install
8+
9+
script:
10+
- yarn lint
11+
- yarn build
12+
- yarn test
13+
- yarn test:bench

.jestrc renamed to jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{
1+
module.exports = {
22
"verbose": true,
33
"transform": { ".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js" },
44
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",

package.json

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,46 @@
44
"description": "Serverless 1.0 plugin to generate OpenAPI V3 documentation from serverless configuration",
55
"main": "dist/index.js",
66
"author": "Abilio Henrique <[email protected]>",
7+
"contributors": [
8+
"Abilio Henrique <[email protected]>",
9+
10+
],
711
"license": "MIT",
812
"files": [
913
"dist"
1014
],
1115
"scripts": {
1216
"test": "yarn test:unit",
13-
"test:unit": "jest -i --config .jestrc",
14-
"lint": "eslint src",
15-
"test:watch": "jest --config .jestrc -i -t '/[^/.]+\\.test' --watch",
16-
"release:npm": "cd dist && npm publish",
17-
"docs": "typedoc --out ./dist/docs --target es6 --readme README.md",
18-
"build": "node scripts/package"
17+
"test:unit": "jest",
18+
"lint": "tslint 'src/**/*.ts'",
19+
"test:watch": "jest -t '/[^/.]+\\.test' --watch",
20+
"release": "cd dist && npm publish",
21+
"build": "scripts/build.bash"
1922
},
2023
"devDependencies": {
21-
"@types/jest": "^19.2.2",
22-
"@types/node": "^7.0.12",
23-
"@types/typescript": "^2.0.0",
24-
"eslint": "^3.19.0",
25-
"eslint-config-airbnb-base": "^11.1.3",
26-
"eslint-plugin-import": "^2.2.0",
27-
"jest": "^19.0.2",
28-
"serverless": "^1.11.0",
29-
"ts-jest": "^19.0.8",
30-
"ts-node": "^3.0.2",
31-
"tslint": "^5.1.0",
32-
"tslint-eslint-rules": "^4.0.0",
33-
"typedoc": "^0.5.10",
34-
"typescript": "^2.2.2"
24+
"@types/chalk": "^0.4.31",
25+
"@types/fs-extra": "^3.0.3",
26+
"@types/jest": "^20.0.2",
27+
"@types/js-yaml": "^3.5.31",
28+
"@types/node": "^8.0.7",
29+
"@types/uuid": "^3.0.0",
30+
"jest": "^20.0.4",
31+
"serverless": "1.11",
32+
"ts-jest": "^20.0.6",
33+
"ts-node": "^3.1.0",
34+
"tslint": "^5.4.3",
35+
"tslint-config-temando": "^1.1.4",
36+
"typescript": "^2.4.1"
3537
},
3638
"dependencies": {
37-
"@jdw/jst": "^1.0.0-beta.10",
38-
"@types/bluebird": "^3.5.2",
39-
"@types/chalk": "^0.4.31",
40-
"@types/fs-promise": "^1.0.3",
41-
"@types/js-yaml": "^3.5.29",
42-
"@types/uuid": "^2.0.29",
39+
"@jdw/jst": "^1.0.0",
40+
"@types/bluebird": "^3.5.8",
4341
"bluebird": "^3.5.0",
44-
"chalk": "^1.1.3",
45-
"fs-promise": "^2.0.2",
46-
"js-yaml": "^3.8.3",
47-
"lutils": "^1.2.5",
48-
"swagger2openapi": "^2.0.3",
49-
"uuid": "^3.0.1"
42+
"chalk": "^2.0.1",
43+
"fs-extra": "^3.0.1",
44+
"js-yaml": "^3.8.4",
45+
"lutils": "^2.4.0",
46+
"swagger2openapi": "^2.5.0",
47+
"uuid": "^3.1.0"
5048
}
5149
}

scripts/build.bash

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
# Clean
4+
rm -rf dist
5+
mkdir dist
6+
7+
# Copy latent, belonging to the index module
8+
rsync -am . ./dist --exclude '*/*' --include '*'
9+
10+
# Copy latent files from source, recursively
11+
rsync -am ./src/* ./dist --exclude '*.ts'
12+
13+
# Build typescript
14+
yarn tsc
15+
16+
17+
18+

scripts/package.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/generate.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default class DocumentGenerator {
2828
* Constructor
2929
* @param serviceDescriptor IServiceDescription
3030
*/
31-
constructor(serviceDescriptor: IServiceDescription) {
31+
constructor (serviceDescriptor: IServiceDescription) {
3232
this.serviceDescriptor = clone(serviceDescriptor);
3333

3434
merge(this.config, {
@@ -51,7 +51,7 @@ export default class DocumentGenerator {
5151
}
5252
}
5353

54-
public generate() {
54+
public generate () {
5555
const result: any = {};
5656
process.stdout.write(`${ c.bold.yellow('[VALIDATION]') } Validating OpenAPI generated output\n`);
5757
try {
@@ -71,7 +71,7 @@ export default class DocumentGenerator {
7171
* Add Paths to OpenAPI Configuration from Serverless function documentation
7272
* @param config Add
7373
*/
74-
public addPathsFromFunctionConfig(config: IServerlessFunctionConfig[]): void {
74+
public addPathsFromFunctionConfig (config: IServerlessFunctionConfig[]): void {
7575
// loop through function configurations
7676
for (const funcConfig of config) {
7777
// loop through http events
@@ -103,7 +103,7 @@ export default class DocumentGenerator {
103103
* Cleans schema objects to make them OpenAPI compatible
104104
* @param schema JSON Schema Object
105105
*/
106-
private cleanSchema(schema) {
106+
private cleanSchema (schema) {
107107
// Clone the schema for manipulation
108108
const cleanedSchema = clone(schema);
109109

@@ -120,7 +120,7 @@ export default class DocumentGenerator {
120120
* Derives Path, Query and Request header parameters from Serverless documentation
121121
* @param documentationConfig
122122
*/
123-
private getParametersFromConfig(documentationConfig): IParameterConfig[] {
123+
private getParametersFromConfig (documentationConfig): IParameterConfig[] {
124124
const parameters: IParameterConfig[] = [];
125125

126126
// Build up parameters from configuration for each parameter type
@@ -164,11 +164,10 @@ export default class DocumentGenerator {
164164

165165
if ('style' in parameter) {
166166
parameterConfig.style = parameter.style;
167-
if (parameter.explode) {
168-
parameterConfig.explode = parameter.explode;
169-
} else {
170-
parameterConfig.explode = parameter.explode || (parameter.style === 'form' ? true : false);
171-
}
167+
168+
parameterConfig.explode = parameter.explode
169+
? parameter.explode
170+
: parameter.style === 'form';
172171
}
173172

174173
// console.log(parameter);
@@ -194,7 +193,7 @@ export default class DocumentGenerator {
194193
* Derives request body schemas from event documentation configuration
195194
* @param documentationConfig
196195
*/
197-
private getRequestBodiesFromConfig(documentationConfig) {
196+
private getRequestBodiesFromConfig (documentationConfig) {
198197
const requestBodies = {};
199198

200199
// Does this event have a request model?
@@ -242,7 +241,7 @@ export default class DocumentGenerator {
242241
* Gets response bodies from documentation config
243242
* @param documentationConfig
244243
*/
245-
private getResponsesFromConfig(documentationConfig) {
244+
private getResponsesFromConfig (documentationConfig) {
246245
const responses = {};
247246
if (documentationConfig.methodResponses) {
248247
for (const response of documentationConfig.methodResponses) {
@@ -269,14 +268,14 @@ export default class DocumentGenerator {
269268

270269
merge(responses, {
271270
[response.statusCode]: methodResponseConfig,
272-
});
271+
});
273272
}
274273
}
275274

276275
return responses;
277276
}
278277

279-
private getResponseContent(response) {
278+
private getResponseContent (response) {
280279
const content = {};
281280
for (const responseKey of Object.keys(response)) {
282281
const responseModel = this.serviceDescriptor.models.filter(
@@ -300,7 +299,7 @@ export default class DocumentGenerator {
300299
return content;
301300
}
302301

303-
private getHttpEvents(funcConfig) {
302+
private getHttpEvents (funcConfig) {
304303
return funcConfig.filter((event) => event.http ? true : false);
305304
}
306305
}

src/index.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default class ServerlessOpenAPIDocumentation {
2020
* @param serverless
2121
* @param options
2222
*/
23-
constructor(serverless, options) {
23+
constructor (serverless, options) {
2424
// pull the serverless instance into our class vars
2525
this.serverless = serverless;
2626
// pull the CLI options into our class vars
@@ -66,7 +66,7 @@ export default class ServerlessOpenAPIDocumentation {
6666
* Processes CLI input by reading the input from serverless
6767
* @returns config IConfigType
6868
*/
69-
private processCliInput(): IConfigType {
69+
private processCliInput (): IConfigType {
7070
const config: IConfigType = {
7171
format: 'yaml',
7272
file: 'openapi.yml',
@@ -95,7 +95,7 @@ export default class ServerlessOpenAPIDocumentation {
9595
/**
9696
* Generates OpenAPI Documentation based on serverless configuration and functions
9797
*/
98-
private generate() {
98+
private generate () {
9999
process.stdout.write(c.bold.underline('OpenAPI v3 Documentation Generator\n\n'));
100100
// Instantiate DocumentGenerator
101101
const dg = new DocumentGenerator(this.customVars.documentation);
@@ -118,13 +118,13 @@ export default class ServerlessOpenAPIDocumentation {
118118
// Output the OpenAPI document to the correct format
119119
let outputContent = '';
120120
switch (config.format.toLowerCase()) {
121-
case 'json':
122-
outputContent = JSON.stringify(outputObject, null, config.indent);
123-
break;
124-
case 'yaml':
125-
default:
126-
outputContent = YAML.safeDump(outputObject, { indent: config.indent });
127-
break;
121+
case 'json':
122+
outputContent = JSON.stringify(outputObject, null, config.indent);
123+
break;
124+
case 'yaml':
125+
default:
126+
outputContent = YAML.safeDump(outputObject, { indent: config.indent });
127+
break;
128128
}
129129

130130
// Write to disk
@@ -134,4 +134,3 @@ export default class ServerlessOpenAPIDocumentation {
134134
}
135135

136136
module.exports = ServerlessOpenAPIDocumentation;
137-

src/utils.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as lutils from 'lutils';
1+
import { Clone, IMerge, Merge } from 'lutils';
22

3-
export const merge = (...args) => lutils.merge([...args], { depth: 100 });
4-
5-
export const clone = (arg, options = {}) => lutils.clone(arg, { ...options, depth: 100 });
3+
export const merge = new Merge({ depth: 100 }).merge;
4+
export const clone = new Clone({ depth: 100 }).clone;

test/openapi-generate.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as fs from 'fs-promise';
1+
import * as fs from 'fs-extra';
22
import * as path from 'path';
33
import * as Serverless from 'serverless';
44
import DocumentGenerator from '../src/generate';

tsconfig.json

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
{
22
"compilerOptions": {
3-
"target": "es5",
3+
"target": "es6",
44
"module": "commonjs",
55
"moduleResolution": "node",
66
"outDir":"./dist",
7-
"inlineSourceMap": true,
8-
"inlineSources": true,
9-
"allowJs": false,
10-
"allowSyntheticDefaultImports": true,
7+
"sourceMap": true,
118
"declaration": true,
129
"lib": [
13-
"es2015",
14-
"es2016",
15-
"es2017.object"
10+
"es6",
11+
"es7",
12+
"dom"
1613
]
1714
},
18-
"exclude": [
19-
"node_modules",
20-
"dist"
21-
],
22-
"include": [
23-
"src/**/*"
24-
]
15+
"exclude": [],
16+
"include": [ "src/**/*" ]
2517
}

0 commit comments

Comments
 (0)