Skip to content
This repository was archived by the owner on Dec 10, 2021. It is now read-only.

Commit dd9b28c

Browse files
author
Abilio Henrique
committed
Initial commit
0 parents  commit dd9b28c

16 files changed

+4296
-0
lines changed

Diff for: .editorconfig

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
insert_final_newline = true

Diff for: .gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
/npm-*
3+
/dist
4+
5+
.directory
6+
.DS_STORE*

Diff for: .jestrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"verbose": true,
3+
"transform": { ".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js" },
4+
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
5+
"moduleFileExtensions": [ "ts", "tsx", "js" ],
6+
"testPathIgnorePatterns": [
7+
"/node_modules/",
8+
"./dist"
9+
]
10+
}

Diff for: .node-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6

Diff for: .vscode/launch.json

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
// Use IntelliSense to learn about possible Node.js debug attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"compounds": [
7+
{
8+
"name": "Compound",
9+
"configurations": [
10+
"Project1"
11+
]
12+
}
13+
],
14+
"configurations": [
15+
{
16+
"type": "node",
17+
"request": "attach",
18+
"name": "Attach (Inspector Protocol)",
19+
"port": 9229,
20+
"protocol": "inspector"
21+
},
22+
{
23+
"type": "node",
24+
"request": "launch",
25+
"protocol": "legacy",
26+
"name": "Jest (Legacy)",
27+
"cwd": "${workspaceRoot}",
28+
"stopOnEntry": false,
29+
"runtimeExecutable": null,
30+
"runtimeArgs": [
31+
"--debug-brk",
32+
"${workspaceRoot}/node_modules/.bin/jest",
33+
"-i",
34+
"-c", ".jestrc"
35+
],
36+
"smartStep": true,
37+
"outDir": null,
38+
"sourceMaps": true,
39+
"port": 5858,
40+
"address": "127.0.0.1",
41+
"skipFiles": [
42+
"<node_internals>/**/*.js",
43+
"node_modules/**/*.js"
44+
]
45+
}
46+
]
47+
}

Diff for: .vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"typescript.tsdk": "./node_modules/typescript/lib"
3+
}

Diff for: .vscode/tasks.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"version": "0.1.0",
3+
"command": "tsc",
4+
"isShellCommand": true,
5+
"args": [],
6+
"showOutput": "silent",
7+
"problemMatcher": "$tsc"
8+
}

Diff for: CHANGELOG.md

Whitespace-only changes.

Diff for: README.md

Whitespace-only changes.

Diff for: package.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "serverless-openapi-documentation",
3+
"version": "0.0.0",
4+
"description": "Serverless 1.0 plugin to generate OpenAPI V3 documentation from serverless configuration",
5+
"main": "dist/index.js",
6+
"author": "Abilio Henrique <[email protected]>",
7+
"license": "MIT",
8+
"files": [
9+
"dist"
10+
],
11+
"scripts": {
12+
"test": "jest --config ./.jestrc",
13+
"lint": "eslint src",
14+
"test:watch": "yarn test -- -i --watch",
15+
"release:npm": "cd dist && npm publish",
16+
"docs": "typedoc --out ./dist/docs --target es6 --readme README.md",
17+
"build": "node scripts/package"
18+
},
19+
"devDependencies": {
20+
"@types/node": "^7.0.12",
21+
"eslint": "^3.18.0",
22+
"eslint-config-airbnb-base": "^11.1.2",
23+
"eslint-plugin-import": "^2.2.0",
24+
"jest": "^19.0.2",
25+
"serverless": "^1.9.0",
26+
"ts-jest": "^19.0.6",
27+
"ts-node": "^3.0.2",
28+
"tslint": "^4.5.1",
29+
"tslint-eslint-rules": "^3.5.1",
30+
"typescript": "^2.2.2"
31+
},
32+
"dependencies": {
33+
"@types/bluebird": "^3.5.2",
34+
"@types/fs-promise": "^1.0.1",
35+
"@types/js-yaml": "^3.5.29",
36+
"bluebird": "^3.5.0",
37+
"fs-promise": "^2.0.2",
38+
"js-yaml": "^3.8.2",
39+
"lutils": "^1.2.5"
40+
}
41+
}

Diff for: scripts/package.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* `package` script.
3+
*
4+
* - Builds `./dist` for a `npm publish` by merging
5+
* the project root and files built from `./src`.
6+
*/
7+
8+
const exec = require('shelljs').exec;
9+
10+
exec('rm -rf dist');
11+
exec('mkdir dist');
12+
// exec('cp * dist');
13+
// exec('cp .* dist');
14+
exec('tsc');

