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

Bug 1472226 - Add additional field validations for JSON Schema. #615

Merged
merged 2 commits into from Jan 10, 2018
Merged

Bug 1472226 - Add additional field validations for JSON Schema. #615

merged 2 commits into from Jan 10, 2018

Conversation

cfchase
Copy link
Contributor

@cfchase cfchase commented Jan 5, 2018

Updated apb spec to allow for more validations from JSON Schema.
https://datatracker.ietf.org/doc/draft-handrews-json-schema-validation/

Validations follow JSON schema keywords, and uses snake_case instead of camelCase for consistency when writing APBs

Added apb_field (JSON schema field):

  • max_length (maxLength)
  • min_length (minLength)
  • multiple_of (multipleOf)
  • minimum (minimum)
  • maximum (maximum)
  • exclusive_minimum (exclusiveMinimum)
  • exclusive_maximum (exclusiveMaximum)

Allow maxlength to be used for backwards compatibility as DeprecatedMaxlength.
Allowed type: integer since it's used in JSON schema

@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 5, 2018
@coveralls
Copy link

coveralls commented Jan 5, 2018

Coverage Status

Changes Unknown when pulling 20d0822 on cfchase:param-validation into ** on openshift:master**.

@cfchase cfchase requested a review from jmrodri January 5, 2018 19:19
if min, ok := pd.Minimum.(float64); ok {
prop.Minimum = schema.Number{Val: min, Initialized: true}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the JSON schema validations documentation, exclusiveMinimum and exclusiveMaximum MUST be a number. However go-jsschema and the serialized values it sends uses boolean values for exclusiveMaximum and exclusiveMinimum are boolean and use the numbers in maximum and minimum.

I followed with the docs and used exclusive_maximum/exclusive_minimum as a number for the APB spec, but if there are strong opinions that I should use boolean exclusive_maximum/exclusive_minimum instead, I'd like to hear reasoning. I was divided myself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with following the docs. exclusive_maximum representing the max number seems intuitive to me.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling a8c4117 on cfchase:param-validation into ** on openshift:master**.

Copy link
Member

@dymurray dymurray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks sane to me! +1 for adding integer to the case statements. That's bitten others :)

Copy link
Contributor

@shawn-hurley shawn-hurley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except this bit. Would like to start a discussion on this point.

pkg/apb/types.go Outdated

// number validators
MultipleOf float64 `json:"multipleOf,omitempty" yaml:"multiple_of,omitempty"`
Maximum interface{} `json:"maximum,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the loss of type validation if someone is creating a ParameterDescription by hand. If we can make this not exported I would be much less worried about it.

This is another way around this. Using a type declaration for float64 and dereferencing the pointer when using that value. Example:

type nilableNumber float64

type ParameterDescription struct {
.....
	Maximum          *nilableNumber `json:"maximum,omitempty"`
.....
}

https://play.golang.org/p/qpeFB6b8GXp

@cfchase
Copy link
Contributor Author

cfchase commented Jan 8, 2018

@shawn-hurley thanks for the tip. I switched to the nilableNumber in 7450587.

Let me know if this addresses your concerns.

}

// max_length overrides maxlength
if pd.MaxLength > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure that you are going to need to dereference the pointer here.

pkg/apb/types.go Outdated
@@ -32,20 +32,34 @@ type Parameters map[string]interface{}
// SpecManifest - Spec ID to Spec manifest
type SpecManifest map[string]*Spec

type nilableNumber float64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should make this exportable so that it can be used when creating a ParameterDescriptor outside of the APB package.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 7450587 on cfchase:param-validation into ** on openshift:master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 29f6f46 on cfchase:param-validation into ** on openshift:master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling eb04eb5 on cfchase:param-validation into ** on openshift:master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling eb04eb5 on cfchase:param-validation into ** on openshift:master**.

@cfchase cfchase removed the request for review from jmrodri January 9, 2018 13:51
@rthallisey rthallisey added the 3.9 | release-1.1 Kubernetes 1.9 | Openshift 3.9 | Broker release-1.1 label Jan 9, 2018
@rthallisey rthallisey merged commit 5495518 into openshift:master Jan 10, 2018
jianzhangbjz pushed a commit to jianzhangbjz/ansible-service-broker that referenced this pull request May 17, 2018
…shift#615)

* Bug 1472226 - Add additional field validations for JSON Schema.

* Bug 1472226 - Use NilableNumber instead of interface{}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9 | release-1.1 Kubernetes 1.9 | Openshift 3.9 | Broker release-1.1 size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants