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

Nested Objects #13

Merged

Conversation

Sergej-Popov
Copy link
Collaborator

@Sergej-Popov Sergej-Popov commented Jan 30, 2020

Add support for nested object Schema for objects that are not Dictionaries.

#8 has introduced nested schemas. But it only accounted for Dictionaries: objects with arbitrary keys. This was a little design mistake since there was no nice way to address nested Objects with defined schema. This PR changes dictionary syntax to use DictionarySchema<T> and reserves nested Schema<T> for structured objects.

Since the change is breaking - the major version of the package is increased.

Type of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • I have updated the documentation accordingly.

New Feature Submissions:

  • Does your submission pass tests?
  • Have you lint your code locally prior to submission?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully run tests with your changes locally?

@Sergej-Popov Sergej-Popov changed the title Add support for nested object Schema f… Nested Objects Jan 30, 2020
@@ -84,7 +84,7 @@ export class ArraySchema extends TypeSchema<"array"> {
enum: [i]
};
});
if (schema.items && schema.items instanceof Schema) this.items = schema.items.compile().additionalProperties as PropertySchema;
if (schema.items && schema.items instanceof Schema) this.items = schema.items.compile();

Choose a reason for hiding this comment

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

Just to see if I understand this at all 😄

It seems this line is giving us the ability to delegate to the compile method which properties to return. Which lets the compile method for the DictionarySchema select not to use the additionalProperties property...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that's correct. Should have never been part of array-schema logic but I didn't see it at the time.

Copy link

@TomFreeman TomFreeman left a comment

Choose a reason for hiding this comment

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

Looks okay to me.

I'm not going to pretend I understand how the fix works 😄

@Sergej-Popov
Copy link
Collaborator Author

Added a bit more info in Wiki to explain the difference between normal object & dictionary
https://github.com/justeat/ts-jsonschema-builder/wiki/Object

@Sergej-Popov Sergej-Popov merged commit 32cc622 into justeat:master Feb 1, 2020
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

2 participants