我正在尝试使用swagger为具有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设置的身份验证头出现了一些问题,因为之前代码元运行得很好。
我在上面的命令中为-a选项尝试了以下组合:
-a access_token:<token>
-a "access_token":<token>
-a name:AUTHORIZATION,<token>但什么都没起作用。我今天真的遇到了麻烦。真的很感激任何快速的帮助
谢谢
发布于 2016-10-24 05:54:00
我一直在尝试同样的事情,我会张贴我认为你的问题是什么。请尝试以下格式的命令。
java -jar <Path of codegen jar>/swagger-codegen-cli.jar generate -i <path of swagger JSON>/swagger.json -l java -o <Output path>在您的命令中,我看不到"http://localhost:8080/someapi/api-docs“中的JSON文件名
如果这不起作用,这就是我所做的,使码元工作成功。
要从源代码构建Installation,需要在$PATH中安装和提供以下内容:
可以使用以下命令从源构建代码元
您还可以直接从maven.org下载JAR (最新版本)。
生成代码
您可以使用以下命令为从Swagger生成的特定JSON生成代码。
与此相关的其他详细信息可在链接https://github.com/swagger-api/swagger-codegen/blob/master/README.md#compatibility中找到。
生成的代码具有maven构建,因此代码的库依赖项是在pom.xml中指定的。
https://stackoverflow.com/questions/29537222
复制相似问题