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

Minor changes on chapters 4 and 5 #231

Merged
merged 5 commits into from
Aug 17, 2020
Merged

Minor changes on chapters 4 and 5 #231

merged 5 commits into from
Aug 17, 2020

Conversation

relu91
Copy link
Member

@relu91 relu91 commented Aug 10, 2020

This PR reports @egekorkan review changes in chapters 4 and 5 (no comments were left on chapter 3). See the related #230 (comment) and the pdf document


Preview | Diff

index.html Show resolved Hide resolved
index.html Outdated
@@ -332,7 +332,7 @@ <h2>The <dfn>ThingDescription</dfn> type</h2>
<a>TD</a>.
</p>
<div>
To <dfn>expand a TD</dfn> given |td:ThingDescription|, run the following steps:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why to remove the algorithm name?

@@ -347,23 +347,24 @@ <h2>The <dfn>ThingDescription</dfn> type</h2>
Therefore, this API expects the {{ThingDescription}} objects be validated before used as parameters. This specification defines a basic <a>TD</a> validation as follows.
</p>
<div>
To <dfn>validate a TD</dfn> given |td:ThingDescription|, run the following steps:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same: I don't think algorithm names and params should be removed.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, see my review.

index.html Outdated
@@ -332,7 +332,7 @@ <h2>The <dfn>ThingDescription</dfn> type</h2>
<a>TD</a>.
</p>
<div>
To <dfn>expand a TD</dfn> given |td:ThingDescription|, run the following steps:
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this element should be kept, is it @zolkis?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes.

<li>
If <a href="https://www.w3.org/TR/2019/CR-wot-thing-description-20190516/#json-schema-for-validation">JSON schema validation</a> fails on |td|, [= exception/throw =] a
{{"TypeError"}} and abort these steps.
</li>
Copy link
Member Author

Choose a reason for hiding this comment

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

@egekorkan comment on this change:

The JSON Schema validation should be before step 2 and that way if something fails the schema validation, it must have values for terms that do not have defaults. The schema validation does not expect a TD with defaults filled in.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd leave as it was. As far as I understand if a property is marked as required in JSONSchema even if it has a default value, it must appear in the validating object. However, I'd add a step to make the process a little bit clearer:

  1. Check if it is an Object
  2. Check if any of the mandatory fields with no default are not defined.
  3. Fill mandatory fields with default
  4. Do JSONSchema validation

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with the sequence proposed above.

@relu91 relu91 requested a review from zolkis August 11, 2020 09:35
@relu91
Copy link
Member Author

relu91 commented Aug 11, 2020

I added a filling default step in the validation algorithm. This is because AFAIK JSONschema validation fails if a required property is not present even if it has a default value. @egekorkan could you check this?

@relu91
Copy link
Member Author

relu91 commented Aug 11, 2020

It seems there is a relevant discussion about this topic in eclipse-thingweb/node-wot#302

@egekorkan
Copy link
Contributor

egekorkan commented Aug 11, 2020

The thing is that the values that have a default value are not required in the official validation schema, i.e. if a property form does not have an op value, it will pass validation. Thus, an algorithm that fills the defaults should check that a TD is valid in the first place. In Thingweb Playground, the first schema validation corresponds to the validation with the official schema whereas the second validation that says with defaults correspond to a validation where all the values that have defaults should be filled. The previous example with a property with no op fails the second validation.

index.html Outdated Show resolved Hide resolved
index.html Outdated
@@ -360,6 +360,10 @@ <h2>The <dfn>ThingDescription</dfn> type</h2>
are missing from |td|, [= exception/throw =] a
{{"TypeError"}} and abort these steps.
</li>
<li>
Fill any missing mandatory property defined in [[!WOT-TD]] that have a
<a href="https://www.w3.org/TR/2019/CR-wot-thing-description-20190516/#sec-default-values">default definition</a> with its default.
Copy link
Contributor

@zolkis zolkis Aug 11, 2020

Choose a reason for hiding this comment

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

Suggestion: usually these complex steps should be more detailed, e.g. using sub-steps with a loop, or an explicit loop, for instance

For each mandatory property defined in [[!WOT-TD]] that have default definitions, add the property to |td| if it's missing and set its value to the default value specified in [[!WOT-TD]].

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like there are no mandatory properties in the TD spec that would have default values, so this text needs updating. We need an initialization policy for the default values of mandatory TD properties. I suggest we create a separate issue about that in the TD repo, then link it here and also in a new issue in this repo. Then we can resolve this and merge this PR.

@relu91
Copy link
Member Author

relu91 commented Aug 13, 2020

In Thingweb Playground, the first schema validation corresponds to the validation with the official schema whereas the second validation that says with defaults correspond to a validation where all the values that have defaults should be filled. The previous example with a property with no op fails the second validation.

The thing here is that if it has a default, it probably does not need to be defined.... I agree with @danielpeintner here:

However I don't think that any implementation needs to add these default values. What would be the idea of having them in the first place if they NEED to get added. My take on this is that IF there is no value the default values kicks in for any processing. The reason to NOT HAVE them is manifold:

  • reduced data exchange (TD more compact)

  • simpler to see non defaults

  • avoiding to exchange knowledge that is default anyway

@relu91
Copy link
Member Author

relu91 commented Aug 13, 2020

Meanwhile, I updated the validation algorithm to have a really basic starting point. I removed the following steps:

  1. If td is not an object, throw a "TypeError" and abort these steps.
  2. If any of the mandatory properties defined in [WOT-TD] for Thing that don't have default definitions are missing from td, throw a "TypeError" and abort these steps.

They are both covered by the JSONSchema validation process. The only difference is that JSONSchema is more restrictive on point 2. It fails even if the mandatory property has a default assigned. However, since Looks like there are no mandatory properties in the TD spec that would have default values I think we can omit it.

Simplify so that we can build more complex steps from this solid ground
Copy link
Contributor

@zolkis zolkis left a comment

Choose a reason for hiding this comment

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

Please include an editor's note mentioning that more steps are going to be included for filling the mandatory properties defined in the TD spec, once the default values are specified in the TD spec (and please file an issue on the TD spec for this).

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.

3 participants