Skip to content

Commit

Permalink
swagger-api#1248 createXMLSample Added handling readyOnly params
Browse files Browse the repository at this point in the history
  • Loading branch information
bodnia committed Jan 18, 2016
1 parent e2b464d commit 25895fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
20 changes: 12 additions & 8 deletions swagger-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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('');

Expand All @@ -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();
Expand All @@ -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();
}
Expand All @@ -27038,6 +27041,7 @@ SwaggerUi.partials.signature = (function () {
this.definition = definition;
this.models = models;
this.type = type;
this.isParam = isParam;
}

function getDescriptorByRef($ref, models) {
Expand All @@ -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 || {};

Expand All @@ -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 {
Expand Down
Loading

0 comments on commit 25895fc

Please sign in to comment.