2015-04-20 21 views
0

我正在升级到swagger 2.0,并且在我的模型的用户界面中,我希望字符串显示为“”。Swagger 2.0在模型中的字符串显示为“”

眼下模型模式看起来像

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

,我希望它看起来像

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

有没有一种方法来设置这招摇2.0吗?

回答

1

为了让我不得不更新swagger-client file

我改变了线与//// BEGIN CUSTOM编辑///评论的变化。这些更改使得字符串显示为'',而不是字符串和布尔值,在模式中显示为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 = {}; 
1

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

如果您对此感到强烈,那么欢迎您修改代码以适合您的节点。代码随时可用,并可根据您的意愿自定义。

+0

非常感谢!你有什么机会可以将我指向我应该修改的代码的方向? – nastassiar

+0

不幸的是,因为我不熟悉ui的代码库。您可以在存储库上打开一个问题,并要求其中一位开发人员指出您正确的方向。 – Ron

相关问题