Swagger UI为我的服务生成的curl
命令如下:
curl -X GET --header "Accept: application/json" "http://localhost:8080/foo/402215"
如何在命令中添加额外的标题,以便我得到以下内容:
curl -X GET --header "Accept: application/json" --header "Content-type: application/json" "http://localhost:8080/foo/402215"
我的控制器看起来像:
@Controller
@RequestMapping(value = "/",
consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE},
produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE}
)
public class BlobController {
@RequestMapping(value = "/foo", method = RequestMethod.GET)
@ResponseBody
public Blob foo(@RequestBody String id) {
return new Blob();
}
}
我使用的是Spring Boot和SpringFox。
答案 0 :(得分:0)
要添加自定义标题,您可以修改swagger index.html文件并添加如下所示的行:
if UIImagePickerController.isCameraDeviceAvailable(cameraDevice:UIImagePickerControllerCameraDevice.self)
{
}
见这里:https://github.com/swagger-api/swagger-ui#custom-header-parameters---for-basic-auth-etc
答案 1 :(得分:0)
应自动生成Accept和Content-type参数。如果您想要包含动态值的标头,可以将 <ListView>
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding A}" Grid.Column="0"/>
<TextBlock Text="{Binding B}" Grid.Column="1"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
注释添加到方法签名中:
@HeaderParam
然后,Swagger将显示该头参数以及其他路径&amp;查询参数。