Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
SamuelLabrador opened this issue Sep 20, 2021 · 0 comments

Comments

@SamuelLabrador
Copy link

SamuelLabrador commented Sep 20, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant