【问题标题】:swagger-codegen-maven-plugin 2.3.1 generate response custom object but not in 3.0.0swagger-codegen-maven-plugin 2.3.1 生成响应自定义对象但不在 3.0.0 中
【发布时间】:2018-07-12 13:11:05
【问题描述】:

swagger-codegen-maven-plugin 2.3.1 生成java对象:

public InlineResponse2005 loginJsonapiPost(Auth auth) throws RestClientException { ...

public class InlineResponse2005 {
  @JsonProperty("data")
  private User data = null;
  @JsonProperty("meta")
  private Object meta = null;
  @JsonProperty("links")
  private Object links = null;
  @JsonProperty("errors")
  private Errors errors = null;
  ...
}

但是 swagger-codegen-maven-plugin 3.0.0-SNAPSHOT NOT 生成 java 对象并返回 Object 对象:

public Object loginJsonapiPost(Object body) throws RestClientException { ...

我的招摇文件:

"/login.jsonapi": {
      "post": {
        "summary": "Create a session",
        "tags": [
          "Users"
        ],
        "consumes": [
          "application/json"
        ],
        "description": "      Authenticate a user with her/his email and password and return an\n      access token suitable for authentication.\n",
        "parameters": [
          {
            "name": "auth",
            "in": "body",
            "schema": {
              "type": "object",
              "properties": {
                "email": {
                  "type": "string"
                },
                "password": {
                  "type": "string"
                }
              }
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Returning",
            "schema": {
              "type": "object",
              "properties": {
                "data": {
                  "$ref": "#/definitions/user"
                },
                "meta": {
                  "type": "object"
                },
                "links": {
                  "type": "object"
                },
                "errors": {
                  "$ref": "#/definitions/errors"
                }
              },
              "required": [
                "data"
              ]
            }
          },
          "422": {
            "description": "Returning",
            "schema": {
              "type": "object",
              "properties": {
                "errors": {
                  "$ref": "#/definitions/errors"
                }
              },
              "required": [
                "errors"
              ]
            }
          }
        }
      }
    },

我的回答是:

responses.schema.properties.data "#/definitions/user"

responses.schema.properties.meta“对象”

responses.schema.properties.links“对象”

responses.schema.properties.errors "#/definitions/errors"

【问题讨论】:

    标签: java maven swagger


    【解决方案1】:

    3.0.0-SNAPSHOT 有一个 V2 模型的错误。我们需要使用 swagger-codegen-maven-plugin 的 V2.3.1。

    就我而言,我有 2 个模型(一个 V2 和一个 V3)。儿子我用 3 个模块(源生成器 V2、源生成器 V3 和我的项目)创建了一个 Maven 父级。

    我在我的父母上mvn clean install,我的项目没有问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-15
      • 2020-04-05
      • 1970-01-01
      • 2022-10-20
      • 1970-01-01
      • 2021-06-27
      • 2023-03-04
      • 1970-01-01
      相关资源
      最近更新 更多