swagger-client
Advanced tools
Comparing version 2.1.10 to 2.1.11
@@ -43,2 +43,7 @@ 'use strict'; | ||
} | ||
// OPTIONS support | ||
if(obj.method.toLowerCase() === 'OPTIONS' && typeof client === 'SuperagentHttpClient') { | ||
log('forcing jQuery as OPTIONS are not supported by SuperAgent'); | ||
obj.useJQuery = true; | ||
} | ||
if(this.isInternetExplorer() && (obj.useJQuery === false || !hasJQuery )) { | ||
@@ -45,0 +50,0 @@ throw new Error('Unsupported configuration! JQuery is required but not available'); |
@@ -146,3 +146,25 @@ 'use strict'; | ||
if (response.schema) { | ||
this.resolveTo(root, response.schema, resolutionTable, location); | ||
var responseObj = response; | ||
if(_.isArray(responseObj.schema.allOf)) { | ||
// move to a definition | ||
var modelName = 'inline_model'; | ||
var name = modelName; | ||
var done = false; var counter = 0; | ||
while(!done) { | ||
if(typeof spec.definitions[name] === 'undefined') { | ||
done = true; | ||
break; | ||
} | ||
name = modelName + '_' + counter; | ||
counter ++; | ||
} | ||
spec.definitions[name] = { allOf: responseObj.schema.allOf }; | ||
delete responseObj.schema.allOf; | ||
delete responseObj.schema.type; | ||
responseObj.schema.$ref = '#/definitions/' + name; | ||
this.processAllOf(root, name, spec.definitions[name], resolutionTable, unresolvedRefs, spec); | ||
} | ||
else { | ||
this.resolveTo(root, response.schema, resolutionTable, location); | ||
} | ||
} | ||
@@ -458,5 +480,22 @@ } | ||
if(item.indexOf('http://') !== 0 && item.indexOf('https://') !== 0) { | ||
if(item.indexOf('#') !== 0) { | ||
// TODO: check if root ends in '/'. If not, AND item has no protocol, make relative | ||
var appendHash = true; | ||
var oldRoot = root; | ||
if(root) { | ||
var lastChar = root.slice(-1); | ||
if(lastChar !== '/' && (item.indexOf('#') !== 0 && item.indexOf('http://') !== 0 && item.indexOf('https://'))) { | ||
console.log('working with ' + item); | ||
appendHash = false; | ||
var parts = root.split('\/'); | ||
parts = parts.splice(0, parts.length - 1); | ||
root = ''; | ||
for(var i = 0; i < parts.length; i++) { | ||
root += parts[i] + '/'; | ||
} | ||
} | ||
} | ||
if(item.indexOf('#') !== 0 && appendHash) { | ||
item = '#' + item; | ||
} | ||
item = (root || '') + item; | ||
@@ -553,3 +592,3 @@ obj[key] = item; | ||
var lroot = root; | ||
if (typeof ref !== 'undefined') { | ||
if ((typeof ref !== 'undefined') && (ref !== null)) { | ||
if(ref.indexOf('#') >= 0) { | ||
@@ -556,0 +595,0 @@ var parts = ref.split('#'); |
'use strict'; | ||
var log = require('../helpers').log; | ||
var _ = { | ||
@@ -24,2 +25,3 @@ isPlainObject: require('lodash-compat/lang/isPlainObject'), | ||
Model.prototype.createJSONSample = Model.prototype.getSampleValue = function (modelsToIgnore) { | ||
log('Methods createJSONSample and getSampleValue are deprecated', 'color: red;'); | ||
modelsToIgnore = modelsToIgnore || {}; | ||
@@ -44,3 +46,4 @@ | ||
Model.prototype.getMockSignature = function () { | ||
log('Method getMockSignature is deprecated', 'color: red;'); | ||
return SchemaMarkup.schemaToHTML(this.name, this.definition, this.models, this.modelPropertyMacro); | ||
}; |
@@ -150,2 +150,3 @@ 'use strict'; | ||
param.modelSignature = {type: innerType, definitions: this.models}; | ||
param.signature = this.getModelSignature(innerType, this.models).toString(); | ||
@@ -152,0 +153,0 @@ param.sampleJSON = this.getModelSampleJSON(innerType, this.models); |
@@ -11,3 +11,3 @@ { | ||
"description": "swagger-client is a javascript client for use with swaggering APIs.", | ||
"version": "2.1.10", | ||
"version": "2.1.11", | ||
"homepage": "http://swagger.io", | ||
@@ -14,0 +14,0 @@ "repository": { |
@@ -26,8 +26,8 @@ # Swagger JS library | ||
```js | ||
var client = require('swagger-client'); | ||
var Swagger = require('swagger-client'); | ||
var swagger = new client({ | ||
var client = new Swagger({ | ||
url: 'http://petstore.swagger.io/v2/swagger.json', | ||
success: function() { | ||
swagger.pet.getPetById({petId:7},{responseContentType: 'application/json'},function(pet){ | ||
client.pet.getPetById({petId:7},{responseContentType: 'application/json'},function(pet){ | ||
console.log('pet', pet); | ||
@@ -75,8 +75,8 @@ }); | ||
```js | ||
var client = require('swagger-client'); | ||
var Swagger = require('swagger-client'); | ||
var swagger = new client({ | ||
var client = new Swagger({ | ||
url: 'http://petstore.swagger.io/v2/swagger.json', | ||
success: function() { | ||
swagger.pet.getPetById({petId:7}, function(success){ | ||
client.pet.getPetById({petId:7}, function(success){ | ||
console.log('succeeded and returned this object: ' + success.obj); | ||
@@ -114,3 +114,3 @@ }, | ||
```js | ||
client.clientAuthorizations.add("apiKey", new client.ApiKeyAuthorization("api_key","special-key","query")); | ||
client.clientAuthorizations.add("apiKey", new Swagger.ApiKeyAuthorization("api_key","special-key","query")); | ||
``` | ||
@@ -121,3 +121,3 @@ | ||
```js | ||
client.clientAuthorizations.add("apiKey", new client.ApiKeyAuthorization("api_key","special-key","header")); | ||
client.clientAuthorizations.add("apiKey", new Swagger.ApiKeyAuthorization("api_key","special-key","header")); | ||
``` | ||
@@ -128,3 +128,3 @@ | ||
```js | ||
var swagger = new client({ | ||
var client = new Swagger({ | ||
url: 'http://example.com/spec.json', | ||
@@ -148,8 +148,8 @@ success: function() {}, | ||
<script type="text/javascript"> | ||
// initialize swagger, point to a resource listing | ||
window.swagger = new SwaggerClient({ | ||
// initialize swagger client, point to a resource listing | ||
window.client = new SwaggerClient({ | ||
url: "http://petstore.swagger.io/v2/swagger.json", | ||
success: function() { | ||
// upon connect, fetch a pet and set contents to element "mydata" | ||
swagger.pet.getPetById({petId:1},{responseContentType: 'application/json'}, function(data) { | ||
client.pet.getPetById({petId:1},{responseContentType: 'application/json'}, function(data) { | ||
document.getElementById("mydata").innerHTML = JSON.stringify(data.obj); | ||
@@ -172,3 +172,3 @@ }); | ||
swagger.pet.addPet({body: pet}); | ||
client.pet.addPet({body: pet}); | ||
``` | ||
@@ -180,3 +180,3 @@ | ||
swagger.pet.addPet({body: pet}, {requestContentType:"application/xml"}); | ||
client.pet.addPet({body: pet}, {requestContentType:"application/xml"}); | ||
``` | ||
@@ -186,3 +186,3 @@ | ||
```js | ||
swagger.pet.getPetById({petId:1}, {responseContentType:"application/xml"}); | ||
client.pet.getPetById({petId:1}, {responseContentType:"application/xml"}); | ||
``` | ||
@@ -211,2 +211,8 @@ | ||
You can add it to the swagger-client like such: | ||
```js | ||
client.clientAuthorizations.add('my-auth', new CustomRequestSigner()); | ||
``` | ||
### How does it work? | ||
@@ -265,3 +271,3 @@ The swagger javascript client reads the swagger api definition directly from the server. As it does, it constructs a client based on the api definition, which means it is completely dynamic. It even reads the api text descriptions (which are intended for humans!) and provides help if you need it: | ||
Copyright 2011-2015 SmartBear Software | ||
Copyright 2016 SmartBear Software | ||
@@ -268,0 +274,0 @@ Licensed under the Apache License, Version 2.0 (the "License"); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2526168
30533
273
1