Skip to content

Commit

Permalink
test: extend external definition tests (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
toomuchdesign authored Sep 22, 2023
1 parent ff11da1 commit 7fcaa84
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 16 deletions.
56 changes: 48 additions & 8 deletions test/externalRefs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,68 @@ describe('External $ref', () => {
silent: true,
});

const externalDefinitionSchema = await import(
path.resolve(outputPath, 'components/schemas/ExternalDefinition')
// $ref: './external-definition.yaml#/components/schemas/Foo1'
const externalDefinitionWithRefSchema = await import(
path.resolve(outputPath, 'components/schemas/ExternalDefinitionWithRef')
);

expect(externalDefinitionSchema.default).toEqual({
description: 'External Foo 1 description',
expect(externalDefinitionWithRefSchema.default).toEqual({
description: 'External Foo description',
type: ['string', 'null'],
enum: ['yes', 'no', null],
});

const localDefinitionReferencingExternalSchema = await import(
// $ref: './external-definition-whole-document.yaml'
const externalDefinitionWholeDocumentSchema = await import(
path.resolve(
outputPath,
'components/schemas/ExternalDefinitionWholeDocument',
)
);

expect(externalDefinitionWholeDocumentSchema.default).toEqual({
description: 'External definition whole document',
type: ['string', 'null'],
enum: ['yes', 'no', null],
});

// $ref: './external-definition-nested-refs.yaml#/components/schemas/BarFromRef'
const externalDefinitionNestedRefsSchema = await import(
path.resolve(
outputPath,
'components/schemas/ExternalDefinitionNestedRefs',
)
);

expect(externalDefinitionNestedRefsSchema.default).toEqual({
description: 'External Bar description',
type: ['string', 'null'],
enum: ['yes', 'no', null],
});

// Local definition referencing external schemas
const localDefinitionReferencingExternalSchemas = await import(
path.resolve(
outputPath,
'components/schemas/LocalDefinitionReferencingExternal',
)
);

expect(localDefinitionReferencingExternalSchema.default).toEqual({
expect(localDefinitionReferencingExternalSchemas.default).toEqual({
type: 'object',
properties: {
remoteDefinition: {
description: 'External Foo 1 description',
externalDefinitionWithRef: {
description: 'External Foo description',
type: ['string', 'null'],
enum: ['yes', 'no', null],
},
externalDefinitionWholeDocument: {
description: 'External definition whole document',
type: ['string', 'null'],
enum: ['yes', 'no', null],
},
externalDefinitionNestedRefs: {
description: 'External Bar description',
type: ['string', 'null'],
enum: ['yes', 'no', null],
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
openapi: 3.0.3
info:
title: title
description: description
version: 1.0.0
components:
schemas:
BarFromRef:
$ref: './external-definition.yaml#/components/schemas/Bar'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
description: External definition whole document
type: string
nullable: true
enum:
- yes
- no
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ info:
version: 1.0.0
components:
schemas:
Foo1:
description: External Foo 1 description
Foo:
description: External Foo description
type: string
nullable: true
enum:
- yes
- no
Bar1:
description: External Bar 1 description
Bar:
description: External Bar description
type: string
nullable: true
enum:
Expand Down
16 changes: 12 additions & 4 deletions test/fixtures/external-ref/specs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ components:
LocalDefinitionReferencingExternal:
type: object
properties:
remoteDefinition:
$ref: '#/components/schemas/ExternalDefinition'
ExternalDefinition:
$ref: './external-definition-1.yaml#/components/schemas/Foo1'
externalDefinitionWithRef:
$ref: '#/components/schemas/ExternalDefinitionWithRef'
externalDefinitionWholeDocument:
$ref: '#/components/schemas/ExternalDefinitionWholeDocument'
externalDefinitionNestedRefs:
$ref: '#/components/schemas/ExternalDefinitionNestedRefs'
ExternalDefinitionWithRef:
$ref: './external-definition.yaml#/components/schemas/Foo'
ExternalDefinitionWholeDocument:
$ref: './external-definition-whole-document.yaml'
ExternalDefinitionNestedRefs:
$ref: './external-definition-nested-refs.yaml#/components/schemas/BarFromRef'

0 comments on commit 7fcaa84

Please sign in to comment.