Skip to content

Commit

Permalink
add properties to test case
Browse files Browse the repository at this point in the history
  • Loading branch information
asc11cat committed Oct 7, 2022
1 parent 9c63e1b commit 5b026bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/spec/openapi/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ function prepareOpenapiSchemas (schemas, ref) {
// swagger doesn't accept $id on components schemas
// $ids are needed by ref.resolve to check the URI
// definitions are added by resolve, but they are not needed, as we resolve
// the $ref to already existing schemas in components.schemas using method below, not the definition ones
// the $ref to already existing schemas in components.schemas using method below
// therefore, we delete both $id and definitions at the end of the process
delete resolvedRef.$id
delete resolvedRef.definitions
Expand Down
7 changes: 6 additions & 1 deletion test/spec/openapi/refs.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ test('support schema with definitions keyword and $ref inside', async (t) => {
fastify.register(async (instance) => {
instance.addSchema({
$id: 'NestedSchema',
properties: {
id: { type: 'string' },
},
definitions: {
SchemaA: {
type: 'object',
Expand All @@ -312,9 +315,11 @@ test('support schema with definitions keyword and $ref inside', async (t) => {

const openapiObject = fastify.swagger()
t.equal(typeof openapiObject, 'object')

// definitions are getting merged to properties
t.match(Object.keys(openapiObject.components.schemas), ['NestedSchema'])
t.match(Object.keys(openapiObject.components.schemas.NestedSchema), ['properties'])
t.match(Object.keys(openapiObject.components.schemas.NestedSchema.properties), ['SchemaA', 'SchemaB'])
t.match(Object.keys(openapiObject.components.schemas.NestedSchema.properties), ['id', 'SchemaA', 'SchemaB'])

// ref must be prefixed by '#/components/schemas/'
t.equal(openapiObject.components.schemas.NestedSchema.properties.SchemaB.properties.example.$ref, '#/components/schemas/NestedSchema/properties/SchemaA')
Expand Down

0 comments on commit 5b026bc

Please sign in to comment.