out with the old

This commit is contained in:
Ron
2017-03-17 20:34:15 -07:00
parent ccf7f03dab
commit bd8344c808
189 changed files with 0 additions and 49048 deletions

View File

@@ -1,10 +0,0 @@
{
"extends": "../.jshintrc",
"expr": true,
"jasmine": true,
"globals": {
"before": false,
"after": false,
"expect": true
}
}

View File

@@ -1,10 +0,0 @@
/*
* Web driver manager
*/
'use strict';
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.firefox()).build();
module.exports = driver;

View File

@@ -1,10 +0,0 @@
'use strict';
var path = require('path');
var SPEC_FILE_EXT = '.json';
module.exports.parseSpecFilename = function (name) {
var filename = path.parse(name);
var foldername = filename.dir.split(path.sep).splice(-1)[0];
return [path.sep, foldername, path.sep, filename.name, SPEC_FILE_EXT].join('');
};

View File

@@ -1,42 +0,0 @@
/*
* Swagger UI and Specs Servers
*/
'use strict';
var path = require('path');
var createServer = require('http-server').createServer;
var dist = path.join(__dirname, '..', '..', 'dist');
var specs = path.join(__dirname, '..', '..', 'test', 'specs');
var DOCS_PORT = 8080;
var SPEC_SERVER_PORT = 8081;
var driver = require('./driver');
var swaggerUI;
var specServer;
module.exports.start = function (specsLocation, done) {
swaggerUI = createServer({ root: dist, cors: true });
specServer = createServer({ root: specs, cors: true });
swaggerUI.listen(DOCS_PORT);
specServer.listen(SPEC_SERVER_PORT);
var swaggerSpecLocation = encodeURIComponent('http://localhost:' + SPEC_SERVER_PORT + specsLocation);
var url = 'http://localhost:' + DOCS_PORT + '/index.html?url=' + swaggerSpecLocation;
setTimeout(function(){
driver.get(url);
setTimeout(function() {
done();
}, 2000);
console.log('waiting for UI to load');
}, process.env.TRAVIS ? 20000 : 5000);
console.log('waiting for server to start');
};
module.exports.close = function() {
swaggerUI.close();
specServer.close();
};

View File

@@ -1,103 +0,0 @@
'use strict';
var expect = require('chai').expect;
var driver = require('./driver');
var servers = require('./servers');
var webdriver = require('selenium-webdriver');
var until = webdriver.until;
var elements = [
'swagger-ui-container',
'resources_container',
'api_info',
'resource_pet',
'resource_store',
'resource_user',
'header'
];
describe('swagger 1.x spec tests', function () {
this.timeout(10 * 1000);
before(function (done) {
this.timeout(25 * 1000);
servers.start('/v1.2/petstore/api-docs.json', done);
});
afterEach(function(){
it('should not have any console errors', function (done) {
driver.manage().logs().get('browser').then(function(browserLogs) {
var errors = [];
browserLogs.forEach(function(log){
// 900 and above is "error" level. Console should not have any errors
if (log.level.value > 900) {
console.log('browser error message:', log.message); errors.push(log);
}
});
expect(errors).to.be.empty;
done();
});
});
});
it('should have "Swagger UI" in title', function () {
return driver.wait(until.titleIs('Swagger UI'), 1000);
});
elements.forEach(function (id) {
it('should render element: ' + id, function (done) {
var locator = webdriver.By.id(id);
driver.isElementPresent(locator).then(function (isPresent) {
expect(isPresent).to.be.true;
done();
});
});
});
// TODO: enable me
xit('should find the contact name element', function(done){
var locator = webdriver.By.css('.info_name');
driver.isElementPresent(locator).then(function (isPresent) {
expect(isPresent).to.be.true;
done();
});
});
it('should find the pet link', function(done){
var locator = webdriver.By.xpath('//*[@data-id="pet"]');
driver.isElementPresent(locator).then(function (isPresent) {
expect(isPresent).to.be.true;
done();
});
});
// TODO: enable me
xit('should find the pet resource description', function(done){
var locator = webdriver.By.xpath('//div[contains(., "Operations about pets")]');
driver.findElements(locator).then(function (elements) {
expect(elements.length).to.not.equal(0);
done();
});
});
it('should find the user link', function(done){
var locator = webdriver.By.xpath('//*[@data-id="user"]');
driver.isElementPresent(locator).then(function (isPresent) {
expect(isPresent).to.be.true;
done();
});
});
it('should find the store link', function(done){
var locator = webdriver.By.xpath('//*[@data-id="store"]');
driver.isElementPresent(locator).then(function (isPresent) {
expect(isPresent).to.be.true;
done();
});
});
after(function(done){
servers.close();
done();
});
});

View File

@@ -1,133 +0,0 @@
'use strict';
var expect = require('chai').expect;
var webdriver = require('selenium-webdriver');
var driver = require('../driver');
var servers = require('../servers');
var until = webdriver.until;
var helpers = require('../helpers');
var elements = [
'swagger-ui-container',
'resources_container',
'api_info',
'resource_pet',
'resource_store',
'resource_user',
'header'
];
var specPath = helpers.parseSpecFilename(__filename);
describe('swagger 2.0 spec tests', function () {
this.timeout(40 * 1000);
before(function (done) {
this.timeout(50 * 1000);
servers.start(specPath, done);
});
afterEach(function(){
it('should not have any console errors', function (done) {
driver.manage().logs().get('browser').then(function(browserLogs) {
var errors = [];
browserLogs.forEach(function(log){
// 900 and above is "error" level. Console should not have any errors
if (log.level.value > 900) {
console.log('browser error message:', log.message); errors.push(log);
}
});
expect(errors).to.be.empty;
done();
});
});
});
it('should have "Swagger UI" in title', function () {
return driver.wait(until.titleIs('Swagger UI'), 1000);
});
elements.forEach(function (id) {
it('should render element: ' + id, function (done) {
var locator = webdriver.By.id(id);
driver.isElementPresent(locator).then(function (isPresent) {
expect(isPresent).to.be.true;
done();
});
});
});
it('should find the contact name element', function(done){
var locator = webdriver.By.css('.info_name');
driver.isElementPresent(locator).then(function (isPresent) {
expect(isPresent).to.be.true;
done();
});
});
it('should find the contact email element', function(done){
var locator = webdriver.By.css('.info_email');
driver.isElementPresent(locator).then(function (isPresent) {
expect(isPresent).to.be.true;
done();
});
});
it('should find the contact url element', function(done){
var locator = webdriver.By.css('.info_url');
driver.isElementPresent(locator).then(function (isPresent) {
expect(isPresent).to.be.true;
done();
});
});
it('should find the pet link', function(done){
var locator = webdriver.By.xpath('//*[@data-id="pet"]');
driver.isElementPresent(locator).then(function (isPresent) {
expect(isPresent).to.be.true;
done();
});
});
it('should find the pet resource description', function(done){
var locator = webdriver.By.xpath('//div[contains(., "Everything about your Pets")]');
driver.findElements(locator).then(function (elements) {
expect(elements.length).to.not.equal(0);
done();
});
});
it('should find the user link', function(done){
var locator = webdriver.By.xpath('//*[@data-id="user"]');
driver.isElementPresent(locator).then(function (isPresent) {
expect(isPresent).to.be.true;
done();
});
});
it('should find the store link', function(done){
var locator = webdriver.By.xpath('//*[@data-id="store"]');
driver.isElementPresent(locator).then(function (isPresent) {
expect(isPresent).to.be.true;
done();
});
});
/*
// TODO: disabling for now
['root.id','root.username','root.firstName','root.lastName', 'root.email', 'root.password', 'root.phone', 'root.userStatus']
.forEach(function (id) {
it('should find a jsoneditor for user post with field: ' + id, function (done) {
var locator = webdriver.By.xpath('//*[@id=\'user_createUser\']//*[@data-schemapath=\''+id+'\']');
driver
.wait(webdriver.until.elementLocated(locator),2000)
.then(function() { done(); });
});
});
// TODO JSonEditor Tests for POST/PUT
*/
after(function(done) {
servers.close();
done();
});
});

