Commit 5f6baad1 authored by Eric Eastwood's avatar Eric Eastwood

Add user and snippets route

parent bab3d230
Pipeline #6118408 failed
......@@ -2,3 +2,4 @@ node_modules/
npm-debug.log
dist/
data/
......@@ -25,7 +25,7 @@ See `routes.yml` ([Swagger](http://swagger.io/specification/) document)
### Initial mock data
See `data.json` (Array of [Resource objects](https://github.com/BigstickCarpet/swagger-express-middleware/blob/master/docs/samples/walkthrough2.md#pre-populated-data))
See `initial-data.json` (Array of [Resource objects](https://github.com/BigstickCarpet/swagger-express-middleware/blob/master/docs/samples/walkthrough2.md#pre-populated-data))
## Testing
......
......@@ -2,18 +2,18 @@ const Promise = require('bluebird');
const express = require('express');
const cors = require('cors');
const middleware = Promise.promisify(require('swagger-express-middleware'));
const MemoryDataStore = require('swagger-express-middleware/lib/data-store/memory-data-store');
const FileDataStore = require('swagger-express-middleware/lib/data-store/file-data-store');
const Resource = require('swagger-express-middleware/lib/data-store/resource');
const spectacle = require('spectacle-docs');
const data = require('./data.json');
const initialData = require('./initial-data.json');
const routesFilePath = './routes.yml';
const app = express();
app.use(cors());
const myDB = new MemoryDataStore();
myDB.save(Resource.parse(data));
const myDB = new FileDataStore('./data/');
myDB.save(Resource.parse(initialData));
console.log('Starting app...');
......
......@@ -5,11 +5,39 @@ info:
description: API mocks for use with GitLab
consumes:
- application/x-www-form-urlencoded
- application/json
produces:
- application/json
definitions:
user:
required:
- id
- username
properties:
id:
type: string
minLength: 16
pattern: "^[a-zA-Z0-9]+$"
username:
type: string
minLength: 4
pattern: "^[a-zA-Z0-9- ]+$"
snippet:
required:
- id
- name
- text
properties:
id:
type: string
name:
type: string
text:
type: string
pet:
required:
- name
......@@ -46,6 +74,12 @@ definitions:
parameters:
userId:
name: userId
in: path
description: User ID
required: true
type: string
petName:
name: petName
in: path
......@@ -56,6 +90,112 @@ parameters:
paths:
/users:
post:
description: Creates a new user in the store
operationId: addUser
parameters:
- name: user
in: body
description: The user to add to the store
required: true
schema:
$ref: "#/definitions/user"
responses:
201:
description: Returns the newly-added user
schema:
$ref: "#/definitions/user"
headers:
Location:
type: string
description: The URL of the newly-added user
/users/{userId}:
parameters:
- $ref: "#/parameters/userId"
get:
description: Returns a user by user ID
operationId: findUserByUserId
responses:
default:
description: Returns the user
schema:
$ref: "#/definitions/user"
patch:
description: Updates a user by user ID
parameters:
- name: user
in: body
description: The updated user info
required: true
schema:
$ref: "#/definitions/user"
responses:
default:
description: Returns the updated user data
schema:
$ref: "#/definitions/user"
/users/{userId}/snippets:
parameters:
- $ref: "#/parameters/userId"
post:
description: Creates a new snippet in the store
operationId: addSnippetUnderUser
parameters:
- name: snippet
in: body
description: The snippet to add to the store
required: true
schema:
$ref: "#/definitions/snippet"
responses:
201:
description: Returns the newly-added snippet
schema:
$ref: "#/definitions/snippet"
headers:
Location:
type: string
description: The URL of the newly-added snippet
/users/{userId}/snippets/{id}:
parameters:
- $ref: "#/parameters/userId"
- name: id
in: path
description: The ID of the snippet
required: true
type: string
get:
description: Returns a snippet by ID
operationId: findSnippetUnderUserById
responses:
default:
description: Returns the snippet
schema:
$ref: "#/definitions/snippet"
patch:
description: Updates a snippet by ID
parameters:
- name: snippet
in: body
description: The updated snippet info
required: true
schema:
$ref: "#/definitions/snippet"
responses:
default:
description: Returns the updated snippet data
schema:
$ref: "#/definitions/snippet"
/pets:
get:
......@@ -88,41 +228,11 @@ paths:
required: false
type: string
format: date
- name: address.city
in: query
description: Filters pets by city
required: false
type: string
- name: address.state
in: query
description: Filters pets by state
required: false
type: string
- name: address.zipcode
in: query
description: Filters pets by zip code
required: false
type: integer
- name: vet.name
in: query
description: Filters pets by veterinarian name
required: false
type: string
- name: vet.address.city
in: query
description: Filters pets by veterinarian city
required: false
type: string
- name: vet.address.state
in: query
description: Filters pets by veterinarian state
required: false
type: string
- name: vet.address.zipcode
in: query
description: Filters pets by veterinarian zip code
required: false
type: integer
responses:
default:
description: Returns the matching pets
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment