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

Add linting and docs

parent 19addeb7
No related branches found
No related tags found
No related merge requests found
Pipeline #
node_modules/
npm-debug.log
dist/
lint:
script:
- npm run lint
const gulp = require('gulp');
const SwaggerParser = require('swagger-parser');
gulp.task('lint-routes', () => {
return SwaggerParser.validate('./routes.yml');
});
gulp.task('lint', gulp.series(
'lint-routes'
));
gulp.task('default', gulp.series(
'lint'
));
<!doctype html>
<html>
<head>
<title>
API Lab
</title>
</head>
<body>
<h1>
API Lab
</h1>
</body>
</html>
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');
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 Resource = require('swagger-express-middleware/lib/data-store/resource');
const spectacle = require('spectacle-docs');
 
var app = express();
const data = require('./data.json');
const routesFilePath = './routes.yml';
 
const app = express();
app.use(cors());
 
var myDB = new MemoryDataStore();
const 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)
);
console.log('Starting app...');
 
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
Promise.all([
middleware(routesFilePath, app),
spectacle({
silent: true,
specFile: routesFilePath,
targetFile: 'index.html',
targetDir: 'dist'
})
.then(mock => {
console.log('mock', mock);
res.send(mock);
return mock;
})
.catch(error => {
res.status(500).send(error);
])
.then(([ middleware ]) => {
app.use(express.static('dist'));
app.get('/routes.yml', (req, res) => {
res.sendFile(routesFilePath, { root: './' });
});
});
 
app.listen(8000, function() {
console.log('The PetStore sample is now running at http://localhost:8000');
});
/* */
app.use(
middleware.metadata(),
middleware.CORS(),
middleware.files(),
middleware.parseRequest(),
middleware.validateRequest(),
middleware.mock(myDB)
);
})
.catch((err) => {
console.log('Error', err, err.stack);
app.get('*', (req, res) => {
res.status(500).send({
error: err.message,
stack: err.stack
});
});
})
.then(() => {
app.listen(8000, function() {
console.log('API Lab is now running at http://localhost:8000');
});
})
Loading
Loading
@@ -5,6 +5,7 @@
"main": "index.js",
"scripts": {
"start": "node index.js",
"lint": "gulp lint",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
Loading
Loading
@@ -18,8 +19,15 @@
},
"homepage": "https://gitlab.com/gitlab-org/apilab#README",
"dependencies": {
"bluebird": "^3.4.7",
"cors": "^2.8.1",
"express": "^4.14.0",
"spectacle-docs": "^0.6.9",
"swagger-express-middleware": "^1.0.0-alpha.12",
"swagmock": "^1.0.0"
},
"devDependencies": {
"gulp": "gulpjs/gulp#4.0",
"swagger-parser": "^3.4.1"
}
}
swagger: "2.0"
info:
version: 1.0.0
title: Swagger petstore
description: A sample API that demonstrates Swagger-Express-Middleware features
title: Swagger API Lab
description: API mocks for use with GitLab
 
consumes:
- application/json
Loading
Loading
@@ -27,8 +27,6 @@ definitions:
type:
type: string
enum: [cat, dog, bird]
address:
$ref: "#/definitions/address"
vet:
$ref: "#/definitions/veterinarian"
tags:
Loading
Loading
@@ -45,26 +43,7 @@ definitions:
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:
Loading
Loading
@@ -74,7 +53,10 @@ parameters:
required: true
type: string
 
paths:
/pets:
get:
description: Returns all pets, optionally filtered by one or more criteria
Loading
Loading
@@ -225,121 +207,3 @@ paths:
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