Skip to content
Snippets Groups Projects
Commit 19addeb7 authored by Eric Eastwood's avatar Eric Eastwood
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
node_modules/
[
{
"collection": "/pets",
"name": "/Lassie",
"data": {
"name": "Lassie",
"type": "dog"
}
},
{
"collection": "/pets",
"name": "/Clifford",
"data": {
"name": "Clifford",
"type": "dog"
}
},
{
"collection": "/pets",
"name": "/Garfield",
"data": {
"name": "Garfield",
"type": "cat"
}
},
{
"collection": "/pets",
"name": "/Snoopy",
"data": {
"name": "Snoopy",
"type": "dog"
}
},
{
"collection": "/pets",
"name": "/Hello%20Kitty",
"data": {
"name": "Hello Kitty",
"type": "cat"
}
}
]
<!doctype html>
<html>
<head>
<title>
API Lab
</title>
</head>
<body>
<h1>
API Lab
</h1>
</body>
</html>
index.js 0 → 100644
var express = require('express');
var middleware = require('swagger-express-middleware');
var MemoryDataStore = require('swagger-express-middleware/lib/data-store/memory-data-store');
var Resource = require('swagger-express-middleware/lib/data-store/resource');
var data = require('./data.json');
var app = express();
var myDB = new MemoryDataStore();
myDB.save(Resource.parse(data));
/* */
middleware('routes.yaml', app, function(err, middleware) {
// Add all the Swagger Express Middleware, or just the ones you need.
// NOTE: Some of these accept optional options (omitted here for brevity)
app.use(
middleware.metadata(),
middleware.CORS(),
middleware.files(),
middleware.parseRequest(),
middleware.validateRequest(),
middleware.mock(myDB)
);
app.listen(8001, function() {
console.log('The PetStore sample is now running at http://localhost:8000');
});
});
/* */
/* * /
let Swagmock = require('swagmock');
//let Mockgen = Swagmock('routes.yaml', {});
let Mockgen = Swagmock('routes2.json', {});
app.use('*', function(req, res) {
Mockgen
.responses({
path: req.path,
operation: req.method.toLowerCase(),
response: 200
})
.then(mock => {
console.log('mock', mock);
res.send(mock);
return mock;
})
.catch(error => {
res.status(500).send(error);
});
});
app.listen(8000, function() {
console.log('The PetStore sample is now running at http://localhost:8000');
});
/* */
{
"name": "apilab",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+ssh://git@gitlab.com/gitlab-org/apilab.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://gitlab.com/gitlab-org/apilab/issues"
},
"homepage": "https://gitlab.com/gitlab-org/apilab#README",
"dependencies": {
"express": "^4.14.0",
"swagger-express-middleware": "^1.0.0-alpha.12",
"swagmock": "^1.0.0"
}
}
swagger: "2.0"
info:
version: 1.0.0
title: Swagger petstore
description: A sample API that demonstrates Swagger-Express-Middleware features
consumes:
- application/json
produces:
- application/json
definitions:
pet:
required:
- name
- type
properties:
name:
type: string
minLength: 4
pattern: "^[a-zA-Z0-9- ]+$"
age:
type: integer
dob:
type: string
format: 'date'
type:
type: string
enum: [cat, dog, bird]
address:
$ref: "#/definitions/address"
vet:
$ref: "#/definitions/veterinarian"
tags:
type: array
uniqueItems: true
items:
type: string
minLength: 1
veterinarian:
required:
- name
properties:
name:
type: string
minLength: 1
address:
$ref: "#/definitions/address"
address:
properties:
street:
type: string
minLength: 1
city:
type: string
minLength: 1
state:
type: string
minLength: 2
maxLength: 2
pattern: "^[A-Z]+$"
zipcode:
type: integer
minimum: 10000
maximum: 99999
parameters:
petName:
name: petName
in: path
description: Name of the pet
required: true
type: string
paths:
/pets:
get:
description: Returns all pets, optionally filtered by one or more criteria
operationId: findPets
parameters: &petFilters
- name: tags
in: query
description: Filters pets by one or more tags
required: false
type: array
items:
type: string
uniqueItems: true
collectionFormat: csv
- name: type
in: query
description: Filters pets by type (dog, cat, or bird)
required: false
type: string
enum: [cat, dog, bird]
- name: age
in: query
description: Filters pets by age
required: false
type: integer
- name: dob
in: query
description: Filters pets by date of birth
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
schema:
type: array
items:
$ref: "#/definitions/pet"
headers:
last-modified:
type: string
description: The date/time that a pet was last modified
delete:
description: Deletes all pets, optionally filtered by one or more criteria
operationId: deletePets
parameters: *petFilters
responses:
default:
description: Returns the pets that were deleted
schema:
type: array
items:
$ref: "#/definitions/pet"
post:
description: Creates a new pet in the store
operationId: addPet
parameters:
- name: pet
in: body
description: The pet to add to the store
required: true
schema:
$ref: "#/definitions/pet"
responses:
201:
description: Returns the newly-added pet
schema:
$ref: "#/definitions/pet"
headers:
Location:
type: string
description: The URL of the newly-added pet
/pets/{petName}:
parameters:
- $ref: "#/parameters/petName"
get:
description: Returns a pet by name
operationId: findPetByName
responses:
default:
description: Returns the pet data
schema:
$ref: "#/definitions/pet"
headers:
last-modified:
type: string
description: The date/time that the pet was last modified
delete:
description: Deletes a single pet based on the name supplied
operationId: deletePet
responses:
default:
description: Returns the pet that was deleted
schema:
$ref: "#/definitions/pet"
patch:
description: Updates a pet by name
parameters:
- name: pet
in: body
description: The updated pet info
required: true
schema:
$ref: "#/definitions/pet"
responses:
default:
description: Returns the updated pet data
schema:
$ref: "#/definitions/pet"
/pets/{petName}/photos:
parameters:
- $ref: "#/parameters/petName"
post:
description: Upload a new pet photo
operationId: addPetPhoto
consumes:
- multipart/form-data
parameters:
- name: id
in: formData
description: The photo ID (generated automatically)
type: integer
format: int32
minimum: 1
- name: label
in: formData
description: A label for the photo
required: true
type: string
minLength: 1
- name: description
in: formData
description: An optional description of the photo
type: string
- name: photo
in: formData
description: The pet photo
required: true
type: file
minLength: 1
maxLength: 5000000 # ~5MB
responses:
default:
description: Returns the photo information
schema:
properties:
id:
type: integer
format: int32
description: The auto-generated photo ID
label:
type: string
description:
type: string
photo:
type: object
description: Information about the photo (size, file name, etc.)
headers:
Location:
type: string
description: The URL of the newly-added photo
get:
description: Get a list of the photos for a pet
responses:
200:
description: Returns the list of photos
schema:
type: array
items:
properties:
id:
type: integer
format: int32
description: The auto-generated photo ID
label:
type: string
description:
type: string
photo:
type: object
description: Information about the photo (size, file name, etc.)
/pets/{petName}/photos/{id}:
parameters:
- $ref: "#/parameters/petName"
- name: id
in: path
description: The ID of the photo
required: true
type: integer
format: int32
get:
description: Gets a pet photo
operationId: getPetPhoto
produces:
- image/jpeg
- image/gif
- image/png
- image/bmp
responses:
default:
description: Returns the pet photo
schema:
type: file
delete:
description: Deletes a pet photo
operationId: deletePetPhoto
responses:
default:
description: The photo was deleted successfully
/:
get:
produces:
- text/html
responses:
default:
description: The Swagger Pet Store homepage :)
schema:
type: file
default:
$ref: "index.html"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment