Small details

This commit is contained in:
fkereki
2018-06-05 00:17:02 -04:00
parent b2a06951c7
commit 51273628b8
4 changed files with 368 additions and 163 deletions
-138
View File
@@ -1,138 +0,0 @@
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Swagger Petstore",
"license": {
"name": "MIT"
}
},
"host": "petstore.swagger.io",
"basePath": "/v1",
"schemes": ["http"],
"consumes": ["application/json"],
"produces": ["application/json"],
"paths": {
"/pets": {
"get": {
"summary": "List all pets",
"operationId": "listPets",
"tags": ["pets"],
"parameters": [
{
"name": "limit",
"in": "query",
"description":
"How many items to return at one time (max 100)",
"required": false,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "An paged array of pets",
"headers": {
"x-next": {
"type": "string",
"description":
"A link to the next page of responses"
}
},
"schema": {
"$ref": "#/definitions/Pets"
}
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"post": {
"summary": "Create a pet",
"operationId": "createPets",
"tags": ["pets"],
"responses": {
"201": {
"description": "Null response"
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
},
"/pets/{petId}": {
"get": {
"summary": "Info for a specific pet",
"operationId": "showPetById",
"tags": ["pets"],
"parameters": [
{
"name": "petId",
"in": "path",
"required": true,
"description": "The id of the pet to retrieve",
"type": "string"
}
],
"responses": {
"200": {
"description":
"Expected response to a valid request",
"schema": {
"$ref": "#/definitions/Pets"
}
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
}
},
"definitions": {
"Pet": {
"required": ["id", "name"],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"tag": {
"type": "string"
}
}
},
"Pets": {
"type": "array",
"items": {
"$ref": "#/definitions/Pet"
}
},
"Error": {
"required": ["code", "message"],
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
}
}
}
}
}
+1 -1
View File
@@ -7,7 +7,7 @@ const app = express();
const bodyParser = require("body-parser");
const cors = require("cors");
const swaggerUi = require("swagger-ui-express");
const swaggerDocument = require("../restful.json");
const swaggerDocument = require("../swagger.json");
const dbConn = require("./restful_db.js");
const validateUser = require("./validate_user.js");
+334
View File
@@ -0,0 +1,334 @@
{
"swagger": "2.0",
"info": {
"description": "This is a RESTful API to access world data, including countries, regions, and cities.",
"version": "1.0.0",
"title": "World Data API"
},
"host": "127.0.0.1:8443",
"schemes": [
"http"
],
"tags": [
{
"name": "token",
"description": "Get a JWT for authorization"
},
{
"name": "countries",
"description": "Access the world countries"
},
{
"name": "regions",
"description": "Access the regions of countries"
},
{
"name": "cities",
"description": "Access the world cities"
}
],
"paths": {
"/gettoken": {
"post": {
"tags": [
"token"
],
"summary": "Get a token to authorize future requests",
"consumes": [
"application/x-www-form-urlencoded"
],
"produces": [
"text/plain"
],
"parameters": [
{
"in": "formData",
"name": "user",
"required": true,
"type": "string"
},
{
"in": "formData",
"name": "password",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "A valid token to use for other requests"
},
"401": {
"description": "No token provided"
},
"404": {
"description": "Country not found"
}
}
}
},
"/regions": {
"get": {
"tags": [
"regions"
],
"summary": "Get all regions of all countries",
"produces": [
"application/json"
],
"parameters": [
{
"in": "header",
"name": "Authorization",
"required": true,
"type": "string",
"description": "Authorization Token"
}
],
"responses": {
"200": {
"description": "OK"
},
"401": {
"description": "No token provided"
}
}
},
"post": {
"tags": [
"regions"
],
"summary": "Add a region to a given country",
"consumes": [
"application/x-www-form-urlencoded"
],
"produces": [
"text/plain"
],
"parameters": [
{
"in": "formData",
"name": "name",
"required": true,
"type": "string",
"description": "The new region's name."
},
{
"in": "header",
"name": "Authorization",
"required": true,
"type": "string",
"description": "Authorization Token"
},
{
"in": "header",
"name": "Authorization",
"required": true,
"type": "string",
"description": "Authorization Token"
}
],
"responses": {
"201": {
"description": "OK, created"
},
"400": {
"description": "Name missing, region not created"
},
"401": {
"description": "No token provided"
},
"403": {
"description": "Country not found, region not created"
},
"409": {
"description": "Other failure, region not created"
}
}
}
},
"/regions/{country}": {
"get": {
"tags": [
"regions"
],
"summary": "Get all regions of a given country",
"produces": [
"application/json"
],
"parameters": [
{
"name": "country",
"in": "path",
"description": "Country (id) whose regions are required",
"type": "string",
"required": true
},
{
"in": "header",
"name": "Authorization",
"required": true,
"type": "string",
"description": "Authorization Token"
}
],
"responses": {
"200": {
"description": "OK"
},
"401": {
"description": "No token provided"
},
"404": {
"description": "Country not found"
}
}
}
},
"/regions/{country}/{id}": {
"get": {
"tags": [
"regions"
],
"summary": "Get a specific region of a given country",
"produces": [
"application/json"
],
"parameters": [
{
"name": "country",
"in": "path",
"description": "Country (id) of the region",
"type": "string",
"required": true
},
{
"name": "id",
"in": "path",
"description": "Region (id) that is required",
"type": "string",
"required": true
},
{
"in": "header",
"name": "Authorization",
"required": true,
"type": "string",
"description": "Authorization Token"
}
],
"responses": {
"200": {
"description": "OK"
},
"401": {
"description": "No token provided"
},
"404": {
"description": "Country not found"
}
}
},
"delete": {
"tags": [
"regions"
],
"summary": "Delete a specific region of a given country",
"description": "",
"parameters": [
{
"name": "country",
"in": "path",
"description": "Country (id) of the region",
"type": "string",
"required": true
},
{
"name": "id",
"in": "path",
"description": "Region (id) that is to be deleted",
"type": "string",
"required": true
},
{
"in": "header",
"name": "Authorization",
"required": true,
"type": "string",
"description": "Authorization Token"
}
],
"responses": {
"204": {
"description": "OK, region was deleted"
},
"401": {
"description": "No token provided"
},
"404": {
"description": "Region does not exist"
},
"405": {
"description": "Region has cities, cannot be deleted"
}
}
},
"put": {
"tags": [
"regions"
],
"summary": "Update a specific region of a given country",
"consumes": [
"application/x-www-form-urlencoded"
],
"produces": [
"text/plain"
],
"parameters": [
{
"name": "country",
"in": "path",
"description": "Country (id) of the region",
"type": "string",
"required": true
},
{
"name": "id",
"in": "path",
"description": "Region (id) that is to be deleted",
"type": "string",
"required": true
},
{
"in": "formData",
"name": "name",
"required": true,
"type": "string",
"description": "The region's new name."
},
{
"in": "header",
"name": "Authorization",
"required": true,
"type": "string",
"description": "Authorization Token"
}
],
"responses": {
"204": {
"description": "OK, region was updated"
},
"400": {
"description": "Name missing, region not updated"
},
"401": {
"description": "No token provided"
},
"404": {
"description": "Country not found"
}
}
}
}
}
}
+33 -24
View File
@@ -1,10 +1,13 @@
openapi: "2.0.0"
swagger: "2.0"
info:
description: "This is a RESTful API to access world data, including countries, regions, and cities."
version: "1.0.0"
title: "World Data API"
host: "localhost:8443"
host: "127.0.0.1:8443"
schemes:
- "http"
tags:
- name: "token"
description: "Get a JWT for authorization"
@@ -14,8 +17,7 @@ tags:
description: "Access the regions of countries"
- name: "cities"
description: "Access the world cities"
schemes:
- "http"
paths:
/gettoken:
@@ -32,19 +34,15 @@ paths:
name: user
required: true
type: string
description: A person's name.
- in: formData
name: password
required: true
type: string
description: A person's favorite number.
responses:
200:
description: A valid token to use for other requests
401:
description: "No token provided"
404:
description: "Country not found"
/regions:
get:
@@ -53,6 +51,12 @@ paths:
summary: "Get all regions of all countries"
produces:
- application/json
parameters:
- in: header
name: "Authorization"
required: true
type: string
description: Authorization Token
responses:
200:
description: "OK"
@@ -74,7 +78,7 @@ paths:
type: string
description: The new region's name.
- in: header
name: "Authorization: Bearer"
name: "Authorization"
required: true
type: string
description: Authorization Token
@@ -103,6 +107,11 @@ paths:
description: "Country (id) whose regions are required"
type: string
required: true
- in: header
name: "Authorization"
required: true
type: string
description: Authorization Token
responses:
200:
description: "OK"
@@ -130,6 +139,11 @@ paths:
description: "Region (id) that is required"
type: string
required: true
- in: header
name: "Authorization"
required: true
type: string
description: Authorization Token
responses:
200:
description: "OK"
@@ -154,6 +168,11 @@ paths:
description: "Region (id) that is to be deleted"
type: string
required: true
- in: header
name: "Authorization"
required: true
type: string
description: Authorization Token
responses:
204:
description: "OK, region was deleted"
@@ -188,6 +207,11 @@ paths:
required: true
type: string
description: The region's new name.
- in: header
name: "Authorization"
required: true
type: string
description: Authorization Token
responses:
204:
description: "OK, region was updated"
@@ -197,18 +221,3 @@ paths:
description: "No token provided"
404:
description: "Country not found"
components:
securitySchemes:
JwtAuth:
type: apiKey
in: header
name: Authorization
bearerAuth: # arbitrary name for the security scheme
type: apiKey
in: header
scheme: bearer
bearerFormat: JWT