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

feat: type aggregation validation #164

Merged
merged 5 commits into from
Jun 11, 2020
Merged

feat: type aggregation validation #164

merged 5 commits into from
Jun 11, 2020

Conversation

sapirpol
Copy link
Member

@sapirpol sapirpol commented Jun 4, 2020

No description provided.

@sapirpol sapirpol requested review from bd82 and tal-sapan June 4, 2020 15:36
@bd82 bd82 marked this pull request as ready for review June 8, 2020 13:09
packages/logic-utils/api.d.ts Outdated Show resolved Hide resolved
xmlElement.parent,
model
);
if (ui5class !== undefined && allowedTypeInAggregation !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

flip condition and return empty array if we do not have enough data to compute
and at the last statement return the result of getInvalidAggregationTypeIssue

xmlns="sap.ui.commons">
<m:Panel>
<m:headerToolbar>
<🢂Toolbar🢀></Toolbar>
Copy link
Member

@bd82 bd82 Jun 8, 2020

Choose a reason for hiding this comment

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

ToolBar does not match the type of headerToolBa?

Copy link
Member

Choose a reason for hiding this comment

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

maybe choose something else like a Button so its more obvious it should not match?

Copy link
Member

Choose a reason for hiding this comment

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

This is not resolved.
The error message itself is misleading:

  • getMessage(INVALID_AGGREGATION_TYPE, "Toolbar", "Toolbar")

Can we please pick a more logical scenario to fail? e.g some Button inside headerToolbar

);
});

it("will detect mismatch of class to explicit aggregation of 'UI5Interface' type", () => {
Copy link
Member

Choose a reason for hiding this comment

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

Should this description include the term "default aggregation"?
Also I do not think this is "explicit" case

Copy link
Member

Choose a reason for hiding this comment

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

again this is not resolved, this is not an explicit aggregation case in this snippet
but instead an implicit (default) aggregation of Panel

);
});

it("will detect mismatch of class to default aggregation type", () => {
Copy link
Member

Choose a reason for hiding this comment

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

the description seems inaccurate, this does not look like a default aggregation scenario

Copy link
Member

Choose a reason for hiding this comment

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

The description seems inaccurate to me. I see no defualt aggregation in this snippet

});
});

it("will not detect an issue when the class is not under aggregation", () => {
Copy link
Member

Choose a reason for hiding this comment

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

a class is always under an aggregation, in the case below it is under the Default aggregation of mvc:View.

Copy link
Member

Choose a reason for hiding this comment

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

Again this is unresolved.

The description should be about "no issue when the types match"

@sapirpol sapirpol requested a review from bd82 June 9, 2020 16:36
const allowedTypeInAggregation = getValidAggregationTypeForSubNodes(
parentAggregation
);
if (ui5class === undefined || allowedTypeInAggregation === undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

The return [] for if (ui5class === undefined) should probably be done immediately after initializing the ui5Class variable

return aggregationType as UI5Class;
case "UI5Interface":
return aggregationType as UI5Interface;
/* istanbul ignore next - we can only recieve aggregation type of 'UI5Class' or 'UI5Interface' */
Copy link
Member

Choose a reason for hiding this comment

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

Its probably true that the model does not contain any aggregation with an invalid type.
But that does not mean we could never receive one, just that we are unlikely to.

So perhaps we should create a test for this (with deepClone of the model).

But maybe the best solution would be to narrow down the type signature of UI5Aggregation?
@tal-sapan WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

If its not clear I meant that the UI5Aggregation.type would be narrowed down and be more specific UI5Class | UI5Interface and that the semanticModelBuilder would create a warn/error if that assumption is not met.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

No. The type might be unresolved (e.g. if there is a typo) or there might be other errors in the api.json (and cases which I'm not even sure are errors, like primitive types, though I think they would be specified in altTypes instead). It should be handled in the code.

Copy link
Member

Choose a reason for hiding this comment

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

  • Representing unresolved in the model seems fine.
  • But assuming an aggregation may not be of enum/primitive types, why should it even be represented in the model?

The model should not represent the API.json verbatim, rather it should represent the UI5 Semantics.

Copy link
Member

Choose a reason for hiding this comment

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

I will investigate this outside the scope of this PR

@sapirpol sapirpol requested a review from bd82 June 11, 2020 10:42
Copy link
Member

@bd82 bd82 left a comment

Choose a reason for hiding this comment

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

I'm approving to avoid merge conflicts.
But please fix the test descriptions and maybe add another negative test case before merge or in a different PR

Oops looked at wrong commit

@sapirpol sapirpol merged commit 63c5b5a into master Jun 11, 2020
@sapirpol sapirpol deleted the type_validation branch June 11, 2020 15:22
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.

None yet

3 participants