View File

@@ -1 +0,0 @@
test/e2e/**/*.js --recursive --timeout 5000

View File

@@ -1,60 +0,0 @@
{
"apiVersion": "1.0.0",
"swaggerVersion": "1.2",
"apis": [
{
"path": "http://localhost:8081/v1.2/petstore/pet.json",
"description": "Operations about pets"
},
{
"path": "http://localhost:8081/v1.2/petstore/user.json",
"description": "Operations about user"
},
{
"path": "http://localhost:8081/v1.2/petstore/store.json",
"description": "Operations about store"
}
],
"authorizations": {
"oauth2": {
"type": "oauth2",
"scopes": [
{
"scope": "email",
"description": "Access to your email address"
},
{
"scope": "pets",
"description": "Access to your pets"
}
],
"grantTypes": {
"implicit": {
"loginEndpoint": {
"url": "http://petstore.swagger.io/oauth/dialog"
},
"tokenName": "access_token"
},
"authorization_code": {
"tokenRequestEndpoint": {
"url": "http://petstore.swagger.io/oauth/requestToken",
"clientIdName": "client_id",
"clientSecretName": "client_secret"
},
"tokenEndpoint": {
"url": "http://petstore.swagger.io/oauth/token",
"tokenName": "access_code"
}
}
}
}
},
"info": {
"title": "Swagger Sample App",
"description": "This is a sample server Petstore server. You can find out more about Swagger \n at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample,\n you can use the api key \"special-key\" to test the authorization filters",
"termsOfServiceUrl": "http://swagger.io/terms/",
"contact": "apiteam@swagger.io",
"license": "Apache 2.0",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
}

View File

@@ -1,425 +0,0 @@
{
"apiVersion": "1.0.0",
"swaggerVersion": "1.2",
"basePath": "http://petstore.swagger.io/api",
"resourcePath": "/pet",
"produces": [
"application/json",
"application/xml",
"text/plain",
"text/html"
],
"apis": [
{
"path": "/pet/{petId}",
"operations": [
{
"method": "GET",
"summary": "Find pet by ID",
"notes": "Returns a pet based on ID",
"type": "Pet",
"nickname": "getPetById",
"authorizations": {},
"parameters": [
{
"name": "petId",
"description": "ID of pet that needs to be fetched",
"required": true,
"type": "integer",
"format": "int64",
"paramType": "path",
"minimum": "1.0",
"maximum": "100000.0"
}
],
"responseMessages": [
{
"code": 400,
"message": "Invalid ID supplied"
},
{
"code": 404,
"message": "Pet not found"
}
]
},
{
"method": "PATCH",
"summary": "partial updates to a pet",
"notes": "",
"type": "array",
"items": {
"$ref": "Pet"
},
"nickname": "partialUpdate",
"produces": [
"application/json",
"application/xml"
],
"consumes": [
"application/json",
"application/xml"
],
"authorizations": {
"oauth2": [
{
"scope": "test:anything",
"description": "anything"
}
]
},
"parameters": [
{
"name": "petId",
"description": "ID of pet that needs to be fetched",
"required": true,
"type": "string",
"paramType": "path"
},
{
"name": "body",
"description": "Pet object that needs to be added to the store",
"required": true,
"type": "Pet",
"paramType": "body"
}
],
"responseMessages": [
{
"code": 400,
"message": "Invalid tag value"
}
]
},
{
"method": "POST",
"summary": "Updates a pet in the store with form data",
"notes": "",
"type": "void",
"nickname": "updatePetWithForm",
"consumes": [
"application/x-www-form-urlencoded"
],
"authorizations": {
"oauth2": [
{
"scope": "test:anything",
"description": "anything"
}
]
},
"parameters": [
{
"name": "petId",
"description": "ID of pet that needs to be updated",
"required": true,
"type": "string",
"paramType": "path"
},
{
"name": "name",
"description": "Updated name of the pet",
"required": false,
"type": "string",
"paramType": "form"
},
{
"name": "status",
"description": "Updated status of the pet",
"required": false,
"type": "string",
"paramType": "form"
}
],
"responseMessages": [
{
"code": 405,
"message": "Invalid input"
}
]
},
{
"method": "DELETE",
"summary": "Deletes a pet",
"notes": "",
"type": "void",
"nickname": "deletePet",
"authorizations": {
"oauth2": [
{
"scope": "test:anything",
"description": "anything"
}
]
},
"parameters": [
{
"name": "petId",
"description": "Pet id to delete",
"required": true,
"type": "string",
"paramType": "path"
}
],
"responseMessages": [
{
"code": 400,
"message": "Invalid pet value"
}
]
}
]
},
{
"path": "/pet",
"operations": [
{
"method": "PUT",
"summary": "Update an existing pet",
"notes": "",
"type": "void",
"nickname": "updatePet",
"authorizations": {},
"parameters": [
{
"name": "body",
"description": "Pet object that needs to be updated in the store",
"required": true,
"type": "Pet",
"paramType": "body"
}
],
"responseMessages": [
{
"code": 400,
"message": "Invalid ID supplied"
},
{
"code": 404,
"message": "Pet not found"
},
{
"code": 405,
"message": "Validation exception"
}
]
},
{
"method": "POST",
"summary": "Add a new pet to the store",
"notes": "",
"type": "void",
"nickname": "addPet",
"consumes": [
"application/json",
"application/xml"
],
"authorizations": {
"oauth2": [
{
"scope": "test:anything",
"description": "anything"
}
]
},
"parameters": [
{
"name": "body",
"description": "Pet object that needs to be added to the store",
"required": true,
"type": "Pet",
"paramType": "body"
}
],
"responseMessages": [
{
"code": 405,
"message": "Invalid input"
}
]
}
]
},
{
"path": "/pet/findByStatus",
"operations": [
{
"method": "GET",
"summary": "Finds Pets by status",
"notes": "Multiple status values can be provided with comma seperated strings",
"type": "array",
"items": {
"$ref": "Pet"
},
"nickname": "findPetsByStatus",
"authorizations": {},
"parameters": [
{
"name": "status",
"description": "Status values that need to be considered for filter",
"defaultValue": "available",
"required": true,
"type": "string",
"paramType": "query",
"enum": [
"available",
"pending",
"sold"
]
}
],
"responseMessages": [
{
"code": 400,
"message": "Invalid status value"
}
]
}
]
},
{
"path": "/pet/findByTags",
"operations": [
{
"method": "GET",
"summary": "Finds Pets by tags",
"notes": "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.",
"type": "array",
"items": {
"$ref": "Pet"
},
"nickname": "findPetsByTags",
"authorizations": {},
"parameters": [
{
"name": "tags",
"description": "Tags to filter by",
"required": true,
"type": "string",
"paramType": "query"
}
],
"responseMessages": [
{
"code": 400,
"message": "Invalid tag value"
}
],
"deprecated": "true"
}
]
},
{
"path": "/pet/uploadImage",
"operations": [
{
"method": "POST",
"summary": "uploads an image",
"notes": "",
"type": "void",
"nickname": "uploadFile",
"consumes": [
"multipart/form-data"
],
"authorizations": {
"oauth2": [
{
"scope": "test:anything",
"description": "anything"
},
{
"scope": "test:nothing",
"description": "nothing"
}
]
},
"parameters": [
{
"name": "additionalMetadata",
"description": "Additional data to pass to server",
"required": false,
"type": "string",
"paramType": "form"
},
{
"name": "file",
"description": "file to upload",
"required": false,
"type": "File",
"paramType": "body"
}
]
}
]
}
],
"models": {
"Tag": {
"id": "Tag",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
}
}
},
"Pet": {
"id": "Pet",
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": "unique identifier for the pet",
"minimum": "0.0",
"maximum": "100.0"
},
"category": {
"$ref": "Category"
},
"name": {
"type": "string"
},
"photoUrls": {
"type": "array",
"items": {
"type": "string"
}
},
"tags": {
"type": "array",
"items": {
"$ref": "Tag"
}
},
"status": {
"type": "string",
"description": "pet status in the store",
"enum": [
"available",
"pending",
"sold"
]
}
}
},
"Category": {
"id": "Category",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
}
}
}
}
}

