Swagger-Codegen生成的是一个空的类,而不是一个ByteArrayOutputStream实例。

huangapple go评论148阅读模式
英文:

Swagger-Codegen generates empty class instead of an instance of ByteArrayOutputStream

问题

以下是翻译好的内容:

我目前正在尝试使用swagger-codegen生成API。唯一的问题是swagger生成了一个名为"ByteArrayOutputStream"的空类,而不是一个ByteArrayOutputStream的实例。生成的类还没有任何属性。

生成的swagger-yaml还像这样定义了ByteArrayOutputStream:

  ByteArrayOutputStream:
    type: "object"

这是swagger.yaml的相关部分。我已经用"..."替换了一些值并缩短了文件。

---
swagger: "2.0"
info:
  version: "1.0"
  title: "..."
  contact:
    name: "..."
    url: "..."
host: "..."
basePath: "/"
schemes:
- "https"
paths:
  /rest/v1/pkw:
    post:
      summary: "..."
      description: ""
      operationId: "..."
      produces:
      - "application/json"
      parameters:
      - in: "body"
        name: "body"
        required: false
        schema:
          $ref: "#/definitions/Request"
      responses:
        200:
          description: "操作成功"
          schema:
            $ref: "#/definitions/Result"
definitions:
  ByteArrayOutputStream:
    type: "object"
  Request:
    ...
  Result:
    type: "object"
    properties:
      ...
      pdf:
        $ref: "#/definitions/ByteArrayOutputStream"
英文:

I'm currently trying to generate an api with swagger-codegen. The only problem i have is that swagger generates an empty class with the name "ByteArrayOutputStream" instead of an instance of ByteArrayOutputStream. The generated class also contains no attributes.

The generated swagger-yaml also defines ByteArrayOutputStream like this:

  ByteArrayOutputStream:
    type: "object"

This is the relevant part of the swagger.yaml. I've replaced some of the values with "..." and shortened the file.

---
swagger: "2.0"
info:
  version: "1.0"
  title: "..."
  contact:
    name: "..."
    url: "..."
host: "..."
basePath: "/"
schemes:
- "https"
paths:
  /rest/v1/pkw:
    post:
      summary: "..."
      description: ""
      operationId: "..."
      produces:
      - "application/json"
      parameters:
      - in: "body"
        name: "body"
        required: false
        schema:
          $ref: "#/definitions/Request"
      responses:
        200:
          description: "successful operation"
          schema:
            $ref: "#/definitions/Result"
definitions:
  ByteArrayOutputStream:
    type: "object"
  Request:
    ...
  Result:
    type: "object"
    properties:
      ...
      pdf:
        $ref: "#/definitions/ByteArrayOutputStream"



</details>


# 答案1
**得分**: 0

更新:
我已经更改了我的API,并且用字符串替换了ByteArrayOutputStream。我使用Base64编码和解码来实现这一点。这帮助我避免了问题,而且运行良好。

<details>
<summary>英文:</summary>

Update:
I&#39;ve changed my api and replaced ByteArrayOutputStram by a String. I use Base64 encoding and decoding to do so. This helped me avoid the problems and works fine.

</details>



# 答案2
**得分**: 0

发生这种情况是在你使用它时。你只需覆盖那个类,你的问题就会解决。

祝好。

<details>
<summary>英文:</summary>

That&#39;s happen when you use it. You just have to overrides that class and your problem will fix.

Regards.

</details>



huangapple
  • 本文由 发表于 2020年10月27日 17:05:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/64551123.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定