-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
WIP Feature/concat schemas #432
base: master
Are you sure you want to change the base?
Conversation
…metarhia-master # Conflicts: # CHANGELOG.md # lib/schema.js # test/schema.js
Metarhia master
@@ -20,6 +20,37 @@ class Schema extends SchemaMetadata { | |||
return null; | |||
} | |||
|
|||
static concat(...sources) { |
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.
try to use Schema.protoype.toJSON
to reduce amount of code. You can create new Schema with just typings from toJSON
// Q: How to merge options? | ||
for (const schema of schemas) { | ||
resultSchema.updateFromSchema(schema); | ||
// Q: Can we have conflicts with indexes? |
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.
I need examples of it, write tests please
const schema2 = Schema.from({ c: 'string', d: 'number' }); | ||
const schema3 = Schema.from({ e: 'string', f: 'number' }); | ||
test.strictEqual( | ||
Schema.concat(schema1, schema2, schema3).toString(), |
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.
use toJSON
to check typings
} | ||
const schema3 = Schema.from({ Custom: {}, type: 'string' }); | ||
const schema4 = Schema.from({ Custom: {}, type: 'number' }); | ||
try { |
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.
use test.throws(() => fn(), new Error(your error message))
(test) => { | ||
const schema1 = Schema.from({ a: 'string', b: 'number' }); | ||
const schema2 = Schema.from({ Custom: {}, type: 'string' }); | ||
try { |
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.
use test.throws
} | ||
} | ||
const resultSchema = Schema.from(defs); | ||
// Q: How to merge options? |
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.
we don't need to merge options and concat validate functions
npm t
)npm run fmt
)