You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Go does not support adding default values for required variables when only one value is possible.
Describe the solution you'd like
The proposed solution is to add a configuration variable: initRequiredVars.
When initRequiredVars is set to true, and the response JSON lacks values for the required variables or the user hasn't provided values for the required variables, the system should automatically assign default values to these variables if only a single value is possible. If multiple values are possible for the required variables, default values should not be assigned.
For Example, consider the following snippet from the specification file:
As we can see in the above case Dog class contain required property className. Now if we will not specify the className in Dog class as payload and when the payload will be validated will throw an error.
Error:
package main
import (
"encoding/json"
"fmt"
)
// Define the Legs struct
type Legs struct {
Legs string `json:"legs"`
Name string `json:"name,omitempty"`
}
// Define the Dog struct
type Dog struct {
ClassName string `json:"className"`
Breed string `json:"breed"`
Legs Legs `json:"legs"`
Color string `json:"color"`
Run bool `json:"run"`
}
func main() {
legs := Legs{
Legs: "4",
}
dogInstance := Dog{
Breed: "Bulldog",
Legs: legs,
Color: "Black",
Run: true,
}
// Print the dog instance directly
dogJson, _ := json.Marshal(dogInstance)
fmt.Println(string(dogJson))
}
Describe alternatives you've considered
Additional context
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
Go does not support adding default values for required variables when only one value is possible.
Describe the solution you'd like
The proposed solution is to add a configuration variable: initRequiredVars.
When initRequiredVars is set to true, and the response JSON lacks values for the required variables or the user hasn't provided values for the required variables, the system should automatically assign default values to these variables if only a single value is possible. If multiple values are possible for the required variables, default values should not be assigned.
For Example, consider the following snippet from the specification file:
As we can see in the above case Dog class contain required property className. Now if we will not specify the className in Dog class as payload and when the payload will be validated will throw an error.
Error:
Code:
Describe alternatives you've considered
Additional context
The text was updated successfully, but these errors were encountered: