diff --git a/packages/repository-json-schema/src/__tests__/integration/build-schema.integration.ts b/packages/repository-json-schema/src/__tests__/integration/build-schema.integration.ts index 14caf3755bda..bc4fa464ef72 100644 --- a/packages/repository-json-schema/src/__tests__/integration/build-schema.integration.ts +++ b/packages/repository-json-schema/src/__tests__/integration/build-schema.integration.ts @@ -680,6 +680,18 @@ describe('build-schema', () => { }, }); }); + it('does not pollute the options', () => { + @model() + class Category { + @property() + name: string; + } + + const SCHEMA_OPTIONS = {}; + // tslint:disable-next-line:no-unused + const categorySchema = getJsonSchema(Category, SCHEMA_OPTIONS); + expect(SCHEMA_OPTIONS).to.be.empty(); + }); context('circular reference', () => { @model() class Category { diff --git a/packages/repository-json-schema/src/build-schema.ts b/packages/repository-json-schema/src/build-schema.ts index b8dfd55e8503..0ce4105b80eb 100644 --- a/packages/repository-json-schema/src/build-schema.ts +++ b/packages/repository-json-schema/src/build-schema.ts @@ -153,8 +153,9 @@ export function metaToJsonProperty(meta: PropertyDefinition): JSONSchema { */ export function modelToJsonSchema( ctor: Function, - options: JsonSchemaOptions = {}, + jsonSchemaOptions: JsonSchemaOptions = {}, ): JSONSchema { + const options = {...jsonSchemaOptions}; options.visited = options.visited || {}; const meta: ModelDefinition | {} = ModelMetadataHelper.getModelMetadata(ctor);