如果已经回答了这个问题,我深表歉意,但我找不到明确的答案。
目前的生成器支持认证吗?
我需要生成一个具有两种潜在身份验证方式的客户端:
api_token参数。如果有,我该如何使用它?
如果没有,您认为在生成客户端后添加身份验证的最佳方法是什么?
我有以下api文档:
swagger: "3.0"
info:
version: 0.0.1
title: Test API
paths:
/users:
get:
summary: Get all registered users
produces:
- application/json
responses:
200:
description: Users successfully returned
403:
description: User not authorised to call this API
schema:
$ref: 'components.yaml#/components/schemas/AuthError'
Run Code Online (Sandbox Code Playgroud)
其中 AuthError 架构是在名为 Components.yaml 的单独 yaml 文件中定义的:
components:
schemas:
AuthError:
type: object
properties:
error:
type: sting
description: Error message
Run Code Online (Sandbox Code Playgroud)
以及 Swagger 配置:
const swaggerDefinition = {
info: {
title: 'FlexiWAN REST API documentation',
version: '1.0.0',
description: 'This is the REST API for …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 NSwag CLI 在 .NET Core 和 TypeScript 中生成客户端代码:
nswag run options.nswag
Run Code Online (Sandbox Code Playgroud)
这适用于各种 Swagger 2.0 JSON 文件,但会为 OpenApi 3.0 JSON 文件生成多个具有完全相同名称的函数。
我的 options.swag 文件具有以下 .NET 内容(TypeScript 以类似的方式生成并遇到相同的问题):
{
"runtime": "NetCore21",
"defaultVariables": null,
"documentGenerator": {
"fromDocument": {
"url": "https://somedomain.com/openapi.json",
"output": null
}
},
"codeGenerators": {
"openApiToCSharpClient": {
"clientBaseClass": null,
"configurationClass": null,
"generateClientClasses": true,
"generateClientInterfaces": false,
"injectHttpClient": true,
"disposeHttpClient": true,
"protectedMethods": [],
"generateExceptionClasses": true,
"exceptionClass": "ClientApiException",
"wrapDtoExceptions": true,
"useHttpClientCreationMethod": false,
"httpClientType": "System.Net.Http.HttpClient",
"useHttpRequestMessageCreationMethod": false,
"useBaseUrl": true,
"generateBaseUrlProperty": true,
"generateSyncMethods": false,
"exposeJsonSerializerSettings": false, …Run Code Online (Sandbox Code Playgroud) 我从 Springfox Swagger 迁移到 Springdoc OpenApi。我在有关 springdoc 的配置中添加了几行:
springdoc:
pathsToMatch: /api/**
api-docs:
path: /api-docs
swagger-ui:
path: /swagger-ui.html
Run Code Online (Sandbox Code Playgroud)
在配置类中MainConfig.kt我有以下代码:
val customGson: Gson = GsonBuilder()
.registerTypeAdapter(LocalDateTime::class.java, DateSerializer())
.registerTypeAdapter(ZonedDateTime::class.java, ZonedDateSerializer())
.addSerializationExclusionStrategy(AnnotationExclusionStrategy())
.enableComplexMapKeySerialization()
.setPrettyPrinting()
.create()
override fun configureMessageConverters(converters: MutableList<HttpMessageConverter<*>>) {
converters.add(GsonHttpMessageConverter(customGson))
}
Run Code Online (Sandbox Code Playgroud)
当我访问 http://localhost:8013/swagger-ui.html (在我的配置中server.port: 8013)时,页面不会重定向到swagger-ui/index.html?url=/api-docs&validatorUrl=. 但这不是我的主要问题:)。当我访问时,swagger-ui/index.html?url=/api-docs&validatorUrl=我得到了包含以下信息的页面:
无法呈现此定义 提供的定义未指定有效的版本字段。 请指明有效的 Swagger 或 OpenAPI 版本字段。支持的版本字段包括 swagger: "2.0" 和那些匹配 openapi: 3.0.n 的字段(例如 openapi: 3.0.0)。
但是当我访问 http://localhost:8013/api-docs 时,我得到了这个结果:
"{\"openapi\":\"3.0.1\",\"info\":{(...)}}"
Run Code Online (Sandbox Code Playgroud)
我尝试使用默认配置,并评论了configureMessageConverters()方法,结果\api-docs现在看起来像正常的 JSON:
Unable to render this …
React -admin 主页显着地显示了 OpenAPI(以前称为 Swagger)徽标,但我在列表或 GitHub 上找不到相关的数据提供程序。最好使用ra-data-simple-rest和扩展它,还是我遗漏了一些东西,是否有一个现成的适配器可以解析 OpenAPI 规范文件?
我目前正在开发一个使用 Spring 函数式 Web 编程的项目。我通常在restController中使用swagger 2的注释,但是对于功能性Web编程我找不到在哪里!告诉应用程序搜索端点(如 Docket 中的 basepackage)并在 html 页面中加载 swagger 的位置。这是我的代码:
@Configuration
public class RouterClient{
@Bean
public RouterFunction<ServerResponse> routes(ClientHandler client){
return route(GET("/api/client"), client::findAll)
.andRoute(POST("/api/client"),client::add);
}
}
Run Code Online (Sandbox Code Playgroud)
配置类:
@Configuration
public class OpenApiConfiguration{
@Bean
public GroupedOpenApi groupOpenApi() {
String paths[] = {"/api/**"};
String packagesToscan[] = {"com.demo.client"};
return GroupedOpenApi.builder().setGroup("groups").pathsToMatch(paths).packagesToScan(packagesToscan)
.build();
}
}
Run Code Online (Sandbox Code Playgroud)
依赖项:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-webflux-core</artifactId>
<version>1.2.32</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-webflux-ui</artifactId>
<version>1.2.32</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
结果 :
我正在使用 Swagger Codegen 3.0.19,还尝试了 OpenAPI Generator 4.0.3。
Java环境:
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
Run Code Online (Sandbox Code Playgroud)
跑步者:
java -jar ./libs/openapi-generator-cli-4.3.0.jar generate \
-i pet.yaml \
-g spring \
-o ./OUTPUT/api/
Run Code Online (Sandbox Code Playgroud)
这是我的 OpenAPI 架构:
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
Run Code Online (Sandbox Code Playgroud)
输出是:
java -jar ./libs/openapi-generator-cli-4.3.0.jar generate \
-i pet.yaml \
-g spring \
-o ./OUTPUT/api/
Run Code Online (Sandbox Code Playgroud)
为什么代码生成器将 ON/OFF 枚举转换为 TRUE/FALSE?当我使用 Swagger Editor GUI 生成时,它不会执行此操作。
我正在尝试为 OpenAPI 3.0 规范中的响应创建链接。更具体地说,我想提供我的响应之一与其他可用操作之间的已知关系(参见Link Object)。
在我的 Spring Boot 项目中,我使用 Springdoc(版本:1.3.9)来生成 API 文档。根据@ApiResponse#links文档,我尝试使用以下端点代码来实现我的目标:
@GetMapping(value = "/avatar", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Request avatar info", operationId = "requestAvatar")
@ResponseStatus(HttpStatus.OK)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK", links = {
@Link(name = "Download Avatar", operationId = "downloadAvatar",
parameters = {
@LinkParameter(name = "userId"),
@LinkParameter(name = "uuid")
})
}),
...
@ResponseBody
ResponseEntity<Avatar> requestAvatar();
Run Code Online (Sandbox Code Playgroud)
不幸的是,除了“无链接”描述之外,我在 Swagger UI 中看不到任何结果。
检查生成的 JSON 规范后,我也没有找到APIlinks的任何密钥requestAvatar。
我在创建过程中是否遗漏了某些内容,@Link或者 …
我使用以下 OpenAPI 命令来使用openapi-generator生成客户端:
npx @openapitools/openapi-generator-cli generate -i api.yaml -g cpp-restsdk -o %CD%
Run Code Online (Sandbox Code Playgroud)
运行命令后为什么会显示以下警告:
[main] WARN o.o.codegen.DefaultCodegen - The value (generator's option) must be either boolean or string. Default to `false`.
Run Code Online (Sandbox Code Playgroud) 是否可以以某种方式模板化 oauth2 安全方案的基本路径authorizationUrl来tokenUrl处理多个环境(例如 dev、sit、uat)?
我工作的公司每个环境都有一个单独的 IDP 租户,每个环境中的服务将针对特定租户/发行者验证令牌。
理想情况下,我可以定义和选择租户基本 URL,类似于我为 API 路由创建服务器模板的方式 - 请参阅此处。

我的securitySchemes目前看起来像这样:
"securitySchemes": {
"oauth": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://tenant-dev.au.auth0.com/authorize?audience=test",
"tokenUrl": "https://tenant-dev.au.auth0.com/oauth/token"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,我能想到的唯一多环境方法是使用以下安全方案配置,它允许我指定任何 JWT。缺点是我仍然需要通过一些外部手段获取 JWT...
"securitySchemes": {
"oauth": {
"type": "http",
"scheme": "bearer",
"bearerFormat": "JWT"
}
}
Run Code Online (Sandbox Code Playgroud)
笔记;
openapi ×10
spring-boot ×3
swagger ×3
swagger-ui ×2
gson ×1
java ×1
kotlin ×1
nswag ×1
react-admin ×1
springdoc ×1
swagger-2.0 ×1
swagger-3.0 ×1
yaml ×1