From 20bb8a242513077bf1e9218dc63f36349606318e Mon Sep 17 00:00:00 2001 From: jannyHou Date: Tue, 16 Apr 2019 14:39:47 -0400 Subject: [PATCH] fixup!: avoid polluting the options --- .vscode/settings.json | 4 +--- .../integration/build-schema.integration.ts | 12 ++++++++++++ packages/repository-json-schema/src/build-schema.ts | 3 ++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 369b0e48f815..cbfd84958981 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,5 @@ { - "editor.rulers": [ - 80 - ], + "editor.rulers": [80], "editor.tabCompletion": "on", "editor.tabSize": 2, "editor.trimAutoWhitespace": true, 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..50853aa1fe55 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 JSON schema options', () => { + @model() + class Category { + @property() + name: string; + } + + const JSON_SCHEMA_OPTIONS = {}; + // tslint:disable-next-line:no-unused + const categorySchema = getJsonSchema(Category, JSON_SCHEMA_OPTIONS); + expect(JSON_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);