【发布时间】:2016-10-24 13:54:00
【问题描述】:
我正在尝试使用 swagger codegen 为具有 OAuth 2.0 安全性的 REST Api 生成客户端。电话如下:
E:\>java -jar swagger-codegen-distribution-2.1.2-M1.jar -a access_token:df8eb092-e34f-48f9-b4ce-32cdd1ae2613 -i http://localhost:8080/someapi/api-docs -l java -o E:\projects\prototypes\ApiClient
但此调用不起作用并生成以下输出:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
reading from http://localhost:8080/someapi/api-docs
reading from http://localhost:8080/someapi/api-docs
usage: Codegen
-a,--auth addes authorization headers when fetching the
swagger definitions remotely. Pass in a
URL-encoded string of name:header with a comma
separating multiple values
-d,--debug-info prints additional info for debugging
-h,--help shows this message
-i,--input-spec <arg> location of the swagger spec, as URL or file
-l,--lang <arg> client language to generate.
Available languages include:
[android, async-scala, java, jaxrs, nodejs,
objc, scalatra, scala, dynamic-html, html,
swagger, tizen, php, python]
-o,--output <arg> where to write the generated files
-t,--template-dir <arg> folder containing the template files
我最近为此 API 实现了 OAuth2.0,因此我认为我使用此 API 设置的身份验证标头存在一些问题,因为之前的 codegen 运行良好。
我为上述命令中的 -a 选项尝试了以下组合:
-a access_token:<token>
-a "access_token":<token>
-a name:AUTHORIZATION,<token>
但没有任何效果。 我今天的演示真的很麻烦。非常感谢任何快速帮助
谢谢
【问题讨论】:
-
您的意思是您需要 OAuth2 授权才能访问 Swagger 定义,还是您的 Swagger 定义包含用于操作的 OAuth2 安全性?
-
我想我需要 Oauth2 授权才能访问 API 的 Swagger 定义
-
我认为这不是授权问题。对于输出,尝试在当前目录下给它一个路径,看看是否有效。
标签: java rest oauth-2.0 swagger