如何从OpenAPI 3 Swagger源代码生成的Java代码中修复缺少的查询对象反序列化/解组函数

时间:2019-05-17 11:01:03

标签: java swagger openapi codegen


你好
在使用Swagger时,我是个新手。
但是我不是使用代码生成器的新手。我什至为不同的公司创建了其中的一些。

首先,我创建了一个可复制的示例Swagger文件,供您了解我的问题(见下文)。

openapi: "3.0.0"
info:
  title: Example for the not work swagger (de)serialization.
  version: 1.0.0
  license:
    name: No license
    url: https://choosealicense.com/no-permission/
servers:
  - url: http://localhost:9080/example
paths:
  /search:
    get:
      operationId: searchIt
      parameters:
      - name: q
        in: query
        description: >-
          A search object as one query paramater which was (de)serialized to/from
          the url als the simple types. Like described in
          "https://swagger.io/docs/specification/serialization/#query"
        required: true
        style: form
        explode: true
        schema:
          $ref: '#/components/schemas/SearchQuery'
      responses:
        200:
          description: A mandantory description.
          content:
            text/plain:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/SearchResult'
components:
  schemas:
    SearchQuery:
      type: object
      properties:
        start:
          type: string
        limit:
          type: integer
          format: int32
        FOO:
          type: string
        BAR:
          type: string
    SearchResult:
      type: object
      required:
        - entries
        - next
      properties:
        entries:  
          type: array
          items:
            $ref: '#/components/schemas/Entry'
        next:
          type: string
    Entry:
      type: object
      properties:
        id:  
          type: integer
        foo:
          type: string
        baz:
          type: string
      required:
      - id

如果将其上传到online Swagger editor,则看不到任何错误,警告或问题。如果现在在此编辑器中模拟对端点的调用(试用),则必须输入 search 值作为Json对象。进行更改并执行后,您将看到生成的URL:

http://localhost:9080/example/search?start=string&limit=0&FOO=string&BAR=string

表明编辑器可以序列化查询对象。

到目前为止,一切都很好,这意味着没有问题。

真的吗?

如果现在让我们生成一个“ jaxrs-jersey”服务器,下载生成的zip文件并通过mvn package jetty:run运行生成的演示,您将得到一个 ModelValidationException 。忽略此警告并不是一个好主意,因为如果您在信任的浏览器中输入上述网址,则会得到一个HTTP 503
生成的Java客户端显示出类似的缺点。

嗯...

此刻,经过我的整个调查(例如询问像这样的大哥和平台)之后,我怀疑在代码生成器中实现反序列化功能只是被遗忘了。或者,也许只是忘记生成正确的注释。但我希望不是。

有人知道,我如何使用代码生成器解决问题?
这主要意味着,在上述Swagger文件中我必须更改的内容是代码生成器可以在其中进行(全部)工作。或者也许认识其他可以处理上述Swagger文件的Java代码生成器。

谢谢。

0 个答案:

没有答案