temp fix to get things working on oav.azurewebsites.net

This commit is contained in:
amarzavery 2017-04-20 08:50:31 -07:00
Родитель c66cb7398f
Коммит 3c90aeaf7b
2 изменённых файлов: 307 добавлений и 5 удалений

Просмотреть файл

@ -12,15 +12,13 @@ const express = require('express');
const bodyParser = require('body-parser');
const multer = require('multer');
var swaggerSpec = require('./openapi/oav-express.json');
var swaggerSpecDevelopment = require('./openapi/oav-express.json');
var swaggerSpecProduction = require('./openapi/oav-express-production.json');
const ErrorCodes = oav.Constants.ErrorCodes;
const port = process.env.PORT || 1337;
const app = express();
var server;
if (process.env['NODE_ENV'] === 'production') {
swaggerSpec.info.host = 'oav.azurewebsites.net';
}
// LiveValidator configuration options
const liveValidatorOptions = {
git: {
@ -47,7 +45,15 @@ app.get('/', (req, res) => {
// serve swagger
app.get('/swagger.json', function (req, res) {
res.setHeader('Content-Type', 'application/json');
res.send(swaggerSpec);
let host;
if (server && server.address() && server.address().address) {
host = server.address().address;
}
if (host && (host === '::' || host === 'localhost')) {
res.send(swaggerSpecDevelopment);
} else {
res.send(swaggerSpecProduction);
}
});
// This responds a POST request for live validation

Просмотреть файл

@ -0,0 +1,296 @@
{
"swagger": "2.0",
"info": {
"version": "1.0",
"title": "LiveRequestValidationClient",
"description": "Live request validation client"
},
"host": "oav.azurewebsites.net",
"schemes": [
"http",
"https"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/validate": {
"post": {
"operationId": "Oav_ValidateRequestResponse",
"description": "Validates the request and response against the operatswagger specification",
"parameters": [
{
"name": "requestResponse",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/RequestResponse"
},
"description": "The request and corresponding response to validate."
}
],
"responses": {
"200": {
"description": "Describes the validation result of the live request and response.",
"schema": {
"$ref": "#/definitions/ValidationResult"
}
},
"default": {
"description": "Describes the error response for negative scenarios. Currently we return the same schema as 200. The errors array will not be empty.",
"schema": {
"$ref": "#/definitions/ValidationResult"
}
}
}
}
}
},
"definitions": {
"RequestResponse": {
"properties": {
"liveRequest": {
"description": "Schema for the live request to be validated",
"$ref": "#/definitions/LiveRequest"
},
"liveResponse": {
"description": "Schema for the live response to be validated",
"$ref": "#/definitions/LiveResponse"
}
},
"required": [
"liveRequest",
"liveResponse"
],
"description": "Describes the live request and response to be validated."
},
"LiveRequest": {
"properties": {
"headers": {
"description": "Headers of the request.",
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"method": {
"description": "Http verb of the request.",
"type": "string",
"enum": [
"GET",
"PUT",
"PATCH",
"POST",
"DELETE",
"HEAD",
"OPTIONS",
"TRACE"
]
},
"url": {
"description": "Url of the request.",
"type": "string"
},
"body": {
"description": "Parsed body of the request as a JSON.",
"type": "object"
}
},
"required": [
"headers",
"method",
"url"
],
"description": "Properties of the request."
},
"LiveResponse": {
"properties": {
"statusCode": {
"description": "The Response status code.",
"type": "string"
},
"headers": {
"description": "Headers of the response.",
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"body": {
"description": "Body of the response.",
"type": "object"
},
"encoding": {
"description": "The encoding of the response body when the body is a buffer.",
"type": "string"
}
},
"required": [
"statusCode",
"headers"
],
"description": "Properties of the response."
},
"OperationInfo": {
"description": "Describes the operation against which the live request and response validation happened.",
"type": "object",
"required": [
"operationId",
"apiVersion"
],
"properties": {
"operationId": {
"type": "string",
"description": "The id of the operation against which validation happened. This will help find the problematic information in the spec and will be useful in preparing report."
},
"apiVersion": {
"type": "string",
"description": "Describes the api-version of the openapi specification. This will help find the openapi spec corresponding to that api-version and will be useful in preparing report."
}
}
},
"ValidationResult": {
"description": "Describes the validation result of the live request, response validation.",
"type": "object",
"properties": {
"requestValidationResult": {
"description": "Describes the validation result of the live request.",
"$ref": "#/definitions/RequestValidationResult",
"readOnly": true
},
"responseValidationResult": {
"description": "Describes the validation result of the live response.",
"$ref": "#/definitions/ResponseValidationResult",
"readOnly": true
},
"errors": {
"description": "Provides more information about validation for scenarios where no potential operation was found or multiple operations were found or the input was invalid.",
"type": "array",
"readOnly": true,
"items": {
"$ref": "#/definitions/ErrorWrapper"
}
}
}
},
"RequestValidationResult": {
"description": "Describes the validation result of the live request.",
"properties": {
"successfulRequest": {
"readOnly": true,
"type": "boolean",
"description": "Describes the status of live request validation."
},
"operationInfo": {
"readOnly": true,
"description": "The corresponding operation(s) in openapi spec that was used for validating the request.",
"type": "array",
"items": {
"$ref": "#/definitions/OperationInfo"
}
},
"errors": {
"readOnly": true,
"description": "Provides more information about live response validation.",
"type": "array",
"items": {
"$ref": "#/definitions/ErrorWrapper"
}
}
}
},
"ResponseValidationResult": {
"description": "Describes the validation result of the live response.",
"properties": {
"successfulResponse": {
"type": "boolean",
"readOnly": true,
"description": "Describes the status of live response validation."
},
"operationInfo": {
"readOnly": true,
"description": "The corresponding operation(s) in openapi spec that was used for validating the response.",
"type": "array",
"items": {
"$ref": "#/definitions/OperationInfo"
}
},
"errors": {
"readOnly": true,
"description": "Provides more information about live response validation.",
"type": "array",
"items": {
"$ref": "#/definitions/ErrorWrapper"
}
}
}
},
"LiveValidationError": {
"description": "Describes the error occurred while performing validation on live request/response.",
"type": "object",
"required": [
"code",
"message"
],
"properties": {
"code": {
"description": "The unique error code describing an error.",
"type": "string"
},
"message": {
"description": "The error message providing meaningful information.",
"type": "string"
}
}
},
"ErrorResponse": {
"description": "Describes the error response for negative scenarios.",
"type": "object",
"properties": {
"description": {
"description": "Description of the model property or the parameter in the swagger spec that causes validation failure.",
"type": "string"
},
"params": {
"description": "The parameters used when validation failed (z-schema construct).",
"type": "array",
"items": {
"type": "string"
}
},
"path": {
"description": "The path to the location in the document or the model where the error/warning occurred.",
"type": "array",
"items": {
"type": "string"
}
}
},
"allOf": [
{
"$ref": "#/definitions/LiveValidationError"
}
]
},
"ErrorWrapper": {
"description": "Wrapper object",
"properties": {
"errors": {
"description": "An array of inner errors.",
"type": "array",
"items": {
"$ref": "#/definitions/ErrorResponse"
}
}
},
"allOf": [
{
"$ref": "#/definitions/ErrorResponse"
}
]
}
}
}