Diff for: src/generate.ts

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { merge } from 'lutils';
2+
3+
type ServiceDescriptionType = {
4+
description: string,
5+
version: string,
6+
summary: string,
7+
termsOfService?: string,
8+
contact?: {
9+
name?: string,
10+
email?: string,
11+
url?: string,
12+
},
13+
license?: {
14+
name: string,
15+
url: string,
16+
},
17+
};
18+
19+
export default class DocumentGenerator {
20+
private config: ServiceDescriptionType = {
21+
description: '',
22+
version: '0.0.0',
23+
summary: '',
24+
};
25+
26+
constructor(serviceDescriptor: ServiceDescriptionType) {
27+
merge([this.config, serviceDescriptor], { depth: 32 });
28+
}
29+
30+
public generate() {
31+
return {
32+
openapi: '3.0.0-RC0',
33+
servers: this.getServers(),
34+
info: {
35+
description: this.getDescription(),
36+
version: this.getVersion(),
37+
title: this.getTitle(),
38+
termsOfService: this.getTermsOfService(),
39+
},
40+
tags: this.getTags(),
41+
paths: {},
42+
components: {
43+
schemas: this.getSchemas(),
44+
requestBodies: {},
45+
responses: {},
46+
parameters: {},
47+
examples: {},
48+
securitySchemes: {},
49+
},
50+
};
51+
}
52+
53+
private getDescription() {
54+
return this.config.description;
55+
}
56+
57+
private getSchemas() {
58+
return {};
59+
}
60+
61+
private getServers() {
62+
return [{ url: 'nothing' }];
63+
}
64+
65+
private getTermsOfService() {
66+
return this.config.termsOfService;
67+
}
68+
69+
private getTags() {
70+
return [];
71+
}
72+
73+
private getTitle() {
74+
return this.config.summary;
75+
}
76+
77+
private getVersion() {
78+
return this.config.version;
79+
}
80+
81+
}

Diff for: src/index.ts

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import * as DocumentGenerator from './generate';
2+
3+
class ServerlessOpenAPIDocumentation {
4+
public hooks;
5+
private serverless;
6+
private options;
7+
private provider;
8+
private customVars;
9+
private getMethodLogicalId;
10+
private normalizePath;
11+
12+
constructor(serverless, options) {
13+
this.serverless = serverless;
14+
this.options = options;
15+
this.provider = 'aws';
16+
17+
this.customVars = this.serverless.variables.service.custom;
18+
const naming = this.serverless.providers.aws.naming;
19+
this.getMethodLogicalId = naming.getMethodLogicalId.bind(naming);
20+
this.normalizePath = naming.normalizePath.bind(naming);
21+
22+
this.hooks = {
23+
'before:deploy:deploy': this.beforeDeploy.bind(this),
24+
'after:deploy:deploy': this.afterDeploy.bind(this),
25+
};
26+
}
27+
28+
private beforeDeploy() {
29+
const dg = new DocumentGenerator(this.customVars.documentation);
30+
31+
const funcConfigs = this.serverless.service.getAllFunctions().map((functionName) => {
32+
const func = this.serverless.service.getFunction(functionName);
33+
console.log(func.events);
34+
return func;
35+
});
36+
37+
return Promise.reject(new Error('fuck'));
38+
}
39+
40+
private afterDeploy() {
41+
console.log('bye');
42+
}
43+
}
44+
45+
module.exports = ServerlessOpenAPIDocumentation;

Diff for: tsconfig.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2016",
4+
"module": "commonjs",
5+
"moduleResolution": "node",
6+
"outDir":"./dist",
7+
"inlineSourceMap": true,
8+
"inlineSources": true,
9+
"allowJs": false,
10+
"allowSyntheticDefaultImports": true
11+
},
12+
"exclude": [
13+
"node_modules",
14+
"dist"
15+
],
16+
"include": [
17+
"src/**/*"
18+
]
19+
}

Diff for: tslint.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends":[
3+
"tslint:latest",
4+
"tslint-eslint-rules"
5+
],
6+
"rules": {
7+
"quotemark": ["single"],
8+
"only-arrow-functions": [false],
9+
"curly": false,
10+
"object-curly-spacing": [ true, "always" ],
11+
"space-in-parens": [true, "never"],
12+
"no-multi-spaces": [true],
13+
"object-literal-sort-keys": false
14+
}
15+
}

0 commit comments

Comments
 (0)