Skip to content

Commit

Permalink
feat: add open api support
Browse files Browse the repository at this point in the history
  • Loading branch information
kazimanzurrashid committed Oct 1, 2022
1 parent c329101 commit 6798dbe
Show file tree
Hide file tree
Showing 12 changed files with 355 additions and 10 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ docker-compose.yml
.env
k8s
.husky
gen
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules/
build/
dist/
coverage/
gen/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ coverage/
pkg/
bin/
.env
gen/
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules/
build/
dist/
coverage/
gen/
17 changes: 17 additions & 0 deletions copy-other-required-files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { basename } from 'path';
import { cp } from 'fs';
import copydir from 'copy-dir';

cp('./open-api.json', './dist/open-api.json', (error) => {
if (error) {
throw error;
}
});

copydir('./node_modules/swagger-ui-dist', './dist/', {
filter: (_, filepath) => {
const filename = basename(filepath);

return filename.startsWith('swagger-ui') || filename.startsWith('favicon');
}
});
225 changes: 225 additions & 0 deletions open-api.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
{
"openapi": "3.0.3",
"info": {
"title": "Consents API",
"version": "0.1.0"
},
"paths": {
"/users": {
"post": {
"tags": [
"Users"
],
"summary": "Creates a new user",
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"required": true,
"properties": {
"email": {
"type": "string",
"description": "Unique email address of user",
"required": true
}
}
}
}
},
"required": true
},
"responses": {
"201": {
"description": "Returns newly created user",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/userResponse"
}
}
}
},
"422": {
"description": "When input is not valid",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/errorsResponse"
}
}
}
}
}
}
},
"/users/{id}": {
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
],
"delete": {
"tags": [
"Users"
],
"summary": "Deletes the user",
"responses": {
"204": {
"description": "No content is returned upon success"
},
"404": {
"description": "When user does not exist",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/errorsResponse"
}
}
}
}
}
},
"get": {
"tags": [
"Users"
],
"summary": "Returns the user",
"responses": {
"200": {
"description": "Returns the matching user",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/userResponse"
}
}
}
},
"404": {
"description": "When user does not exist",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/errorsResponse"
}
}
}
}
}
}
},
"/events": {
"post": {
"tags": [
"Events"
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"required": true,
"properties": {
"user": {
"type": "object",
"required": true,
"properties": {
"id": {
"type": "string",
"required": true
}
}
},
"consents": {
"type": "array",
"required": true,
"items": {
"type": "object",
"required": true,
"properties": {
"id": {
"type": "string",
"required": true,
"enum": [
"email_notifications",
"sms_notifications"
]
},
"enabled": {
"type": "boolean",
"required": true
}
}
}
}
}
}
}
}
},
"summary": "Records consents of the given user",
"responses": {
"201": {
"description": "Returns nothing upon success"
},
"422": {
"description": "When input is not valid",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/errorsResponse"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"errorsResponse": {
"type": "object",
"properties": {
"errors": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"userResponse": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"email": {
"type": "string"
},
"consents": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"enabled": {
"type": "boolean"
}
}
}
}
}
}
}
}
}
67 changes: 67 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6798dbe

Please sign in to comment.