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 constraints! #76

Merged
merged 4 commits into from
May 30, 2017
Merged

Conversation

brendo
Copy link
Contributor

@brendo brendo commented May 29, 2017

There's a few changes in here, but should be relatively straightforward to understand.

From reading the JSON Schema specification, most of the constraints only apply to certain types. This made for a simple (if not verbose) implementation, where the Property component delegates most of the work to sub components that are responsible for rendering the constraints.

This change comes with zero styling, that'll be part of #38.

In addition this fixes a couple of other issues:

@brendo brendo requested a review from quangkhoa May 29, 2017 03:19
minItems: PropTypes.number,
uniqueItems: PropTypes.bool
})
};
Copy link
Contributor

Choose a reason for hiding this comment

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

This class's responsibility is to render the validation constraints for arrays, and thus should be named accordingly.

Need one space in UI (Carriers > Returns a list of integrations available for registration)

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you want all the *Property classes to be renamed to *Constraints (I don't feel strongly either way)?

As for the space, I'd add some CSS.

Copy link
Contributor

@quangkhoa quangkhoa May 29, 2017

Choose a reason for hiding this comment

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

Yes, they should either have Constraint in the name, or are all under a Constraints directory. That makes it easy to follow.

minimum: PropTypes.number,
multipleOf: PropTypes.number
})
};
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the construction of the constraints in those new constraints components could be extracted out, which would make the logic a bit easier to test (and those components could potentially go away??? We can then have a shared ConstraintComponent that requires {validations, validationType}. What do you reckon @brendo?

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 don't agree sorry. I considered having one component be responsible for constraints, but ultimately it would still have switch logic in it to only apply certain constraints to certain components.

Having small (tiny even!) components that just focus on all things Numeric or String made for really easy testing and if we want to add more constraints, we'd only have to touch a small part of the codebase!

I'm happy to dumb down the Property constraints proptype (from shape to object) and just leave the smaller components deal with the actual specifics if you think that'd reduce duplication?

Copy link
Contributor

@quangkhoa quangkhoa May 29, 2017

Choose a reason for hiding this comment

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

I totally agreed with you about the approach of having multiple small components.

My point was that all those constraints UI components share the same pattern:

  1. Construct the validations array
  2. Render the validations array, e.g.
<span>
  {validations.map(constraint =>
    <span key={constraint} className={constraintName}>{constraint}</span>
  )}
</span>

So they only differ in the way validations are constructed. This part, however, has nothing to do with UI.

If we move the validation logic out (as we try to keep the UI components really lean), to seperate functions, then there are no difference between those UI constraint components. React components offer PropTypes.shape, which is a nice way to specify the signature (input) of the UI component; however we could achieve something like that with function signature and typescript (down the track).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah got you, I have an idea, let me come back to you...

@@ -0,0 +1,56 @@
import { VALIDATION_KEYWORDS, hasConstraints, getConstraints } from '../../src/parser/open-api/constraintsParser';
Copy link
Contributor

Choose a reason for hiding this comment

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

this test should be under test/parser/open-api

@quangkhoa quangkhoa merged commit 183fbb0 into temando:master May 30, 2017
@brendo brendo deleted the issue-13-render-constraints branch May 30, 2017 01:54
@brendo brendo mentioned this pull request May 30, 2017
17 tasks
brendo pushed a commit to brendo/open-api-renderer that referenced this pull request Jun 20, 2017
brendo pushed a commit to brendo/open-api-renderer that referenced this pull request Jun 20, 2017
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.

2 participants