Reputation: 1621
I'm upgrading to swagger 2.0 and in the UI of my models I want strings to appear as "".
Right now the model schema looks like
{
"Name": "string",
"Id": "string",
"Year": 0
}
and I want it to look like
{
"Name": "",
"Id": "",
"Year": 0
}
Is there a way to set this in swagger 2.0?
Upvotes: 0
Views: 340
Reputation: 1621
To make the change I had to update the swagger-client file
The lines I changed are commented with //// BEGIN CUSTOM EDITS ///. These changes made strings display as '' instead of string and booleans as false instead of true in the schemas.
var schemaToJSON = function (schema, models, modelsToIgnore) {
var type = schema.type || 'object';
var model;
var output;
if (schema.example) {
output = schema.example;
} else if (_.isUndefined(schema.items) && _.isArray(schema.enum)) {
output = schema.enum[0];
}
if (_.isUndefined(output)) {
if (schema.$ref) {
model = models[helpers.simpleRef(schema.$ref)];
if (!_.isUndefined(model)) {
if (_.isUndefined(modelsToIgnore[model.name])) {
modelsToIgnore[model.name] = model;
output = schemaToJSON(model.definition, models, modelsToIgnore);
delete modelsToIgnore[model.name];
} else {
if (model.type === 'array') {
output = [];
} else {
output = {};
}
}
}
} else if (!_.isUndefined(schema.default)) {
output = schema.default;
} else if (type === 'date-time') {
output = new Date().toISOString();
} else if (type === 'date') {
output = new Date().toISOString().split('T')[0];
} else if (type === 'string') {
//// BEGIN CUSTOM EDITS ///
// Change default display
output = '';
// END CUSTOM EDITS
} else if (type === 'integer') {
output = 0;
} else if (type === 'long') {
output = 0;
} else if (type === 'float') {
output = 0.0;
} else if (type === 'double') {
output = 0.0;
} else if (type === 'boolean') {
//// BEGIN CUSTOM EDITS ///
// Change default display
output = false;
// END CUSTOM EDITS
} else if (type === 'number') {
output = 0.0;
} else if (type === 'object') {
output = {};
Upvotes: 1
Reputation: 14830
It's not configurable. This is how the display works and how it tells the end user the type of value that needs to be used. An empty string will not be as descriptive as saying it is a string explicitly.
If you feel strongly about it though, you're more than welcome to modify the code to suit your nodes. The code is readily available and can be customized at your will.
Upvotes: 1