Swagger Codegen 在为具有 OAuth2.0 安全性的 Rest API 生成 Java 客户端时不起作用 [英] Swagger Codegen is not working while generating java client for a Rest API having OAuth2.0 security

查看:64
本文介绍了Swagger Codegen 在为具有 OAuth2.0 安全性的 Rest API 生成 Java 客户端时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 swagger codegen 为具有 OAuth 2.0 安全性的 REST Api 生成客户端.电话如下:

I am trying to generate a client using swagger codegen for a REST Api having OAuth 2.0 security. The call is following:

    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

但是此调用不起作用并生成以下输出:

But this call is not working and generating the following output as:

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 设置的身份验证标头存在一些问题,因为之前代码生成器运行良好.

I have implemented recently the OAuth2.0 for this API so I assume that there is some problem with the authentication header I am setting with this APi as earlier the codegen was working well.

我为上述命令中的 -a 选项尝试了以下组合:

The following combinations I have tried for the -a option in the above command:

 -a access_token:<token>
 -a "access_token":<token>
 -a name:AUTHORIZATION,<token>

但是没有任何效果.我今天的演示真的很麻烦.非常感谢任何快速帮助

But nothing is working. I am really in trouble with a demo today. Really appreciate any quick help

谢谢

推荐答案

我自己一直在尝试同样的事情,我会发布我认为您的问题所在.请尝试以下格式的命令.

I have been trying the same thing myself and I will post what I think your issue is. Please try the command in the format given below.

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 中没有看到 JSON 文件名/api-docs"

如果这在这里不起作用,这是我为使代码生成成功工作所做的工作.

If this does not work here is what I did to make the codegen work sucessfully.

安装要从源代码构建,您需要在 $PATH 中安装并提供以下内容:

Installation To build from source, you need the following installed and available in your $PATH:

  • Java 7 或 8
  • Apache maven 3.3.3 或更高版本

以下命令可用于从源代码构建代码生成

The following commands can be used to build the codegen from the source

您也可以直接从 maven.org 下载 JAR(最新版本)

You can also download the JAR (latest release) directly from maven.org

生成代码

您可以使用以下命令为从 Swagger 编辑器生成的特定 JSON 生成代码.

You can generate the code for a particular JSON that you generated from the Swagger Editor using the following command.

  • java -jar/swagger-codegen-cli.jar generate -i/swagger.json -l java -o

与此相关的其他详细信息可以在链接 https://github.com/swagger-api/swagger-codegen/blob/master/README.md#compatibility

Additional details in relation to this can be found in the link https://github.com/swagger-api/swagger-codegen/blob/master/README.md#compatibility

生成的代码有maven build,所以在pom.xml中指定了代码的库依赖.

The generated code has a maven build, so the library dependencies of the code is specified in the pom.xml.

这篇关于Swagger Codegen 在为具有 OAuth2.0 安全性的 Rest API 生成 Java 客户端时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