OpenAPI生成器最小最大范围整数Go

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

Openapi Generator Minimum Maximum Range integer Go

问题

我有一个使用OpenAPI Generatoropenapi: "3.0.3"的Go项目。

我正在尝试使用minimummaximum范围来实现对int64请求体变量的错误验证。我认为这种类型的验证可以在生成的控制器中进行。例如,类似于AssertPetRequired示例中的某个位置。我查看了controller-api.mustache文件,但没有找到有用的内容。我的POST请求体如下所示(我尝试了关于minimum、maximum、exclusiveMinimum和exclusiveMaximum的所有组合)。

requestBody:
    required: true
    content:
      application/json:
        schema:
          type: object           
          properties:
            id:
              type: string
            amount:
              type: integer
              format: int64
              minimum: 1
              exclusiveMinimum: true
              maximum: 10
              exclusiveMaximum: true
            label:
              type: string
          required:
            - id
            - amount

我是否需要添加其他库,或者我在我的yaml文件中漏掉了一些基本内容?

英文:

I have a go project using the OpenAPI Generator with openapi: "3.0.3".

I am attempting to implement error validation using a minimum and maximum range for an int64 request body variable. I would think that this type of validation could happen within the generated controllers. For example, somewhere like the AssertPetRequired example. I looked through the controller-api.mustache file and do not see anything helpful. My post request body looks like the following (I’ve tried every combination I can think of for: minimum, maximum, exclusiveMinimum and exclusiveMaximum.

requestBody:
    required: true
    content:
      application/json:
        schema:
          type: object           
          properties:
            id:
              type: string
            amount:
              type: integer
              format: int64
              minimum: 1
              exclusiveMinimum: true
              maximum: 10
              exclusiveMaximum: true
            label:
              type: string
          required:
            - id
            - amount

Is there some additional library that I need to add or am I missing something basic within my yaml file?

答案1

得分: 1

我假设你正在生成一个Go服务器,而不是一个Go客户端

不幸的是,Go服务器生成器目前还不支持验证功能。但是这个功能已经计划在7.0.0版本中实现,该版本计划于2023年6月发布。

英文:

I assume you are generating a go server, not a go client.

Unfortunately, the go server generators don't support validations yet. But this feature is planned for the 7.0.0 release, which is scheduled for June 2023.

huangapple
  • 本文由 发表于 2023年3月29日 22:24:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/75878538.html
匿名

发表评论

匿名网友

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

确定