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

Support minProperties and maxProperties on objects #53

Conversation

betsyalegria
Copy link
Contributor

@betsyalegria betsyalegria commented Oct 7, 2021

Description

Adds support for minProperties and maxProperties for objects. Partly completes: #5

Leveraged a lot of the existing patterns we have for minItems and maxItems in arrays. So we created two new classes in this PR: ObjectMaxPropertiesConstraint and ObjectMinPropertiesConstraint that are used in the ObjectBuilder class.

Testing

Updated unit tests and also manually tested

@CLAassistant
Copy link

CLAassistant commented Oct 7, 2021

CLA assistant check
All committers have signed the CLA.

Comment on lines +5 to +6
HHVM_VERSION=4.102.2
HHVM_NEXT_VERSION=4.102.2
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i noticed @sarahhenkens also updated HHVM_VERSION in her PR #52, should we also update HHVM_NEXT_VERSION? i wasn't 100% sure if they should always match

Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm I think we should probably update this to 4.121?

Comment on lines +151 to +152
$max_properties = $this->typed_schema['maxProperties'] ?? null;
$min_properties = $this->typed_schema['minProperties'] ?? null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

someone asked about whether we should validate if these integers are non-negative. i noticed we don't validate that for StringMinLengthConstraint or ArrayMinItemsConstraint - is there a reason/context for that?

if we were to add that check for objects, i'm trying to figure out where the best place for it would be so that it'd error out for the developer trying to generate a schema with negative min/max numbers. doesn't seem like the getCheckMethod is the right place.

Choose a reason for hiding this comment

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

It wasn't intentional that we left those off, just didn't get around to it. I'd add it anywhere in this codegen path, maybe above where you set the class properties?

Copy link
Contributor Author

@betsyalegria betsyalegria Oct 12, 2021

Choose a reason for hiding this comment

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

okay, sounds good - i added checks for those above in the build method & tested that it throws an error when trying to generate a file that has invalid min/max values.

Comment on lines +151 to +152
$max_properties = $this->typed_schema['maxProperties'] ?? null;
$min_properties = $this->typed_schema['minProperties'] ?? null;

Choose a reason for hiding this comment

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

It wasn't intentional that we left those off, just didn't get around to it. I'd add it anywhere in this codegen path, maybe above where you set the class properties?

@mwildehahn mwildehahn merged commit db731bd into slackhq:master Oct 12, 2021
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.

4 participants