Skip to content

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

@esatterwhite

Description

@esatterwhite

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions