-
Notifications
You must be signed in to change notification settings - Fork 58
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
Object type ignored when nested properties use oneOf and raw #233
Comments
Hey @giovanni-bertoncelli thank you for raising this. Can you try to write the tests for isolating the issue and if there is the issue propose a PR? fluent-json-schema/src/utils.test.js Line 6 in c962de0
|
@aboutlo I have no clear idea on how to add this test case. I think this may be come from the |
I can confirm this behavior in my project. Node: v20.11.0
|
Forgot to mention that the change of behaviour occurred after updating fastify, fastify-plugin and fluent-json-schema from v3 to v4. |
Thanks, would you like to send a PR? |
@mcollina any suggestions on where to start? |
fluent-json-schema/src/ObjectSchema.js Line 305 in ec48648
changing it to it('should set type to the potential types based on the combinedKeyword oneOf', () => {
const schema = S.object()
.additionalProperties(true)
.id('JobPublished')
.prop(
'data',
S
.required()
.oneOf([
S.integer(),
S.array(),
])
).valueOf()
expect(schema.properties.data.type).toEqual(['integer', 'array'])
}) |
@giovanni-bertoncelli Proposed PR #237 . Review and give comments please. |
Hi @Uzlopak! In my case, the fix is resulting in:
This is giving me the following schema error:
|
I created some examples here: Invalid schema: https://www.jsonschemavalidator.net/s/WwSDDh5d Valid: |
Prerequisites
Fastify version
4.23.2
Plugin version
4.2.1
Node.js version
20.x
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
13.4
Description
When I'm creating a schema like this:
The
type: object
is omitted in the resulting JSON Schema both event if I use S.object() and raw type object. This can throw errors for example when using Ajv in strict mode. I do not know if the problem it's caused by the oneOf or the raw clause.Steps to Reproduce
You can see a full reproduction example here: https://codesandbox.io/p/sandbox/infallible-cloud-4kw5xm. Run npm start.
Expected Behavior
The resulting JSON schema should not be this:
but this:
It seems that this issue is not present on schemas root level oneOf/raw.
The text was updated successfully, but these errors were encountered: