Selaa lähdekoodia

#1248 createXMLSample Added handling readyOnly params

bubble
Anna Bodnia 8 vuotta sitten
vanhempi
commit
f68420051f
5 muutettua tiedostoa jossa 57 lisäystä ja 25 poistoa
  1. +12
    -8
      dist/swagger-ui.js
  2. +9
    -9
      dist/swagger-ui.min.js
  3. +1
    -1
      src/main/javascript/view/ParameterView.js
  4. +11
    -7
      src/main/javascript/view/partials/signature.js
  5. +24
    -0
      test/unit/view/partials/signatureSpec.js

+ 12
- 8
dist/swagger-ui.js Näytä tiedosto

@@ -26110,7 +26110,7 @@ SwaggerUi.Views.ParameterView = Backbone.View.extend({

var signatureModel = {
sampleJSON: SwaggerUi.partials.signature.createParameterJSONSample(modelType, modelDefinitions),
sampleXML: isXML ? SwaggerUi.partials.signature.createXMLSample(schema, modelDefinitions) : false,
sampleXML: isXML ? SwaggerUi.partials.signature.createXMLSample(schema, modelDefinitions, true) : false,
isParam: true,
signature: SwaggerUi.partials.signature.getParameterModelSignature(modelType, modelDefinitions),
defaultRendering: this.model.defaultRendering
@@ -26980,6 +26980,7 @@ SwaggerUi.partials.signature = (function () {
var name = descriptor.name;
var definition = descriptor.definition;
var models = descriptor.models;
var isParam = descriptor.isParam;
var serializedProperties;
var attrs = [];
var properties = definition.properties;
@@ -26996,6 +26997,8 @@ SwaggerUi.partials.signature = (function () {
properties = properties || {};

serializedProperties = _.map(properties, function (prop, key) {
if (isParam && prop.readOnly) { return ''; }

return createSchemaXML(key, prop, models);
}).join('');

@@ -27010,10 +27013,10 @@ SwaggerUi.partials.signature = (function () {
return '<!-- invalid XML -->';
}

function createSchemaXML (name, definition, models) {
function createSchemaXML (name, definition, models, isParam) {
var $ref = definition.$ref;
var descriptor = _.isString($ref) ? getDescriptorByRef($ref, models)
: getDescriptor(name, definition, models);
: getDescriptor(name, definition, models, isParam);

if (!descriptor) {
return getErrorMessage();
@@ -27029,7 +27032,7 @@ SwaggerUi.partials.signature = (function () {
}
}

function Descriptor (name, type, definition, models) {
function Descriptor (name, type, definition, models, isParam) {
if (arguments.length < 4) {
throw new Error();
}
@@ -27038,6 +27041,7 @@ SwaggerUi.partials.signature = (function () {
this.definition = definition;
this.models = models;
this.type = type;
this.isParam = isParam;
}

function getDescriptorByRef($ref, models) {
@@ -27053,7 +27057,7 @@ SwaggerUi.partials.signature = (function () {
return new Descriptor (name, type, model.definition, models);
}

function getDescriptor (name, definition, models){
function getDescriptor (name, definition, models, isParam){
var type = definition.type || 'object';
var xml = definition.xml || {};

@@ -27063,13 +27067,13 @@ SwaggerUi.partials.signature = (function () {

name = getName(name, xml);

return new Descriptor(name, type, definition, models);
return new Descriptor(name, type, definition, models,isParam);
}

function createXMLSample (definition, models) {
function createXMLSample (definition, models, isParam) {
var prolog = '<?xml version="1.0"?>';

return formatXml(prolog + createSchemaXML('', definition, models));
return formatXml(prolog + createSchemaXML('', definition, models, isParam));
}

return {


+ 9
- 9
dist/swagger-ui.min.js
File diff suppressed because it is too large
Näytä tiedosto


+ 1
- 1
src/main/javascript/view/ParameterView.js Näytä tiedosto

@@ -58,7 +58,7 @@ SwaggerUi.Views.ParameterView = Backbone.View.extend({

var signatureModel = {
sampleJSON: SwaggerUi.partials.signature.createParameterJSONSample(modelType, modelDefinitions),
sampleXML: isXML ? SwaggerUi.partials.signature.createXMLSample(schema, modelDefinitions) : false,
sampleXML: isXML ? SwaggerUi.partials.signature.createXMLSample(schema, modelDefinitions, true) : false,
isParam: true,
signature: SwaggerUi.partials.signature.getParameterModelSignature(modelType, modelDefinitions),
defaultRendering: this.model.defaultRendering


+ 11
- 7
src/main/javascript/view/partials/signature.js Näytä tiedosto

@@ -776,6 +776,7 @@ SwaggerUi.partials.signature = (function () {
var name = descriptor.name;
var definition = descriptor.definition;
var models = descriptor.models;
var isParam = descriptor.isParam;
var serializedProperties;
var attrs = [];
var properties = definition.properties;
@@ -792,6 +793,8 @@ SwaggerUi.partials.signature = (function () {
properties = properties || {};

serializedProperties = _.map(properties, function (prop, key) {
if (isParam && prop.readOnly) { return ''; }

return createSchemaXML(key, prop, models);
}).join('');

@@ -806,10 +809,10 @@ SwaggerUi.partials.signature = (function () {
return '<!-- invalid XML -->';
}

function createSchemaXML (name, definition, models) {
function createSchemaXML (name, definition, models, isParam) {
var $ref = definition.$ref;
var descriptor = _.isString($ref) ? getDescriptorByRef($ref, models)
: getDescriptor(name, definition, models);
: getDescriptor(name, definition, models, isParam);

if (!descriptor) {
return getErrorMessage();
@@ -825,7 +828,7 @@ SwaggerUi.partials.signature = (function () {
}
}

function Descriptor (name, type, definition, models) {
function Descriptor (name, type, definition, models, isParam) {
if (arguments.length < 4) {
throw new Error();
}
@@ -834,6 +837,7 @@ SwaggerUi.partials.signature = (function () {
this.definition = definition;
this.models = models;
this.type = type;
this.isParam = isParam;
}

function getDescriptorByRef($ref, models) {
@@ -849,7 +853,7 @@ SwaggerUi.partials.signature = (function () {
return new Descriptor (name, type, model.definition, models);
}

function getDescriptor (name, definition, models){
function getDescriptor (name, definition, models, isParam){
var type = definition.type || 'object';
var xml = definition.xml || {};

@@ -859,13 +863,13 @@ SwaggerUi.partials.signature = (function () {

name = getName(name, xml);

return new Descriptor(name, type, definition, models);
return new Descriptor(name, type, definition, models,isParam);
}

function createXMLSample (definition, models) {
function createXMLSample (definition, models, isParam) {
var prolog = '<?xml version="1.0"?>';

return formatXml(prolog + createSchemaXML('', definition, models));
return formatXml(prolog + createSchemaXML('', definition, models, isParam));
}

return {


+ 24
- 0
test/unit/view/partials/signatureSpec.js Näytä tiedosto

@@ -418,6 +418,30 @@ describe('SwaggerUi.partials.signature tests', function () {

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, true)).to.equal(expected);
});
});

describe('schema is in definitions', function () {


Ladataan…
Peruuta
Tallenna