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

Object schema does not carry properties added by .raw() to a $ref #216

Closed
2 tasks done
esatterwhite opened this issue Mar 29, 2023 · 3 comments · Fixed by #223
Closed
2 tasks done

Object schema does not carry properties added by .raw() to a $ref #216

esatterwhite opened this issue Mar 29, 2023 · 3 comments · Fixed by #223
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@esatterwhite
Copy link
Contributor

esatterwhite commented Mar 29, 2023

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.10.2

Plugin version

No response

Node.js version

16.14.0

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

5.10.167-1-MANJARO

Description

I think there is a problem with using ref + raw in the object schema in that the values added by the raw() function are removed or not included

Steps to Reproduce

correct

 fluent.ref('foo').raw({test: true}).valueOf()
{ '$ref': 'foo', test: true }

incorrect

fluent.object().prop('a', fluent.string()).prop('test', fluent.ref('foo').raw({test: true})).valueOf()
{
  '$schema': 'http://json-schema.org/draft-07/schema#',
  type: 'object',
  properties: { a: { type: 'string' }, test: { '$ref': 'foo' } }
}

I suspect it is from the object schemas handling of ref

return ObjectSchema({
schema: {
...schema,
[target]: [
...schema[target],
$ref ? { name, $ref } : Object.assign({}, { name }, attributes)
]
},
...options
})
},

Expected Behavior

I'd expect the properties defiend by .raw() to be carried unconditionally to the object they are defined

@aboutlo
Copy link
Collaborator

aboutlo commented May 3, 2023

hey @esatterwhite thank you for reporting this. Would you like to contribute and add a test in the ObjectSchma.test.js file and add the functionality if it fails?

@esatterwhite
Copy link
Contributor Author

I don't particularly have time for it

@Eomm Eomm added bug Something isn't working good first issue Good for newcomers labels Jul 20, 2023
@Fdawgs Fdawgs linked a pull request Jul 22, 2023 that will close this issue
3 tasks
aboutlo pushed a commit that referenced this issue Jul 26, 2023
* fixes: object schema carry properties added by raw to $ref

fixes #216

* Apply suggestions from code review

* update to spread operator for consistency
@esatterwhite
Copy link
Contributor Author

@aboutlo looks like a fix for 5his landed, can we get a new release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants