0

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?

nastassiar
  • 1,545
  • 2
  • 24
  • 43

2 Answers2

1

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.

Ron
  • 14,160
  • 3
  • 52
  • 39
  • Great thanks! Any chance you can point me in the direction of the code I should modify? – nastassiar Apr 21 '15 at 17:22
  • Unfortunately no, because I'm not that familiar with the ui's codebase. You can open an issue on the repository asking that and one of the developers would point you in the right direction. – Ron Apr 21 '15 at 20:49
1

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 = {};
nastassiar
  • 1,545
  • 2
  • 24
  • 43