-
-
Notifications
You must be signed in to change notification settings - Fork 59
Add ref instead all of for additionalProperties lesson #190
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
base: main
Are you sure you want to change the base?
Conversation
jdesrosiers
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I just had a few editorial suggestions.
| # Extending Closed Schemas | ||
|
|
||
| Previously in the Objects module, we learned to `additionalProperties`. However, it is important to note that `additionalProperties` only recognizes properties declared in the same [subschema](https://json-schema.org/learn/glossary#subschema) as itself. | ||
| Previously in the Objects , we learned about `additionalProperties`. However, it is important to note that `additionalProperties` only recognizes properties declared in the same [subschema](https://json-schema.org/learn/glossary#subschema) as itself. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Previously in the Objects , we learned about `additionalProperties`. However, it is important to note that `additionalProperties` only recognizes properties declared in the same [subschema](https://json-schema.org/learn/glossary#subschema) as itself. | |
| Previously in the Objects module, we learned about `additionalProperties`. However, it is important to note that `additionalProperties` only recognizes properties declared in the same [subschema](https://json-schema.org/learn/glossary#subschema) as itself. |
| Previously in the Objects module, we learned to `additionalProperties`. However, it is important to note that `additionalProperties` only recognizes properties declared in the same [subschema](https://json-schema.org/learn/glossary#subschema) as itself. | ||
| Previously in the Objects , we learned about `additionalProperties`. However, it is important to note that `additionalProperties` only recognizes properties declared in the same [subschema](https://json-schema.org/learn/glossary#subschema) as itself. | ||
|
|
||
| So, `additionalProperties` can restrict you from "extending" a schema using combining keywords such as `$ref`. In the following example, we can see how the `additionalProperties` can cause attempts to extend the address schema example to fail. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| So, `additionalProperties` can restrict you from "extending" a schema using combining keywords such as `$ref`. In the following example, we can see how the `additionalProperties` can cause attempts to extend the address schema example to fail. | |
| So, `additionalProperties` can restrict you from "extending" a schema using combining [keywords](https://json-schema.org/learn/glossary#keyword) such as `$ref`. In the following example, we can see how `additionalProperties` can cause attempts to extend the address schema example to fail. |
| ``` | ||
| The above [schema](https://json-schema.org/learn/glossary#schema) will not allow you to define `type` property. because `additionalProperties` is set to `false`. The reason is, `additionalProperties` only recognizes properties declared in the same [subschema](https://json-schema.org/learn/glossary#subschema). | ||
|
|
||
| This [schema](https://json-schema.org/learn/glossary#schema) will **reject valid data** because `additionalProperties: false` only sees the `type` property defined locally. It doesn't recognize the properties from the referenced schema (`street_address`, `city`, `state`), so it would incorrectly treat them as "additional" properties and reject them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This schema will reject valid data [...]
That statement doesn't make sense to me. If the schema rejects it, it isn't valid. Maybe it needs to say something like, it rejects data you intended to be valid.
What kind of change does this PR introduce?
Refactoring Chapter 7, refactored the code to use $ref instead $allOf for explanation
Issue Number:
Screenshots/videos:
If relevant, did you update the documentation?
No
Summary
Does this PR introduce a breaking change?
NO