View File

@@ -1,145 +0,0 @@
{
"apiVersion": "1.0.0",
"swaggerVersion": "1.2",
"basePath": "http://petstore.swagger.io/api",
"resourcePath": "/store",
"produces": [
"application/json"
],
"apis": [
{
"path": "/store/order/{orderId}",
"operations": [
{
"method": "GET",
"summary": "Find purchase order by ID",
"notes": "For valid response try integer IDs with value <= 5. Anything above 5 or nonintegers will generate API errors",
"type": "Order",
"nickname": "getOrderById",
"authorizations": {},
"parameters": [
{
"name": "orderId",
"description": "ID of pet that needs to be fetched",
"required": true,
"type": "string",
"paramType": "path"
}
],
"responseMessages": [
{
"code": 400,
"message": "Invalid ID supplied"
},
{
"code": 404,
"message": "Order not found"
}
]
},
{
"method": "DELETE",
"summary": "Delete purchase order by ID",
"notes": "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors",
"type": "void",
"nickname": "deleteOrder",
"authorizations": {
"oauth2": [
{
"scope": "test:anything",
"description": "anything"
}
]
},
"parameters": [
{
"name": "orderId",
"description": "ID of the order that needs to be deleted",
"required": true,
"type": "string",
"paramType": "path"
}
],
"responseMessages": [
{
"code": 400,
"message": "Invalid ID supplied"
},
{
"code": 404,
"message": "Order not found"
}
]
}
]
},
{
"path": "/store/order",
"operations": [
{
"method": "POST",
"summary": "Place an order for a pet",
"notes": "",
"type": "void",
"nickname": "placeOrder",
"authorizations": {
"oauth2": [
{
"scope": "test:anything",
"description": "anything"
}
]
},
"parameters": [
{
"name": "body",
"description": "order placed for purchasing the pet",
"required": true,
"type": "Order",
"paramType": "body"
}
],
"responseMessages": [
{
"code": 400,
"message": "Invalid order"
}
]
}
]
}
],
"models": {
"Order": {
"id": "Order",
"description": "an order in the system",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"petId": {
"type": "integer",
"format": "int64"
},
"quantity": {
"type": "integer",
"format": "int32"
},
"status": {
"type": "string",
"description": "Order Status",
"enum": [
"placed",
" approved",
" delivered"
]
},
"shipDate": {
"type": "string",
"format": "date-time"
}
}
}
}
}

View File

@@ -1,299 +0,0 @@
{
"apiVersion": "1.0.0",
"swaggerVersion": "1.2",
"basePath": "http://petstore.swagger.io/api",
"resourcePath": "/user",
"produces": [
"application/json"
],
"apis": [
{
"path": "/user",
"operations": [
{
"method": "POST",
"summary": "Create user",
"notes": "This can only be done by the logged in user.",
"type": "void",
"nickname": "createUser",
"authorizations": {
"oauth2": [
{
"scope": "test:anything",
"description": "anything"
}
]
},
"parameters": [
{
"name": "body",
"description": "Created user object",
"required": true,
"type": "User",
"paramType": "body"
}
]
}
]
},
{
"path": "/user/logout",
"operations": [
{
"method": "GET",
"summary": "Logs out current logged in user session",
"notes": "",
"type": "void",
"nickname": "logoutUser",
"authorizations": {},
"parameters": []
}
]
},
{
"path": "/user/createWithArray",
"operations": [
{
"method": "POST",
"summary": "Creates list of users with given input array",
"notes": "",
"type": "void",
"nickname": "createUsersWithArrayInput",
"authorizations": {
"oauth2": [
{
"scope": "test:anything",
"description": "anything"
}
]
},
"parameters": [
{
"name": "body",
"description": "List of user object",
"required": true,
"type": "array",
"items": {
"$ref": "User"
},
"paramType": "body"
}
]
}
]
},
{
"path": "/user/createWithList",
"operations": [
{
"method": "POST",
"summary": "Creates list of users with given list input",
"notes": "",
"type": "void",
"nickname": "createUsersWithListInput",
"authorizations": {
"oauth2": [
{
"scope": "test:anything",
"description": "anything"
}
]
},
"parameters": [
{
"name": "body",
"description": "List of user object",
"required": true,
"type": "array",
"items": {
"$ref": "User"
},
"paramType": "body"
}
]
}
]
},
{
"path": "/user/{username}",
"operations": [
{
"method": "PUT",
"summary": "Updated user",
"notes": "This can only be done by the logged in user.",
"type": "void",
"nickname": "updateUser",
"authorizations": {
"oauth2": [
{
"scope": "test:anything",
"description": "anything"
}
]
},
"parameters": [
{
"name": "username",
"description": "name that need to be deleted",
"required": true,
"type": "string",
"paramType": "path"
},
{
"name": "body",
"description": "Updated user object",
"required": true,
"type": "User",
"paramType": "body"
}
],
"responseMessages": [
{
"code": 400,
"message": "Invalid username supplied"
},
{
"code": 404,
"message": "User not found"
}
]
},
{
"method": "DELETE",
"summary": "Delete user",
"notes": "This can only be done by the logged in user.",
"type": "void",
"nickname": "deleteUser",
"authorizations": {
"oauth2": [
{
"scope": "test:anything",
"description": "anything"
}
]
},
"parameters": [
{
"name": "username",
"description": "The name that needs to be deleted",
"required": true,
"type": "string",
"paramType": "path"
}
],
"responseMessages": [
{
"code": 400,
"message": "Invalid username supplied"
},
{
"code": 404,
"message": "User not found"
}
]
},
{
"method": "GET",
"summary": "Get user by user name",
"notes": "",
"type": "User",
"nickname": "getUserByName",
"authorizations": {},
"parameters": [
{
"name": "username",
"description": "The name that needs to be fetched. Use user1 for testing.",
"required": true,
"type": "string",
"paramType": "path"
}
],
"responseMessages": [
{
"code": 400,
"message": "Invalid username supplied"
},
{
"code": 404,
"message": "User not found"
}
]
}
]
},
{
"path": "/user/login",
"operations": [
{
"method": "GET",
"summary": "Logs user into the system",
"notes": "",
"type": "string",
"nickname": "loginUser",
"authorizations": {},
"parameters": [
{
"name": "username",
"description": "The user name for login",
"required": true,
"type": "string",
"paramType": "query"
},
{
"name": "password",
"description": "The password for login in clear text",
"required": true,
"type": "string",
"paramType": "query"
}
],
"responseMessages": [
{
"code": 400,
"message": "Invalid username and password combination"
}
]
}
]
}
],
"models": {
"User": {
"id": "User",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"firstName": {
"type": "string"
},
"username": {
"type": "string"
},
"lastName": {
"type": "string"
},
"email": {
"type": "string"
},
"password": {
"type": "string"
},
"phone": {
"type": "string"
},
"userStatus": {
"type": "integer",
"format": "int32",
"description": "User Status",
"enum": [
"1-registered",
"2-active",
"3-closed"
]
}
}
}
}
}

View File

@@ -1,53 +0,0 @@
swagger: '2.0'
info:
version: 0.0.0
title: title<script language="javascript">alert('1')</script>
description: description with **markdown** format <script language="javascript">alert('2')</script>
tags:
- name: Admin
description: tag with **markdown**
- name: Xss<script language="javascript">alert('3')</script>
description: tag with **markdown**<script language="javascript">alert('4')</script>
paths:
/test:
get:
description: description with **markdown** format
summary: a summary with **markdown** format
responses:
200:
description: a description with **markdown** format
schema:
$ref: '#/definitions/User'
post:
description: <script language="javascript">alert('5')</script>
summary: <script language="javascript">alert('6')</script>
consumes:
- <script language="javascript">alert('7')</script>
produces:
- <script language="javascript">alert('8')</script>
tags:
- Admin tasks<script language="javascript">alert('9')</script>
parameters:
- in: query
name: foo
type: string
- in: query
name: reg
type: string
responses:
200:
description: nothing<script language="javascript">alert('10')</script>
definitions:
User:
description: also with **markdown**
properties:
name:
description: prop with **markdown**
type: string
email:
$ref: '#/definitions/Email'
Email:
description: <script language="javascript">alert('11')</script>
type: string
format: email
example: <script language="javascript">alert('12')</script>

View File

@@ -1,953 +0,0 @@
{
"swagger": "2.0",
"info": {
"description": "This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters",
"version": "1.0.0",
"title": "Swagger Petstore",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"url": "http://swagger.io",
"name": "Your pals at Swagger",
"email": "apiteam@swagger.io"
},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"host": "petstore.swagger.io",
"basePath": "/v2",
"schemes": [
"http"
],
"tags": [
{
"name": "user",
"description": "Operations about user"
},
{
"name": "store",
"description": "Access to Petstore orders",
"externalDocs": {
"description": "Find out more",
"url": "http://swagger.io"
}
},
{
"name": "pet",
"description": "Everything about your Pets",
"externalDocs": {
"description": "Find out more",
"url": "http://swagger.io"
}
}
],
"paths": {
"/pet": {
"post": {
"tags": [
"pet"
],
"summary": "Add a new pet to the store",
"description": "",
"operationId": "addPet",
"consumes": [
"application/json",
"application/xml"
],
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"in": "body",
"name": "pet",
"description": "Pet object that needs to be added to the store",
"required": false,
"schema": {
"$ref": "#/definitions/Pet"
}
}
],
"responses": {
"405": {
"description": "Invalid input"
}
},
"security": [
{
"petstore_auth": [
"write:pets",
"read:pets"
]
}
]
},
"put": {
"tags": [
"pet"
],
"summary": "Update an existing pet",
"description": "",
"operationId": "updatePet",
"consumes": [
"application/json",
"application/xml"
],
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"in": "body",
"name": "body",
"description": "Pet object that needs to be added to the store",
"required": false,
"schema": {
"$ref": "#/definitions/Pet"
}
}
],
"responses": {
"405": {
"description": "Validation exception"
},
"404": {
"description": "Pet not found"
},
"400": {
"description": "Invalid ID supplied"
}
},
"security": [
{
"petstore_auth": [
"write:pets",
"read:pets"
]
}
]
}
},
"/pet/findByStatus": {
"get": {
"tags": [
"pet"
],
"summary": "Finds Pets by status",
"description": "Multiple status values can be provided with comma seperated strings",
"operationId": "findPetsByStatus",
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"in": "query",
"name": "status",
"description": "Status values that need to be considered for filter",
"required": false,
"type": "array",
"items": {
"type": "string"
},
"collectionFormat": "multi"
}
],
"responses": {
"200": {
"description": "successful operation",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Pet"
}
}
},
"400": {
"description": "Invalid status value"
}
},
"security": [
{
"petstore_auth": [
"write:pets",
"read:pets"
]
}
]
}
},
"/pet/findByTags": {
"get": {
"tags": [
"pet"
],
"summary": "Finds Pets by tags",
"description": "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.",
"operationId": "findPetsByTags",
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"in": "query",
"name": "tags",
"description": "Tags to filter by",
"required": false,
"type": "array",
"items": {
"type": "string"
},
"collectionFormat": "multi"
}
],
"responses": {
"200": {
"description": "successful operation",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Pet"
}
}
},
"400": {
"description": "Invalid tag value"
}
},
"security": [
{
"petstore_auth": [
"write:pets",
"read:pets"
]
}
]
}
},
"/pet/{petId}": {
"get": {
"tags": [
"pet"
],
"summary": "Find pet by ID",
"description": "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions",
"operationId": "getPetById",
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"in": "path",
"name": "petId",
"description": "ID of pet that needs to be fetched",
"required": true,
"type": "integer",
"format": "int64"
}
],
"responses": {
"404": {
"description": "Pet not found"
},
"200": {
"description": "successful operation",
"schema": {
"$ref": "#/definitions/Pet"
}
},
"400": {
"description": "Invalid ID supplied"
}
},
"security": [
{
"api_key": []
},
{
"petstore_auth": [
"write:pets",
"read:pets"
]
}
]
},
"post": {
"tags": [
"pet"
],
"summary": "Updates a pet in the store with form data",
"description": "",
"operationId": "updatePetWithForm",
"consumes": [
"application/x-www-form-urlencoded"
],
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"in": "path",
"name": "petId",
"description": "ID of pet that needs to be updated",
"required": true,
"type": "string"
},
{
"in": "formData",
"name": "name",
"description": "Updated name of the pet",
"required": true,
"type": "string"
},
{
"in": "formData",
"name": "status",
"description": "Updated status of the pet",
"required": true,
"type": "string"
}
],
"responses": {
"405": {
"description": "Invalid input"
}
},
"security": [
{
"petstore_auth": [
"write:pets",
"read:pets"
]
}
]
},
"delete": {
"tags": [
"pet"
],
"summary": "Deletes a pet",
"description": "",
"operationId": "deletePet",
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"in": "header",
"name": "api_key",
"description": "",
"required": true,
"type": "string"
},
{
"in": "path",
"name": "petId",
"description": "Pet id to delete",
"required": true,
"type": "integer",
"format": "int64"
}
],
"responses": {
"400": {
"description": "Invalid pet value"
}
},
"security": [
{
"petstore_auth": [
"write:pets",
"read:pets"
]
}
]
}
},
"/store/order": {
"post": {
"tags": [
"store"
],
"summary": "Place an order for a pet",
"description": "",
"operationId": "placeOrder",
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"in": "body",
"name": "body",
"description": "order placed for purchasing the pet",
"required": false,
"schema": {
"$ref": "#/definitions/Order"
}
}
],
"responses": {
"200": {
"description": "successful operation",
"schema": {
"$ref": "#/definitions/Order"
}
},
"400": {
"description": "Invalid Order"
}
}
}
},
"/store/order/{orderId}": {
"get": {
"tags": [
"store"
],
"summary": "Find purchase order by ID",
"description": "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions",
"operationId": "getOrderById",
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"in": "path",
"name": "orderId",
"description": "ID of pet that needs to be fetched",
"required": true,
"type": "string"
}
],
"responses": {
"404": {
"description": "Order not found"
},
"200": {
"description": "successful operation",
"schema": {
"$ref": "#/definitions/Order"
}
},
"400": {
"description": "Invalid ID supplied"
}
}
},
"delete": {
"tags": [
"store"
],
"summary": "Delete purchase order by ID",
"description": "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors",
"operationId": "deleteOrder",
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"in": "path",
"name": "orderId",
"description": "ID of the order that needs to be deleted",
"required": true,
"type": "string"
}
],
"responses": {
"404": {
"description": "Order not found"
},
"400": {
"description": "Invalid ID supplied"
}
}
}
},
"/user": {
"post": {
"tags": [
"user"
],
"summary": "Create user",
"description": "This can only be done by the logged in user.",
"operationId": "createUser",
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"in": "body",
"name": "body",
"description": "Created user object",
"required": false,
"schema": {
"$ref": "#/definitions/User"
}
}
],
"responses": {
"default": {
"description": "successful operation"
}
}
}
},
"/user/createWithArray": {
"post": {
"tags": [
"user"
],
"summary": "Creates list of users with given input array",
"description": "",
"operationId": "createUsersWithArrayInput",
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"in": "body",
"name": "body",
"description": "List of user object",
"required": false,
"schema": {
"type": "array",
"items": {
"$ref": "User"
}
}
}
],
"responses": {
"default": {
"description": "successful operation"
}
}
}
},
"/user/createWithList": {
"post": {
"tags": [
"user"
],
"summary": "Creates list of users with given input array",
"description": "",
"operationId": "createUsersWithListInput",
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"in": "body",
"name": "body",
"description": "List of user object",
"required": false,
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/User"
}
}
}
],
"responses": {
"default": {
"description": "successful operation"
}
}
}
},
"/user/login": {
"get": {
"tags": [
"user"
],
"summary": "Logs user into the system",
"description": "",
"operationId": "loginUser",
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"in": "query",
"name": "username",
"description": "The user name for login",
"required": false,
"type": "string"
},
{
"in": "query",
"name": "password",
"description": "The password for login in clear text",
"required": false,
"type": "string",
"format": "password"
}
],
"responses": {
"200": {
"description": "successful operation",
"schema": {
"type": "string"
}
},
"400": {
"description": "Invalid username/password supplied"
}
}
}
},
"/user/logout": {
"get": {
"tags": [
"user"
],
"summary": "Logs out current logged in user session",
"description": "",
"operationId": "logoutUser",
"produces": [
"application/json",
"application/xml"
],
"responses": {
"default": {
"description": "successful operation"
}
}
}
},
"/user/{username}": {
"get": {
"tags": [
"user"
],
"summary": "Get user by user name",
"description": "",
"operationId": "getUserByName",
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"in": "path",
"name": "username",
"description": "The name that needs to be fetched. Use user1 for testing. ",
"required": true,
"type": "string"
}
],
"responses": {
"404": {
"description": "User not found"
},
"200": {
"description": "successful operation",
"schema": {
"$ref": "#/definitions/User"
}
},
"400": {
"description": "Invalid username supplied"
}
}
},
"put": {
"tags": [
"user"
],
"summary": "Updated user",
"description": "This can only be done by the logged in user.",
"operationId": "updateUser",
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"in": "path",
"name": "username",
"description": "name that need to be deleted",
"required": true,
"type": "string"
},
{
"in": "body",
"name": "body",
"description": "Updated user object",
"required": false,
"schema": {
"$ref": "#/definitions/User"
}
}
],
"responses": {
"404": {
"description": "User not found"
},
"400": {
"description": "Invalid user supplied"
}
}
},
"delete": {
"tags": [
"user"
],
"summary": "Delete user",
"description": "This can only be done by the logged in user.",
"operationId": "deleteUser",
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"in": "path",
"name": "username",
"description": "The name that needs to be deleted",
"required": true,
"type": "string"
}
],
"responses": {
"404": {
"description": "User not found"
},
"400": {
"description": "Invalid username supplied"
}
}
}
}
},
"securityDefinitions": {
"api_key": {
"type": "apiKey",
"name": "api_key",
"in": "header"
},
"petstore_auth": {
"type": "oauth2",
"authorizationUrl": "http://petstore.swagger.io/api/oauth/dialog",
"flow": "implicit"
}
},
"definitions": {
"User": {
"properties": {
"id": {
"type": "integer",
"format": "int64",
"xml": {
"name": "id"
}
},
"username": {
"type": "string",
"xml": {
"name": "username"
}
},
"firstName": {
"type": "string",
"xml": {
"name": "firstName"
}
},
"lastName": {
"type": "string",
"xml": {
"name": "lastName"
}
},
"email": {
"type": "string",
"xml": {
"name": "email"
}
},
"password": {
"type": "string",
"xml": {
"name": "password"
}
},
"phone": {
"type": "string",
"xml": {
"name": "phone"
}
},
"userStatus": {
"type": "integer",
"format": "int32",
"xml": {
"name": "userStatus"
},
"description": "User Status"
}
},
"xml": {
"name": "User"
}
},
"Category": {
"properties": {
"id": {
"type": "integer",
"format": "int64",
"xml": {
"name": "id"
}
},
"name": {
"type": "string",
"xml": {
"name": "name"
}
}
},
"xml": {
"name": "Category"
}
},
"Pet": {
"required": [
"name",
"photoUrls"
],
"properties": {
"id": {
"type": "integer",
"format": "int64",
"xml": {
"name": "id"
}
},
"category": {
"xml": {
"name": "category"
},
"$ref": "#/definitions/Category"
},
"name": {
"type": "string",
"example": "doggie",
"xml": {
"name": "name"
}
},
"photoUrls": {
"type": "array",
"xml": {
"name": "photoUrl",
"wrapped": true
},
"items": {
"type": "string"
}
},
"tags": {
"type": "array",
"xml": {
"name": "tag",
"wrapped": true
},
"items": {
"$ref": "#/definitions/Tag"
}
},
"status": {
"type": "string",
"xml": {
"name": "status"
},
"description": "pet status in the store"
}
},
"xml": {
"name": "Pet"
}
},
"Tag": {
"properties": {
"id": {
"type": "integer",
"format": "int64",
"xml": {
"name": "id"
}
},
"name": {
"type": "string",
"xml": {
"name": "name"
}
}
},
"xml": {
"name": "Tag"
}
},
"Order": {
"properties": {
"id": {
"type": "integer",
"format": "int64",
"xml": {
"name": "id"
}
},
"petId": {
"type": "integer",
"format": "int64",
"xml": {
"name": "petId"
}
},
"quantity": {
"type": "integer",
"format": "int32",
"xml": {
"name": "quantity"
}
},
"shipDate": {
"type": "string",
"format": "date-time",
"xml": {
"name": "shipDate"
}
},
"status": {
"type": "string",
"xml": {
"name": "status"
},
"description": "Order Status"
},
"complete": {
"type": "boolean"
}
},
"xml": {
"name": "Order"
}
}
}
}

View File

@@ -1,59 +0,0 @@
/* jshint ignore:start */
$(function () {
'use strict';
var url = window.location.search.match(/url=([^&]+)/);
if (url && url.length > 1) {
url = decodeURIComponent(url[1]);
} else {
url = 'http://petstore.swagger.io/v2/swagger.json';
}
// Pre load translate...
if(window.SwaggerTranslator) {
window.SwaggerTranslator.translate();
}
window.swaggerUi = new SwaggerUi({
url: url,
dom_id: 'swagger-ui-container',
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
onComplete: function(){
if(typeof initOAuth === 'function') {
initOAuth({
clientId: 'your-client-id',
clientSecret: 'your-client-secret-if-required',
realm: 'your-realms',
appName: 'your-app-name',
scopeSeparator: ',',
additionalQueryStringParams: {}
});
}
if(window.SwaggerTranslator) {
window.SwaggerTranslator.translate();
}
$('pre code').each(function(i, e) {
hljs.highlightBlock(e);
});
},
onFailure: function() {
log('Unable to Load SwaggerUI');
},
docExpansion: 'none',
jsonEditor: false,
apisSorter: 'alpha',
defaultModelRendering: 'schema',
showRequestHeaders: false
});
window.swaggerUi.load();
function log() {
if ('console' in window) {
console.log.apply(console, arguments);
}
}
});
/* jshint ignore:end */

View File

@@ -1,688 +0,0 @@
'use strict';
describe('SwaggerUi.partials.signature tests', function () {
var sut = SwaggerUi.partials.signature;
var models = {
'Pet': {
'definition': {
'type': 'object',
'required': [ 'name', 'photoUrls' ],
'properties': {
'id': {
'type': 'integer',
'format': 'int64 '
},
'category': { '$ref': '#/definitions/Category' },
'name': {
'type': 'string',
'example': 'doggie'
},
'photoUrls': {
'type': 'array',
'xml': {
'name': 'photoUrl',
'wrapped':true
},
'items': { 'type': 'string' }
},
'tags': {
'type': 'array',
'xml': { 'name': 'tag', 'wrapped':true},
'items': { '$ref': '#/definitions/Tag' }
},
'status': {
'type': 'string',
'description': 'pet status in the store',
'enum':[ 'available', 'pending', 'sold' ]
}
},
'xml': { 'name': 'Pet' }
},
'name': 'Pet'
},
'Category': {
'definition': {
'type': 'object',
'properties': {
'id': { 'type': 'integer', 'format': 'int64' },
'name': { 'type': 'string' }
},
'xml': { 'name': 'Category' }
},
'name': 'Category'
},
'Tag': {
'definition': {
'type': 'object',
'properties': {
'id': { 'type': 'integer', 'format': 'int64' },
'name': { 'type': 'string' }
},
'xml': { 'name': 'Tag' }
},
'name': 'Tag'
},
'Loop1': {
'definition': {
'type': 'object',
'properties': {
'id': { 'type': 'integer'},
'loop2': {
'$ref': '#/definitions/Loop2'
}
},
'xml': { 'name': 'Loop1' }
},
'name': 'Loop1'
},
'Loop2': {
'definition': {
'type': 'object',
'properties': {
'id': { 'type': 'integer'},
'loop1': {
'$ref': '#/definitions/Loop1'
}
},
'xml': { 'name': 'Loop2' }
},
'name': 'Loop2'
},
'Loop3': {
'definition': {
'type': 'object',
'properties' : {
'loop1': {
'$ref': '#/definitions/Loop1'
}
},
'xml': { 'name': 'Loop3' }
},
'name': 'Loop3'
}
};
describe('method createSchemaXML', function () {
var date = new Date(1).toISOString().split('T')[0];
var dateTime = new Date(1).toISOString();
describe('simple types with no xml property', function () {
it('returns tag <tagname>string</tagname> when passing type string', function () {
var name = 'tagname';
var definition = {type: 'string'};
expect(sut.createSchemaXML(name, definition, models)).to.equal('<tagname>string</tagname>');
});
it('returns tag <tagname>1</tagname> when passing type integer', function () {
var name = 'tagname';
var definition = {type: 'integer'};
expect(sut.createSchemaXML(name, definition, models)).to.equal('<tagname>1</tagname>');
});
it('returns tag <tagname>1.1</tagname> when passing type number', function () {
var name = 'tagname';
var definition = {type: 'number'};
expect(sut.createSchemaXML(name, definition, models)).to.equal('<tagname>1.1</tagname>');
});
it('returns tag <tagname>boolean</tagname> when passing type boolean', function () {
var name = 'tagname';
var definition = {type: 'boolean'};
expect(sut.createSchemaXML(name, definition, models)).to.equal('<tagname>true</tagname>');
});
it('returns tag <tagname>' + date + '</tagname> when passing type string format date', function () {
var name = 'tagname';
var definition = {type: 'string', format: 'date'};
expect(sut.createSchemaXML(name, definition, models)).to.equal('<tagname>' + date + '</tagname>');
});
it('returns tag <tagname>' + dateTime + '</tagname> when passing type string format date-time', function () {
var name = 'tagname';
var definition = {type: 'string', format: 'date-time'};
expect(sut.createSchemaXML(name, definition, models)).to.equal('<tagname>' + dateTime + '</tagname>');
});
});
describe('simple types with xml property', function () {
it('returns tag <newtagname>string</newtagname> when passing type string and xml:{name: "newtagname"}', function () {
var name = 'tagname';
var definition = {
type: 'string',
xml: {
name: 'newtagname'
}
};
expect(sut.createSchemaXML(name, definition, models)).to.equal('<newtagname>string</newtagname>');
});
it('returns tag <test:newtagname>string</test:newtagname> when passing type string and xml:{name: "newtagname", prefix:"test"}', function () {
var name = 'tagname';
var definition = {
type: 'string',
xml: {
name: 'newtagname',
prefix: 'test'
}
};
expect(sut.createSchemaXML(name, definition, models)).to.equal('<test:newtagname>string</test:newtagname>');
});
it('returns tag <test:tagname>string</test:tagname> when passing type string and xml:{name: "newtagname", prefix:"test"}', function () {
var name = 'tagname';
var definition = {
type: 'string',
xml: {
prefix: 'test'
}
};
expect(sut.createSchemaXML(name, definition, models)).to.equal('<test:tagname>string</test:tagname>');
});
it('returns tag <test:tagname >string</test:tagname> when passing type string and xml:{"namespace": "http://swagger.io/schema/sample", "prefix": "sample"}', function () {
var name = 'name';
var definition = {
type: 'string',
xml: {
namespace: 'http://swagger.io/schema/sample',
prefix: 'sample'
}
};
expect(sut.createSchemaXML(name, definition, models)).to.equal('<sample:name xmlns:sample="http://swagger.io/schema/sample">string</sample:name>');
});
it('returns tag <test:tagname >string</test:tagname> when passing type string and xml:{"namespace": "http://swagger.io/schema/sample"}', function () {
var name = 'name';
var definition = {
type: 'string',
xml: {
namespace: 'http://swagger.io/schema/sample'
}
};
expect(sut.createSchemaXML(name, definition, models)).to.equal('<name xmlns="http://swagger.io/schema/sample">string</name>');
});
});
describe('array', function () {
it('returns tag <tagname>string</tagname> when passing string items', function () {
var expected = '<tagname>string</tagname>';
var name = 'tagname';
var definition = {
type: 'array',
items: {
type: 'string'
}
};
expect(sut.createSchemaXML(name, definition, models)).to.equal(expected);
});
it('returns tag <animal>string</animal> when passing string items with name', function () {
var expected = '<animal>string</animal>';
var name = 'animals';
var definition = {
type: 'array',
items: {
type: 'string',
xml: {
name: 'animal'
}
}
};
expect(sut.createSchemaXML(name, definition, models)).to.equal(expected);
});
it('returns tag <animals><animal>string</animal></animals> when passing string items with name', function () {
var expected = '<animals><animal>string</animal></animals>';
var name = 'animals';
var definition = {
type: 'array',
items: {
type: 'string',
xml: {
name: 'animal'
}
},
xml: {
wrapped: true
}
};
expect(sut.createSchemaXML(name, definition, models)).to.equal(expected);
});
it('returns tag <aliens><animal>string</animal></aliens> when passing string items with name and {wrapped: true}', function () {
var expected = '<aliens><animal>string</animal></aliens>';
var name = 'animals';
var definition = {
type: 'array',
items: {
type: 'string',
xml: {
name: 'animal'
}
},
xml: {
wrapped: true,
name: 'aliens'
}
};
expect(sut.createSchemaXML(name, definition, models)).to.equal(expected);
});
it('return correct nested wrapped array', function () {
var expected = '<aliens><cat>string</cat></aliens>';
var name = 'animals';
var definition = {
type: 'array',
items: {
type: 'array',
items: {
type: 'string'
},
xml: {
name: 'cat'
}
},
xml: {
wrapped: true,
name: 'aliens'
}
};
expect(sut.createSchemaXML(name, definition, models)).to.equal(expected);
});
it('return correct nested wrapped array', function () {
var expected = '<aliens>' +
'<cats><cat>string</cat></cats>' +
'</aliens>';
var name = 'animals';
var definition = {
type: 'array',
items: {
type: 'array',
items: {
type: 'string',
xml: {
name: 'cat'
}
},
xml: {
name: 'cats',
wrapped: true
}
},
xml: {
wrapped: true,
name: 'aliens'
}
};
expect(sut.createSchemaXML(name, definition, models)).to.equal(expected);
});
});
describe('object', function () {
it('returns object with 2 properties', function () {
var expected = '<aliens>' +
'<alien>string</alien>' +
'<cat>1</cat>' +
'</aliens>';
var name = 'animals';
var definition = {
type: 'object',
properties: {
alien: {
type: 'string'
},
cat: {
type: 'integer'
}
},
xml: {
name: 'aliens'
}
};
expect(sut.createSchemaXML(name, definition, models)).to.equal(expected);
});
it('returns object with integer property and array property', function () {
var expected = '<animals>' +
'<aliens>string</aliens>' +
'<cat>1</cat>' +
'</animals>';
var name = 'animals';
var definition = {
type: 'object',
properties: {
aliens: {
type: 'array',
items: {
type: 'string'
}
},
cat: {
type: 'integer'
}
},
xml: {
name: 'animals'
}
};
expect(sut.createSchemaXML(name, definition, models)).to.equal(expected);
});
it('returns object with integer property and array property', function () {
var expected = '<animals>' +
'<aliens><alien>string</alien></aliens>' +
'<cat>1</cat>' +
'</animals>';
var name = 'animals';
var definition = {
type: 'object',
properties: {
aliens: {
type: 'array',
items: {
type: 'string',
xml: {
name: 'alien'
}
},
xml: {
wrapped: true
}
},
cat: {
type: 'integer'
}
},
xml: {
name: 'animals'
}
};
expect(sut.createSchemaXML(name, definition, models)).to.equal(expected);
});
it('returns nested objects', function () {
var expected = '<animals>' +
'<aliens>' +
'<alien>string</alien>' +
'</aliens>' +
'<cat>string</cat>' +
'</animals>';
var name = 'animals';
var definition = {
type: 'object',
properties: {
aliens: {
type: 'object',
properties: {
alien: {
type: 'string',
xml: {
name: 'alien'
}
}
}
},
cat: {
type: 'string'
}
},
xml: {
name: 'animals'
}
};
expect(sut.createSchemaXML(name, definition, models)).to.equal(expected);
});
it('returns object with no readonly fields for parameter', function () {
var expected = '<animals>' +
'<id>1</id>'+
'</animals>';
var name = 'animals';
var definition = {
type: 'object',
properties: {
id: {
type: 'integer'
},
cat: {
readOnly: true,
type: 'string'
}
},
xml: {
name: 'animals'
}
};
expect(sut.createSchemaXML(name, definition, models, { isParam: true })).to.equal(expected);
});
it('returns object with passed parameter as attribute', function () {
var expected = '<animals id="1">' +
'<dog>string</dog>' +
'</animals>';
var name = 'animals';
var definition = {
type: 'object',
properties: {
id: {
type: 'integer',
xml: {
attribute: true
}
},
dog: {
type: 'string'
}
},
xml: {
name: 'animals'
}
};
expect(sut.createSchemaXML(name, definition, models, {isParam: true})).to.equal(expected);
});
});
describe('schema is in definitions', function () {
it('returns array of Tags wrapped into Tags', function () {
var expected = '<Tags>' +
'<Tag><id>1</id><name>string</name></Tag>' +
'</Tags>';
var schema = {
type: 'array',
items: {
$ref: '#/definitions/Tag'
},
xml: {
name: 'Tags',
wrapped: true
}
};
expect(sut.createSchemaXML('', schema, models)).to.equal(expected);
});
it('returns Object with properties Pet and name', function () {
var expected = '<Pet>' +
'<id>1</id>' +
'<Category>' +
'<id>1</id>' +
'<name>string</name>' +
'</Category>' +
'<name>doggie</name>' +
'<photoUrl>' +
'<photoUrl>string</photoUrl>' +
'</photoUrl>' +
'<tag>' +
'<Tag><id>1</id><name>string</name></Tag>' +
'</tag>' +
'<status>available</status>' +
'</Pet>';
var schema = {
$ref: '#/definitions/Pet'
};
expect(sut.createSchemaXML('', schema, models)).to.equal(expected);
});
it('infinite loop Loop1 => Loop2, Loop2 => Loop1', function () {
var expected = '<Loop1>' +
'<id>1</id>' +
'<Loop2>' +
'<id>1</id>' +
'<!-- Infinite loop $ref:Loop1 -->' +
'</Loop2>' +
'</Loop1>';
var schema = {
$ref: '#/definitions/Loop1'
};
expect(sut.createSchemaXML('', schema, models)).to.equal(expected);
});
it('infinite loop Loop3 => Loop1, Loop1 => Loop2, Loop2 => Loop1', function () {
var expected = '<Loop3>' +
'<Loop1>' +
'<id>1</id>' +
'<Loop2>' +
'<id>1</id>' +
'<!-- Infinite loop $ref:Loop1 -->' +
'</Loop2>' +
'</Loop1>' +
'</Loop3>';
var schema = {
$ref: '#/definitions/Loop3'
};
expect(sut.createSchemaXML('', schema, models)).to.equal(expected);
});
it('infinite loop Loop1 => Loop2, Loop2 => Loop1 with 2 different loops on one level', function () {
var expected = '<Pet><Loop1>' +
'<id>1</id>' +
'<Loop2>' +
'<id>1</id>' +
'<!-- Infinite loop $ref:Loop1 -->' +
'</Loop2>' +
'</Loop1>' +
'<Loop2>' +
'<id>1</id>' +
'<Loop1>' +
'<id>1</id>' +
'<!-- Infinite loop $ref:Loop2 -->' +
'</Loop1>' +
'</Loop2>' +
'</Pet>';
var schema = {
type: 'object',
properties: {
item1: {
$ref: '#/definitions/Loop1'
},
item2: {
$ref: '#/definitions/Loop2'
}
},
xml: {
name: 'Pet'
}
};
expect(sut.createSchemaXML('', schema, models)).to.equal(expected);
});
it('infinite loop Loop1 => Loop2, Loop2 => Loop1 with 2 different loops on one level', function () {
var expected = '<Pet><Loop1>' +
'<id>1</id>' +
'<Loop2>' +
'<id>1</id>' +
'<!-- Infinite loop $ref:Loop1 -->' +
'</Loop2>' +
'</Loop1>' +
'<Loop1>' +
'<id>1</id>' +
'<Loop2>' +
'<id>1</id>' +
'<!-- Infinite loop $ref:Loop1 -->' +
'</Loop2>' +
'</Loop1>' +
'</Pet>';
var schema = {
type: 'object',
properties: {
item1: {
$ref: '#/definitions/Loop1'
},
item2: {
$ref: '#/definitions/Loop1'
}
},
xml: {
name: 'Pet'
}
};
expect(sut.createSchemaXML('', schema, models)).to.equal(expected);
});
});
});
describe('method getPrimitiveSignature', function () {
it('returns warning message when type is object', function () {
expect(sut.getPrimitiveSignature({type: 'object'})).to.equal('Object is not a primitive');
});
it('returns array with items.format when passing array', function () {
var schema = {
type: 'array',
items: {
format: 'format',
type: 'type'
}
};
expect(sut.getPrimitiveSignature(schema)).to.equal('Array[format]');
});
it('returns array with items.type when passing array without items.format', function () {
var schema = {
type: 'array',
items: {
type: 'type'
}
};
expect(sut.getPrimitiveSignature(schema)).to.equal('Array[type]');
});
it('returns format of primitive', function () {
expect(sut.getPrimitiveSignature({type: 'type', format: 'format'})).to.equal('format');
});
it('returns type of primitive if format is not passed', function () {
expect(sut.getPrimitiveSignature({type: 'type'})).to.equal('type');
});
});
});