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.
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 thego-serverandgo-gin-servergenerators.ie:
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:
What I think the expected line should be:
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.