Skip to content

Commit d8a6bb8

Browse files
authored
Merge pull request #1 from temando/uplift
Uplift
2 parents 1d43de2 + 90aa966 commit d8a6bb8

22 files changed

+1155
-1611
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
node_modules
22
/npm-*
3-
/dist
4-
3+
/build
4+
.coverage
55
.directory
66
.DS_STORE*
77
*.log

.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
**/__tests__/**
2+
.*
3+
tslint.json
4+
tsconfig.json
5+
jest.config.js
6+
yarn.lock

.travis.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
language: node_js
2+
node_js: ["6"]
3+
4+
before_install:
5+
- echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc
6+
7+
install:
8+
- yarn install
9+
10+
script:
11+
- yarn lint
12+
- yarn build
13+
- yarn test:build
14+
- DEBUG=true yarn test:coverage
15+
16+
deploy:
17+
provider: script
18+
script:
19+
- npm run release
20+
on:
21+
tags: true

.jestrc renamed to jest.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
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)$",
55
"moduleFileExtensions": [ "ts", "tsx", "js" ],
6+
"coverageDirectory": ".coverage",
67
"testPathIgnorePatterns": [
78
"/node_modules/",
9+
"/build/",
810
"d.ts"
911
]
1012
}

package.json

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,45 @@
22
"name": "serverless-openapi-documentation",
33
"version": "0.0.0",
44
"description": "Serverless 1.0 plugin to generate OpenAPI V3 documentation from serverless configuration",
5-
"main": "dist/index.js",
5+
"main": "index.js",
66
"author": "Abilio Henrique <[email protected]>",
7-
"license": "MIT",
8-
"files": [
9-
"dist"
7+
"contributors": [
8+
"Abilio Henrique <[email protected]>",
9+
1010
],
11+
"license": "MIT",
1112
"scripts": {
12-
"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"
13+
"test": "jest",
14+
"test:build": "jest -c '{}' build",
15+
"test:coverage": "jest --coverage",
16+
"lint": "tslint 'src/**/*.ts'",
17+
"release": "cd build && npm publish",
18+
"build": "scripts/build.bash"
1919
},
2020
"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"
21+
"@types/chalk": "^0.4.31",
22+
"@types/fs-extra": "^3.0.3",
23+
"@types/jest": "^20.0.2",
24+
"@types/js-yaml": "^3.5.31",
25+
"@types/node": "^8.0.7",
26+
"@types/uuid": "^3.0.0",
27+
"jest": "^20.0.4",
28+
"serverless": "^1.16.1",
29+
"ts-jest": "^20.0.6",
30+
"ts-node": "^3.1.0",
31+
"tslint": "^5.4.3",
32+
"tslint-config-temando": "^1.1.4",
33+
"typescript": "^2.4.1"
3534
},
3635
"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",
36+
"@jdw/jst": "^1.0.0",
37+
"@types/bluebird": "^3.5.8",
4338
"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"
39+
"chalk": "^2.0.1",
40+
"fs-extra": "^3.0.1",
41+
"js-yaml": "^3.8.4",
42+
"lutils": "^2.4.0",
43+
"swagger2openapi": "^2.5.0",
44+
"uuid": "^3.1.0"
5045
}
5146
}

scripts/build.bash

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

scripts/package.js

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

src/generate.ts renamed to src/DocumentGenerator.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as uuid from 'uuid';
66
import { IParameterConfig, IServerlessFunctionConfig, IServiceDescription } from './types';
77
import { clone, merge } from './utils';
88

9-
export default class DocumentGenerator {
9+
export class DocumentGenerator {
1010
// The OpenAPI version we currently validate against
1111
private openapiVersion = '3.0.0-RC1';
1212

@@ -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
}

0 commit comments

Comments
 (0)