0

我正在升级到 swagger 2.0,在我的模型的 UI 中,我希望字符串显示为“”。

现在模型模式看起来像

{
  "Name": "string",
  "Id": "string",
  "Year": 0
}

我希望它看起来像

{
  "Name": "",
  "Id": "",
  "Year": 0
}

有没有办法在 swagger 2.0 中设置它?

4

2 回答 2

1

它不可配置。这就是显示的工作方式以及它如何告诉最终用户需要使用的值的类型。一个空字符串不会像明确说它是一个字符串那样具有描述性。

但是,如果您对此有强烈的感觉,我们非常欢迎您修改代码以适合您的节点。该代码很容易获得,并且可以根据您的意愿进行定制。

于 2015-04-20T19:02:31.320 回答
1

要进行更改,我必须更新swagger-client 文件

我更改的行用 //// BEGIN CUSTOM EDITS /// 注释。这些更改使字符串在模式中显示为 '' 而不是字符串,布尔值显示为 false 而不是 true。

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 = {};
于 2015-05-05T20:18:15.453 回答