代码之家  ›  专栏  ›  技术社区  ›  Stéphane GRILLON

swager codegen maven插件2.3.1生成响应自定义对象,但不在3.0.0中

  •  -1
  • Stéphane GRILLON  · 技术社区  · 7 年前

    Saviger-Corden Maven插件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插件3.0.0-snapshot 不是 生成JavaObjt并返回对象对象:

    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“对象”

    1 回复  |  直到 7 年前
        1
  •  0
  •   Stéphane GRILLON    7 年前

    3.0.0-snapshot有一个v2模型的bug。我们需要使用Swagger codegen maven插件的2.3.1版。

    在我的例子中,我有两个模型(一个V2和一个V3)。儿子,我用3个模块(源生成器v2、源生成器v3和我的项目)创建了一个Maven父级。

    mvn clean install 关于我的父母和我的项目没有问题。