Open samechelon opened 6 years ago
Service provider config has plenty of bool type fields with the validation tag "required" on
Will fail in this cases:
int field = 0
string field = " "
bool field = false
Schema has no fields with the validation tag "required" on int, bool or string fields
Service Provider Config
type patch struct {
Supported bool `json:"supported" validate:"required"`
}
type bulk struct {
Supported bool `json:"supported" validate:"required"`
MaxOperations int `json:"maxOperations" validate:"required"`
MaxPayloadSize int `json:"maxPayloadSize" validate:"required"`
}
type filter struct {
Supported bool `json:"supported" validate:"required"`
MaxResults int `json:"maxResults" validate:"required"`
}
type changePassword struct {
Supported bool `json:"supported" validate:"required"`
}
type sort struct {
Supported bool `json:"supported" validate:"required"`
}
type etag struct {
Supported bool `json:"supported" validate:"required"`
}
type authenticationScheme struct {
Type string `json:"type" validate:"required,eq=oauth|eq=oauth2|eq=oauthbearertoken|eq=httpbasic|eq=httpdigest"`
Name string `json:"name" validate:"required"`
Description string `json:"description" validate:"required"`
Resource Type
type SchemaExtension struct {
Schema string `json:"schema" validate:"urn,required"`
Required bool `json:"required" validate:"required"`
}
type ResourceType struct {
CommonAttributes
Name string `json:"name" validate:"required"`
Endpoint string `json:"endpoint" validate:"startswith=/,required"`
Schema string `json:"schema" validate:"urn,required"`
Common
type Meta struct {
Location string `json:"location" validate:"uri,required"`
ResourceType string `json:"resourceType" validate:"required"`
type CommonAttributes struct {
Schemas []string `json:"schemas" validate:"gt=0,dive,urn,required"`
// Common attributes
ID string `json:"id" validate:"excludes=bulkId,required"`
cc @leogr
I have removed the "required" validators for boolean fields of ServiceProviderConfig
.
What to expect when a configuration JSON file misses the required fields?
These fields will contain false values (the null values for booleans in golang).
This is not a problem in the case of ServiceProviderConfig
since its is read-only and it'll be used only at server boot time.
@leodido I agree. Because the different usage context (Structured Resource will be not modified by any external APIs call) we don't need that validation strictly follows RFCs. Currently won't fix, then we can double check and close this issue.
With validation tag "required" on bool type fields if you don't give that field value true, the test using
Validator.Struct()
it will return this error :'ResourceType.SchemaExtensions[0].Required' Error:Field validation for 'Required' failed on the 'required' tag
Fixed temporarily 6f23992e968406bf5558846e9d057b815075e08e removing the required validation tag