-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
feature: Add optional to show schema id instead of def-# #4
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -244,3 +244,59 @@ test('absolute $ref #2', t => { | |
t.equal(out.properties.address.$ref, '#/definitions/def-0') | ||
t.equal(out.properties.houses.items.$ref, '#/definitions/def-0') | ||
}) | ||
|
||
const phoneNumberSchemaId = { | ||
$id: 'phoneNumber', | ||
type: 'object', | ||
properties: { | ||
countryCode: { type: 'string' }, | ||
number: { type: 'string' } | ||
} | ||
} | ||
|
||
test('set showSchemaId to be true with relativeId', t => { | ||
t.plan(4) | ||
|
||
const schema = factory('relativeId-showSchemaId') | ||
const externalSchemas = [phoneNumberSchemaId] | ||
|
||
const resolver = RefResolver({ | ||
clone: true, | ||
showSchemaId: true | ||
}) | ||
const out = resolver.resolve(schema, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this is working since the The purpose of this lib (in conjunction with To do it you can:
Since this module finds a So we need to change these test to absolute references instead and fix invalid local references |
||
externalSchemas | ||
}) | ||
const definitions = resolver.definitions() | ||
|
||
t.deepEquals(definitions, { | ||
definitions: { | ||
[phoneNumberSchemaId.$id]: phoneNumberSchemaId | ||
} | ||
}) | ||
t.equal(out.properties.personal.homeNumber.$ref, '#/definitions/phoneNumber') | ||
t.equal(out.properties.personal.mobilePhoneNumber.$ref, '#/definitions/phoneNumber') | ||
t.equal(out.properties.work.$ref, '#/definitions/phoneNumber') | ||
}) | ||
|
||
test('set showSchemaId to be true with absoluteId', t => { | ||
t.plan(1) | ||
|
||
const schema = factory('absoluteId-localRef') | ||
const externalSchemas = [phoneNumberSchemaId] | ||
|
||
const resolver = RefResolver({ | ||
clone: true, | ||
showSchemaId: true | ||
}) | ||
resolver.resolve(schema, { | ||
externalSchemas | ||
}) | ||
const definitions = resolver.definitions() | ||
|
||
t.deepEquals(definitions, { | ||
definitions: { | ||
'http://example.com/phoneNumber': phoneNumberSchemaId | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add a more complex test too, described here.
|
||
} | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = { | ||
$id: 'personPhoneNumbers', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This schema is invalid due the missing local $ref |
||
type: 'object', | ||
properties: { | ||
personal: { | ||
type: 'object', | ||
homeNumber: { | ||
$ref: '#/definitions/phoneNumber' | ||
}, | ||
mobilePhoneNumber: { | ||
$ref: '#/definitions/phoneNumber' | ||
} | ||
}, | ||
work: { | ||
$ref: '#/definitions/phoneNumber' | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove this const?
This is to avoid issue related to not cloned object, but always fresh ones
I would move it to an external file and load with
factory