- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 ServiceStack 的新 Swagger 插件实现 Swagger API 文档,并试图确定如何使用“容器”数据类型。我需要显示一个字符串字段,其中包含一个预先确定的值列表和其他子对象列表的参数。
除非我遗漏了一些东西,否则我相信 swagger 只能采用一个文本字段,您可以为子对象列表输入 JSON。我相信这段代码应该可以解决问题。
[ApiMember(Name = "Connections", Description = "insert JSON sample here", ParameterType = "body", DataType = "container", IsRequired = false, Verb = "Post")]
"Pet":{
"id":"Pet",
"properties":{
...
"status":{
"type":"String",
"description":"pet status in the store",
"allowableValues":{
"valueType":"LIST",
"values":[
"available",
"pending",
"sold"
]
}
},
"happiness": {
"type": "Int",
"description": "how happy the Pet appears to be, where 10 is 'extremely happy'",
"allowableValues": {
"valueType": "RANGE",
"min": 1,
"max": 10
}
},
...
最佳答案
我一直在为同样的问题苦苦挣扎,但意识到目前不支持此功能。您基本上不能使用模型 POST 或 PUT 数据。这个功能还在不断变化中,正在开发中,所以我想它在待办事项列表中。
如果查看源代码,会看到没有Models
ResourcesResponse 中支持的属性数据合约:
[DataContract]
public class ResourcesResponse
{
[DataMember(Name = "swaggerVersion")]
public string SwaggerVersion { get; set; }
[DataMember(Name = "apiVersion")]
public string ApiVersion { get; set; }
[DataMember(Name = "basePath")]
public string BasePath { get; set; }
[DataMember(Name = "apis")]
public List<RestService> Apis { get; set; }
}
{
"apiVersion":"0.2",
"swaggerVersion":"1.1",
"basePath":"http://petstore.swagger.wordnik.com/api",
"resourcePath":"/pet",
"apis":[
{
"path":"/pet.{format}",
"description":"Operations about pets",
"operations":[
{
"httpMethod":"POST",
"summary":"Add a new pet to the store",
"responseClass":"void",
"nickname":"addPet",
"parameters":[
{
"description":"Pet object that needs to be added to the store",
"paramType":"body",
"required":true,
"allowMultiple":false,
"dataType":"Pet"
}
],
"errorResponses":[
{
"code":405,
"reason":"Invalid input"
}
]
}
]
}
],
"models":{
"Category":{
"id":"Category",
"properties":{
"id":{
"type":"long"
},
"name":{
"type":"string"
}
}
},
"Pet":{
"id":"Pet",
"properties":{
"tags":{
"items":{
"$ref":"Tag"
},
"type":"Array"
},
"id":{
"type":"long"
},
"category":{
"type":"Category"
},
"status":{
"allowableValues":{
"valueType":"LIST",
"values":[
"available",
"pending",
"sold"
],
"valueType":"LIST"
},
"description":"pet status in the store",
"type":"string"
},
"name":{
"type":"string"
},
"photoUrls":{
"items":{
"type":"string"
},
"type":"Array"
}
}
},
"Tag":{
"id":"Tag",
"properties":{
"id":{
"type":"long"
},
"name":{
"type":"string"
}
}
}
}
}
ParameterType
至
body
和
DataType
至
Pet
.在 Swagger 界面中,您将看到一个文本区域,您必须在其中粘贴实际的 JSON 对象。您的请求将如下所示:
[Api("The Thing Service")]
[Route("/thing", "POST", Summary = @"POST a new thing", Notes = "Send a thing here")]
public class ThingRequest
{
[DataMember]
[ApiMember(Name = "Thing", Description = "The thing", ParameterType = "body", DataType = "Thing", IsRequired = false)]
public ThingDto Thing { get; set; }
}
/// <summary>
/// Summary description for ThingService
/// </summary>
public class ThingService : Service
{
public IThingRepository ThingRepository { get; set; }
public object Post(ThingRequest request)
{
var thing = Thing.Map(request);
ThingRepository.Save(thing);
return new ThingResponse();
}
}
关于api - 使用 ServiceStack 的 Swagger 插件,如何实现带有预设值列表的字符串字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14761424/
我想我读过一些可以在 cocoa 应用程序中包含 NSUserDefaults 文件的地方。我似乎无法找到如何做到这一点。 我知道我可以在第一次应用程序启动时创建,但我还不想这样做...... 最佳答
所以我有一个 HTML 表单,用户可以在其中通过选中三个预设答案之一或编写自己的自定义答案来回答单选题。 虽然这显然是一个多对多关系,但我仍然找不到合适的方法来设计数据库表以处理这两种类型(TEXT
这个问题在这里已经有了答案: Unexpected token '=' in React Component [duplicate] (2 个答案) 关闭 4 年前。 我在使用 Webpack 构建
我正在创建一个自定义相机 View ,并尝试查看是否有办法为输入和输出设置不同的 session 预设。我希望能够向用户展示高分辨率,但以低分辨率捕获 var captureSession: AVCa
我当前的设置如下(基于 Brad Larson 的 ColorTrackingCamera 项目): 我正在使用设置为 AVCaptureSessionPreset640x480 的 AVCaptur
我正在开发一个 React-Native 应用程序,它是使用 Expo 安装的,使用以下代码创建 .babelrc 配置: { "presets": ["babel-preset-expo"]
在一个工作 Jest + puppeteer 操作项目中, 为了使用 jest-circus retry feature,我要去 jest-circus . 正如所记录的,我安装了 jest-circ
这个问题已经有答案了: How to use arrow functions (public class fields) as class methods? (4 个回答) 已关闭 4 年前。 当我尝
我正在使用实现 Browserify-Rails 的 Rails 4.0 项目实现Babelify . 在我的本地和远程 Beta 服务器上,一切似乎都很顺利。但是当我部署到生产环境时,某些文件将被跳
我正在向 dat.gui 界面动态添加控件,但“保存设置”功能无法识别它们。 var mygui = new dat.GUI(); mygui.remember(mygui); // standard
我想创建一个录制方形视频的自定义相机。然而,所有的捕获 session 预设都不是方形格式 例如: 1920x1080 1280x720 640x480 无论如何我可以创建一个自定义预设。我仍然想要高
function floatTo16BitPCM(output, offset, input){ for (var i = 0; i < input.length; i++, offset+=2)
我正在阅读有关使用 systemd 预设的 Fedora 打包指南,但遗漏了一个关键点: 宏 %systemd_post 运行 systemctl preset 意味着有关是否启用或禁用该服务的信息必
错误描述:当为 javascript 代码的简单单元测试运行 jest 时,出现错误测试套件无法运行未知选项:.preset 以下是重现错误的文件: { "name": "Relocati
我正在尝试使用 ffmpeg 和 x264 对视频进行编码。我知道 ffmpeg 从命令行使用程序 ffmpeg 时可以使用 x264 预设。但是在代码中使用 ffmpeg 编码时是否可以轻松使用
我的 npm 包构建使用 babel 运行,我在我的 package.json 中配置了一个 babel 预设 "babel": { "presets": ["es2015"] } 我还配置了一个 m
我们正在尝试使用 javacpp 重新编译 ffmpeg 项目,并启用 --enable-libfdk-aac ,构建可以正常工作,但我们无法使用 libfdk_aac 来解码 audio_strea
美好的一天: 我刚刚通过 NPM 安装了 Babel Preset-ENV 并遇到了这个问题: [nodemon] starting `babel-node server.js server.js`
我正在通过 ffmpeg(在 C++ 程序中)使用 libx264,我需要知道如何激活“非常快”预设。 x264 源代码树中的 grep 生成: include/x264.h:static const
我正在处理的一个项目已经配置了 Jest,并且测试工作正常。这就是当前 jest.config.js 文件的样子; const ignores = [...]; const coverageIgnor
我是一名优秀的程序员,十分优秀!