Skip to content
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

Failing of validation tag "required" on int, bool and string type fields #37

Open
samechelon opened this issue Dec 4, 2017 · 4 comments
Labels

Comments

@samechelon
Copy link
Collaborator

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 6f23992 removing the required validation tag

@samechelon
Copy link
Collaborator Author

Service provider config has plenty of bool type fields with the validation tag "required" on

@samechelon samechelon changed the title Validation tag "required" on bool type fields Failing of validation tag "required" on int, bool and string type fields Dec 5, 2017
@samechelon
Copy link
Collaborator Author

samechelon commented Dec 5, 2017

Fields that can fail on validation tag "required"

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

@leodido
Copy link
Collaborator

leodido commented Jan 10, 2018

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.

@leogr
Copy link
Collaborator

leogr commented Jan 10, 2018

@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.

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

No branches or pull requests

3 participants