Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed Jan 24, 2024
1 parent 17a783f commit 71d2563
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/processors/JsonSchemaInputProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ export class JsonSchemaInputProcessor extends AbstractInputProcessor {
dereference: {
circular: true,
excludedPathMatcher: (path: string) => {
return path.includes('/examples/');
return (
path.includes('/examples/') &&
!path.includes('/properties/examples/')
);
}
}
};
Expand Down
34 changes: 33 additions & 1 deletion test/processors/JsonSchemaInputProcessor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AnyModel, CommonModel } from '../../src/models';
jest.mock('../../src/utils/LoggingInterface');
jest.spyOn(JsonSchemaInputProcessor, 'convertSchemaToCommonModel');
let mockedReturnModels = [new CommonModel()];
const mockedMetaModel = new AnyModel('test', undefined);
const mockedMetaModel = new AnyModel('test', undefined, {});
jest.mock('../../src/helpers/CommonModelToMetaModel', () => {
return {
convertToMetaModel: jest.fn().mockImplementation(() => {
Expand Down Expand Up @@ -261,6 +261,38 @@ describe('JsonSchemaInputProcessor', () => {
'Cannot handle input, because it has a root `$ref`, please manually resolve the first reference.'
);
});
test('should not resolve example containing $ref keyword', async () => {
const processor = new JsonSchemaInputProcessor();
const schema = {
examples: [{ $ref: '#/none/existing/reference' }],
properties: {
$ref: {
type: 'string'
}
}
};
const dereferencedSchema = await processor.dereferenceInputs(schema);
expect(dereferencedSchema.examples[0]).toEqual({
$ref: '#/none/existing/reference'
});
});
test('should resolve example containing $ref keyword if part of properties', async () => {
const processor = new JsonSchemaInputProcessor();
const schema = {
definitions: {
reference: {
type: 'string'
}
},
properties: {
$ref: { $ref: '#/definitions/reference' }
}
};
const dereferencedSchema = await processor.dereferenceInputs(schema);
expect(dereferencedSchema.properties.$ref).toEqual({
type: 'string'
});
});
});

describe('convertSchemaToCommonModel()', () => {
Expand Down

0 comments on commit 71d2563

Please sign in to comment.