fastify / fluent-json-schema

A fluent API to generate JSON schemas
MIT License
495 stars 58 forks source link

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

Closed esatterwhite closed 1 year ago

esatterwhite commented 1 year ago

Prerequisites

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

https://github.com/fastify/fluent-json-schema/blob/ab242d2a88973c78365a042fc2e9568208a28872/src/ObjectSchema.js#L321-L331

Expected Behavior

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

aboutlo commented 1 year ago

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 commented 1 year ago

I don't particularly have time for it

esatterwhite commented 1 year ago

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