Swagger inflector - 使用路径参数时缺少复杂对象

时间:2018-06-12 08:50:21

标签: java controller yaml swagger swagger-codegen

我正在尝试使用swagger inflector来构建web服务。但是当我使用复杂对象和路径参数时,传递给控制器​​的复杂对象是空的。我已经运行了一些测试,当我运行没有路径参数的测试时,对象被正确填充。

请查看我提供的配置。

我的YAML:

openapi: 3.0.0
info:
  title: test
  version: 0.1.0
servers:
- url: /api/rest/sites
tags:
- name: test
paths:
  /{foo}/{bar}/test:
    post:
      tags:
      - test
      operationId: test
      parameters:
      - name: foo
        in: path
        required: true
        style: simple
        explode: false
        schema:
          type: string
      - name: bar
        in: path
        required: true
        style: simple
        explode: false
        schema:
          type: string
      requestBody:
        description: Telegram body
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Bodytest'
        required: true
      responses:
        200:
          description: ContainerEmpty received successfully
        400:
          description: Invalid parameters
        500:
          description: The server can not be reached
      x-accepts: ""
      x-contentType: application/json
      x-swagger-router-controller: io.swagger.controllers.Foo_Controller
  /test2:
    post:
      tags:
      - test
      operationId: test2
      requestBody:
        description: Telegram body
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Bodytest'
        required: true
      responses:
        200:
          description: Container received successfully
        400:
          description: Invalid parameters
        500:
          description: The server can not be reached
      x-accepts: ""
      x-contentType: application/json
      x-swagger-router-controller: io.swagger.controllers.Test2Controller
components:
  schemas:
    Bodytest:
      type: object
      properties:
        uuid:
          type: string
          format: uuid
        text:
          maxLength: 10
          type: string
        bool:
          type: boolean
          default: false

两个Controller-Stub非常相似:

public class Foo_Controller  {

    public ResponseContext test(RequestContext request, String foo , String bar , Bodytest body) {
        return new ResponseContext().status(Status.INTERNAL_SERVER_ERROR).entity( "Not implemented" );
    }
}

public class Test2Controller  {

    public ResponseContext test2(RequestContext request , Bodytest body ) {
        return new ResponseContext().status(Status.INTERNAL_SERVER_ERROR).entity( "Not implemented" );
    }
}

当我发送时:

POST http://localhost:8080/sites/test2
{"uuid":"550e8400-e29b-11d4-a716-446655440010","text":"1234567890", "bool":false}

一切正常:

10:31:20.167 [qtp1497992596-14] INFO  i.s.o.i.c.OpenAPIOperationController - calling method public io.swagger.oas.inflector.models.ResponseContext io.swagger.controllers.Test2Controller.test2(io.swagger.oas.inflector.models.RequestContext,io.swagger.model.Bodytest) on controller io.swagger.controllers.Test2Controller@339aee45 with args [io.swagger.oas.inflector.models.RequestContext@6732c6c5, class Bodytest {
    uuid: 550e8400-e29b-11d4-a716-446655440010
    text: 1234567890
    bool: false
}]

另一方面:

POST http://localhost:8080/sites/fooo/barr/test
{"uuid":"550e8400-e29b-11d4-a716-446655440010","text":"1234567890", "bool":false}

没有:

10:34:42.282 [qtp1497992596-17] INFO  i.s.o.i.c.OpenAPIOperationController - calling method public io.swagger.oas.inflector.models.ResponseContext io.swagger.controllers.Foo_Controller.test(io.swagger.oas.inflector.models.RequestContext,java.lang.String,java.lang.String,io.swagger.model.Bodytest) on controller io.swagger.controllers.Foo_Controller@93f9802 with args [io.swagger.oas.inflector.models.RequestContext@4ad670ca, fooo, barr, null]

复杂对象为null。 我是否遗漏了某些东西或者是否存在inflector和openapi 3的问题。

0 个答案:

没有答案