-
-
Notifications
You must be signed in to change notification settings - Fork 57
Question: how to implement a basic object schema? #41
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
Comments
I don't know how it works fastJson in details but I have the feeling the issue could be there to me {
title: 'check string coerce',
type: 'object',
properties: {},
additionalProperties: true
} become const schema = S.object().additionalProperties(true).title('title string coerce')
console.log(JSON.stringify(schema.valueOf(),undefined,2)) which will generate {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": {},
"title": "title string coerce"
} I wonder about So either you set to |
Without |
So looking to the reference:
So the bug is here: https://github.com/fastify/fluent-schema/blob/73adbf43075104d5ac05a874313fd7dbbda72474/src/ObjectSchema.js#L52-L52 we should need something like this: additionalProperties: value => {
if (typeof value !== 'boolean' && !isFluentSchema(value))
throw new Error("'additionalProperties' must be a boolean or a FluentSchema object")
const attribute =
typeof value === 'boolean'
? value.valueOf()
: omit(value.valueOf(), ['$schema'])
return setAttribute({ schema, ...options }, [
'additionalProperties',
attribute,
'array',
])
} |
FYI: re-reading this issue this morning I noticed that I left out a "not" in my last reply. Please re-read it to make sure it still makes sense. |
Still, a bug in fluent because of the spec given
expect: {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": true,
"title": "title string coerce"
} rather than: {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": {},
"title": "title string coerce"
} However, |
PR merged |
Thank you. |
Basically, I want to implement this test with
fluent-schema
-- https://github.com/fastify/fast-json-stringify/blob/06acd3bf09a6c0136eb442d0d95e2a5b1fd85cf2/test/additionalProperties.test.js#L68-L79My attempt keeps resulting in various errors -- https://runkit.com/embed/ep1pfme4238t
The text was updated successfully, but these errors were encountered: