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

Compose schemas #46 #47

Merged
merged 6 commits into from
Nov 22, 2019
Merged

Compose schemas #46 #47

merged 6 commits into from
Nov 22, 2019

Conversation

aboutlo
Copy link
Collaborator

@aboutlo aboutlo commented Sep 14, 2019

Normally inheritance with JSON Schema is achieved with allOf. However when .additionalProperties(false) is used the validator won't
understand which properties come from the base schema. S.extend creates a schema merging the base into the new one so that the validator knows all the properties because it's evaluating only a single schema.
For example in a CRUD API POST /users could use the userBaseSchema rather than GET /users or PATCH /users use the userSchema whose contains the id, createdAt and updatedAt generated server side

related to #46

@aboutlo aboutlo added the enhancement New feature or request label Sep 15, 2019
@aboutlo aboutlo changed the title WIP: Compose schemas #46 Compose schemas #46 Nov 20, 2019
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Good work! Do you think it could be possible for the inherited schema to be already a JSON schema and not our wrapper?

@aboutlo
Copy link
Collaborator Author

aboutlo commented Nov 21, 2019

Thank you @mcollina!

The problem is that our in-memory data structure is different.
I use an array of properties so I know what is the last property and I can add there the attributes.
https://github.com/fastify/fluent-schema/blob/master/src/utils.js#L140-L150

Later I deserialize:
https://github.com/fastify/fluent-schema/blob/master/src/BaseSchema.js#L372

So if we want to accept a JSON schema I guess I need to parse it. On the other hand, I'm starting to see that having something like S.raw() could be interesting and it could be applied here as well.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM

@mcollina
Copy link
Member

This is ok as-is, I would move the discussion on S.raw() in another issue.

README.md Outdated Show resolved Hide resolved
src/FluentSchema.integration.test.js Outdated Show resolved Hide resolved
src/FluentSchema.js Show resolved Hide resolved
@aboutlo aboutlo merged commit 1ddb91d into master Nov 22, 2019
@aboutlo aboutlo mentioned this pull request Dec 7, 2019
@aboutlo aboutlo deleted the compose-schemas branch April 23, 2020 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants