此问题不是(Swagger - 指定可选对象属性或多个响应)的重复,因为该OP试图返回200或400.
我有一个GET可选参数; 例如,GET /endpoint?selector=foo.
我想根据参数是否通过返回其架构不同的200,例如:
GET /endpoint -> {200, schema_1}
GET /endpoint?selector=blah -> {200, schema_2}
Run Code Online (Sandbox Code Playgroud)
在yaml中,我尝试了两个200代码,但是观察者将它们压扁,好像我只指定了一个.
有没有办法做到这一点?
编辑:以下似乎相关:https://github.com/OAI/OpenAPI-Specification/issues/270
我在WebApi 2应用程序中集成了swagger.应用程序有单个控制器时,它工作正常.当我在应用程序中添加第二个控制器时.我收到以下错误:
发生错误.","ExceptionMessage":"Swagger 2.0不支持:路径'api/Credential'和方法'GET'的多个操作.请参阅配置设置 - \"ResolveConflictingActions \"以获取潜在的解决方法","ExceptionType":"System.NotSupportedException","StackTrace":"at Swashbuckle.Swagger.SwaggerGeneratorOptions.DefaultConflictingActionsResolver(IEnumerable
1 apiDescriptions)\r\n at Swashbuckle.Swagger.SwaggerGenerator.CreatePathItem(IEnumerable1 apiDescriptions,SchemaRegistry schemaRegistry)\ r \在Swashbuckle.Swagger.SwaggerGenerator.<> c__DisplayClass7.b__4(IGrouping2 group)\r\n at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source,Func2 keySelector, Func2 elementSelector,IEqualityComparer1 comparer)\r\n at Swashbuckle.Swagger.SwaggerGenerator.GetSwagger(String rootUrl, String apiVersion)\r\n at Swashbuckle.Application.SwaggerDocsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Web.Http.Dispatcher.HttpRoutingDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Web.Http.Cors.CorsMessageHandler.<SendAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.HttpServer.d__0.MoveNext()"} http:// …
c# asp.net-web-api swagger asp.net-web-api-routing swashbuckle
我想知道如何以昂首阔步的方式记录枚举.
根据JavaDoc
dataType.有关支持的数据类型,请参阅文档.如果数据类型是自定义对象,请设置其名称,或者不设置任何名称.在枚举的情况下,使用'string'和allowableValues作为枚举常量.
但我没有找到一些好的Java示例如何真正使用它,规范在这里.
package betlista.tests.swagger;
import betlista.tests.swagger.model.Input;
import betlista.tests.swagger.model.Output;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
@Api(value = "first", position = 1)
public class RestServiceFirst {
@ApiOperation(value = "foo1 operation", httpMethod = "POST", position = 1, nickname = "foo")
public void foo1(Input input) {
}
@ApiOperation(value = "bar1 operation", response = Output.class, httpMethod = "GET", position = 2, nickname = "bar")
public Output bar1() {
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
package betlista.tests.swagger;
import betlista.tests.swagger.model.Input;
import betlista.tests.swagger.model.Output;
import …Run Code Online (Sandbox Code Playgroud) 我的情况如下.
我有一个招摇.json例如:http://petstore.swagger.io/v2/swagger.json 我想为上面的REST API使用生成的java客户端,例如:
PetApi petApi = new PetApi();
Pet pet = new Pet;
pet.setName("cica");
pet.setId(1L);
petApi.addPet(pet);
System.out.println(petApi.getById(1L));`
Run Code Online (Sandbox Code Playgroud)
Expexted输出:cica根据REST API实现存储新宠物.
我已使用以下命令为petstore成功生成服务器存根:
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate
-i http://petstore.swagger.io/v2/swagger.json
-l spring-mvc
-o samples/server/petstore/spring-mvc
Run Code Online (Sandbox Code Playgroud)
但是这个maven项目代码是一个服务器代码.它像注释@RequestMapping中PetApi.java,也有一个WebMvcConfiguration.class.
我不想拥有服务器存根.我想拥有一个petstore REST API的客户端库.
有没有可以为我生成适当的客户端库的工具?我应该修改服务器存根,因此它有所有模型或者我应该使用简单的springRestTemplate吗?
谢谢你的回答!
我想发布一个字符串数组
[
"id1",
"id2"
]
Run Code Online (Sandbox Code Playgroud)
基于Swagger的API.在我的招摇文件中,我有这些行:
paths:
/some_url:
post:
parameters:
- name: ids
in: body
required: true
Run Code Online (Sandbox Code Playgroud)
指定ids字符串数组的类型的正确方法是什么?
更新:
根据规范,以下应该在我的选项中工作:
parameters:
- in: body
description: xxx
required: true
schema:
type: array
items:
type: string
Run Code Online (Sandbox Code Playgroud)
https://github.com/Yelp/swagger_spec_validator不接受它,并返回一长串错综复杂的错误,看起来就像代码所期望的那样$ref.
虽然我已经看到了OpenAPI规范中的示例:
Run Code Online (Sandbox Code Playgroud)type: object additionalProperties: $ref: '#/definitions/ComplexModel'
我不明白为什么使用additionalPropertiesMap是地图/字典的正确模式.
这个规范唯一具体的内容additionalProperties也是没有用的:
以下属性取自JSON Schema定义,但其定义已调整为Swagger规范.它们的定义与JSON Schema中的定义相同,只有在原始定义引用JSON模式定义的情况下,才使用模式对象定义.
- 项目
- 所有的
- 性能
- additionalProperties
如何导出Swagger定义文件(它应该是JSON或YAML文件)?我被要求这样做,而且我对Swagger只有粗略的了解.
我们确实有一个端点http://example.com//swagger/ui/index#!看起来像这样(截图不是我们真正的端点,但我不能发布):
版本是api version: v1.
我看不到"导出"按钮.那么我该如何导出呢?
我正在尝试将Swagger添加到我的项目中。收到的错误如下。
无法使用服务容器中的服务和默认值实例化“ Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator”类型的构造函数。
由于我尚未对Swagger二进制文件本身进行任何更改,因此仅安装了软件包Swashbuckle.AspNetCore和Swashbuckle.AspNetCore.Swagger(均为4.0.1版),我假设这与配置有关。按照这里的建议,我已经设置了如下所示的配置。
services.AddSwaggerGen(_ =>
{
_.SwaggerDoc("v1", new Info { Version = "v1", Title = "My API" });
});
app.UseSwagger();
app.UseSwaggerUI(_ => { _.SwaggerEndpoint("/swagger/v1/swagger.json", "API docs"); });
Run Code Online (Sandbox Code Playgroud)
我不确定是否丢失了一个软件包,是否其中一个是错误的版本,或者我提供的设置配置是否足够。
我已将Swagger添加到Spring Boot 2应用程序中:
这是我的Swagger配置:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
// @formatter:off
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
// @formatter:on
}
}
Run Code Online (Sandbox Code Playgroud)
这是Maven依赖:
<!-- Swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
当我尝试调用例如http:// localhost:8080/api/actuator/auditevents时, 它失败并出现以下错误:
TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.
Run Code Online (Sandbox Code Playgroud)
我做错了什么以及如何解决?
swagger ×10
java ×3
swagger-2.0 ×3
c# ×2
rest ×2
swagger-ui ×2
dictionary ×1
hash ×1
mapping ×1
openapi ×1
spring-boot ×1
springfox ×1
swagger-3.0 ×1
swashbuckle ×1