Skip to content

Do not add validation rules for optional attributes#732

Open
erlendnils1 wants to merge 1 commit into
mainfrom
validation_rules_optional_attributes
Open

Do not add validation rules for optional attributes#732
erlendnils1 wants to merge 1 commit into
mainfrom
validation_rules_optional_attributes

Conversation

@erlendnils1

Copy link
Copy Markdown
Contributor

Optional xsd attributes will currently generate protovalidate rules as if they are mandatory.

For instance:
<attribute name="srsDimension" type="positiveInteger"/>

generates the following proto definition:

uint32 srs_dimension = 22 [
  (buf.validate.field).uint32.gt = 0
];

As xsd attributes are default optional the xml will allow omitting srsDimension. The proto schema will, however, require a positive integer value. It should allow omitting the field / specifying 0.

TODO:
How should this be handled? Current impl simply ignores optional attributes. We could probably create separate rule mappings for required/non required, ie mapping "postiveInteger"+required -> (buf.validate.field).uint32.gt = 0 and "postiveInteger"+non required -> (buf.validate.field).uint32.gte = 0 .

The validation annotation generation does, however, seem quite unfinished in it's current state. For elements it is completely disabled (by if (false && configuration.includeValidationRules) { // TODO SKIP FOR NOW AS RULES ARE NOT COMPILING)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant