Skip to content

Commit

Permalink
add fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed Apr 30, 2024
1 parent d1e64d6 commit dabfd2c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/interpreter/InterpretAdditionalProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export default function interpretAdditionalProperties(
interpreter: Interpreter,
interpreterOptions: InterpreterOptions = Interpreter.defaultInterpreterOptions
): void {
if (typeof schema === 'boolean' || isModelObject(model) === false) {
if (
typeof schema === 'boolean' ||
(model.type !== undefined && isModelObject(model) === false)
) {
return;
}
let defaultAdditionalProperties = true;
Expand Down
20 changes: 20 additions & 0 deletions test/interpreter/unit/InterpretAdditionalProperties.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ describe('Interpretation of additionalProperties', () => {
schema
);
});
test('should try and interpret additionalProperties schema if no type', () => {
const schema: any = { additionalProperties: { type: 'string' } };
const model = new CommonModel();
const interpreter = new Interpreter();
const mockedReturnModel = new CommonModel();
(interpreter.interpret as jest.Mock).mockReturnValue(mockedReturnModel);

interpretAdditionalProperties(schema, model, interpreter);

expect(interpreter.interpret).toHaveBeenNthCalledWith(
1,
{ type: 'string' },
Interpreter.defaultInterpreterOptions
);
expect(model.addAdditionalProperty).toHaveBeenNthCalledWith(
1,
mockedReturnModel,
schema
);
});
test('should ignore model if interpreter cannot interpret additionalProperty schema', () => {
const schema: any = {};
const model = new CommonModel();
Expand Down

0 comments on commit dabfd2c

Please sign in to comment.