Skip to content
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

test: extend external definition tests #90

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'