Skip to content

Commit

Permalink
feat(inital commit): the initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SamWSoftware committed Sep 26, 2021
0 parents commit 624e4b4
Show file tree
Hide file tree
Showing 14 changed files with 23,235 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# package directories
node_modules
jspm_packages

# Serverless directories
.serverless
.dynamodb
.serverless

# Webpack directories
.webpack

.serverless
build

.DS_Store

# Compiled Code
dist



4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__tests__
node_modules
src
jest.config.js
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Serverless Auto Swagger

This plugin allows you to automatically generate a swagger endpoint, describing your application endpoints.

## Usage

This plugin is designed to work with vanilla Serverless Framework. All you need to do is add this plugin to your plugin list and it will generate the swagger file and add the endpoints required. Your new swagger UI will be available at `https://{your-url-domain}/swagger`.

### Adding more details

The default swagger file from vanilla Serverless framework will have the correct paths and methods but no details about the data.

#### Adding Data Types

This plugin uses typescript types to generate the data types for the endpoints. By default it pulls the types from `src/types/api-types.d.ts`.

You can then assign these typescript definition to post requests

#### Responses

You can now add responses to each of the http endpoint events. This is an object that contains the response code with some example details:

```js
responses: {
// response with description and response body
200: {
description: 'this went well',
bodyType: 'helloPostResponse',
},

// response with just a description
400: {
description: 'failed Post',
},
// shorthand for just a description
502: 'server error',
}
```

### with Serverless Offline

In the plugin list, you must list serverless-auto-swagger before the serverless-offline plugin. If you don't you won't get the required endpoints added to your local endpoints.
48 changes: 48 additions & 0 deletions __tests__/recursiveFixAnyOf.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { recursiveFixAnyOf } from '../src/index';

describe('test of recursiveFixAnyOf', () => {
test('without AnyOf', () => {
const definition: { [key: string]: Definition } = {
helloPostBody: {
properties: {
hello: {
properties: {
there: {
properties: {
everyone: {
type: 'string',
},
},
required: ['everyone'],
additionalProperties: false,
type: 'object',
},
},
required: ['there'],
additionalProperties: false,
type: 'object',
},
date: {
type: 'number',
},
number: {
type: 'number',
},
people: {
items: {
$ref: '#/components/schema/People',
},
type: 'array',
},
},
required: ['hello', 'date', 'number', 'people'],
additionalProperties: false,
type: 'object',
},
};

const result = recursiveFixAnyOf(definition);

expect(result).toMatchObject(definition);
});
});
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
roots: ['<rootDir>/src'],
testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
};
Loading

0 comments on commit 624e4b4

Please sign in to comment.