Search code examples
goopenapiopenapi-generatoropenapi-generator-cli

Openapi Generator Minimum Maximum Range integer Go


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?


Solution

  • 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.