Skip to content

[BUG] go-server and go-gin-server missing required field in generated source code #10429

Description

@SamuelLabrador

When defining a requestBody, the models for the generated server stubs do not enforce the required attribute for properties. When I tried it out, it didn't work for the go-server and go-gin-server generators.

ie:

...
requestBody:
  required: true
  content:
    application/json:
      schema:
        title: createAccountRequestBody
        type: "object"
        properties:
          username:
            description: "The user's username"
            type: string
          email:
            description: "The user's email"
            type: string
          password:
            description: "The user's password"
            type: string
        required:
          - username
          - email
          - password
...

I took a look at the model.mustache file and it looks like the properties field are missing the binding:"required" within the structs.

The line in the go-gin-server model.mustache file:

25: ... `json:"{{baseName}}{{^required}},omitempty{{/required}}" ...

What I think the expected line should be:

25: ... `json:"{{baseName}}{{^required}},omitempty"{{/required}}{{required}} binding:"required"{{/required}}" ...

I'm not too familiar with Go, but failure expected? I would think we would want a more strict validator. If this is not expected behavior, I can try to help out and open up a PR.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions