From b319bf6a8a36fc40b7bada6601d44bfc56424ae1 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Sun, 7 Jul 2024 14:01:57 +0200 Subject: [PATCH] Inline the JSONSchema type from yaml-language-server The JSON schema type from `@types/json-schema` is not completely compatible with the JSON schema type used by `yaml-language-server`. `monaco-yaml` now ships a copy of the schema type used by `yaml-language-server`. --- .eslintrc.yaml | 2 + examples/demo/src/index.ts | 1 - package-lock.json | 1 - package.json | 1 - src/index.ts | 75 +++++++++++++++++++++++++++++++++++++- 5 files changed, 75 insertions(+), 5 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 1b22fe8..4fdb116 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -1,6 +1,8 @@ extends: - remcohaszing rules: + eslint-comments/no-use: off + import/no-extraneous-dependencies: off n/no-extraneous-import: off diff --git a/examples/demo/src/index.ts b/examples/demo/src/index.ts index b99f588..12d163c 100644 --- a/examples/demo/src/index.ts +++ b/examples/demo/src/index.ts @@ -24,7 +24,6 @@ window.MonacoEnvironment = { const defaultSchema: SchemasSettings = { uri: 'https://github.com/remcohaszing/monaco-yaml/blob/HEAD/examples/demo/src/schema.json', - // @ts-expect-error TypeScript can’t narrow down the type of JSON imports schema, fileMatch: ['monaco-yaml.yaml'] } diff --git a/package-lock.json b/package-lock.json index d8b2dda..6f65e8a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,6 @@ "examples/*" ], "dependencies": { - "@types/json-schema": "^7.0.0", "jsonc-parser": "^3.0.0", "monaco-languageserver-types": "^0.3.0", "monaco-marker-data-provider": "^1.0.0", diff --git a/package.json b/package.json index 636601a..87e42e0 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,6 @@ "yaml" ], "dependencies": { - "@types/json-schema": "^7.0.0", "jsonc-parser": "^3.0.0", "monaco-languageserver-types": "^0.3.0", "monaco-marker-data-provider": "^1.0.0", diff --git a/src/index.ts b/src/index.ts index 01dc14c..ea97547 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,3 @@ -import { type JSONSchema4, type JSONSchema6, type JSONSchema7 } from 'json-schema' import { fromCodeActionContext, fromFormattingOptions, @@ -18,9 +17,81 @@ import { import { registerMarkerDataProvider } from 'monaco-marker-data-provider' import { type IDisposable, type MonacoEditor } from 'monaco-types' import { createWorkerManager } from 'monaco-worker-manager' +import { type CompletionItemKind } from 'vscode-languageserver-types' import { type YAMLWorker } from './yaml.worker.js' +/* eslint-disable jsdoc/require-jsdoc */ +export interface JSONSchema { + id?: string + $id?: string + $schema?: string + url?: string + type?: string[] | string + title?: string + closestTitle?: string + versions?: Record + default?: unknown + definitions?: Record + description?: string + properties?: Record + patternProperties?: Record + additionalProperties?: JSONSchema | boolean + minProperties?: number + maxProperties?: number + dependencies?: Record + items?: (JSONSchema | boolean)[] | JSONSchema | boolean + minItems?: number + maxItems?: number + uniqueItems?: boolean + additionalItems?: JSONSchema | boolean + pattern?: string + minLength?: number + maxLength?: number + minimum?: number + maximum?: number + exclusiveMinimum?: boolean | number + exclusiveMaximum?: boolean | number + multipleOf?: number + required?: string[] + $ref?: string + anyOf?: (JSONSchema | boolean)[] + allOf?: (JSONSchema | boolean)[] + oneOf?: (JSONSchema | boolean)[] + not?: JSONSchema | boolean + enum?: unknown[] + format?: string + const?: unknown + contains?: JSONSchema | boolean + propertyNames?: JSONSchema | boolean + examples?: unknown[] + $comment?: string + if?: JSONSchema | boolean + then?: JSONSchema | boolean + else?: JSONSchema | boolean + defaultSnippets?: { + label?: string + description?: string + markdownDescription?: string + type?: string + suggestionKind?: CompletionItemKind + sortText?: string + body?: unknown + bodyText?: string + }[] + errorMessage?: string + patternErrorMessage?: string + deprecationMessage?: string + enumDescriptions?: string[] + markdownEnumDescriptions?: string[] + markdownDescription?: string + doNotSuggest?: boolean + allowComments?: boolean + schemaSequence?: JSONSchema[] + filePatternAssociation?: string +} +/* eslint-enable jsdoc/require-jsdoc */ + export interface SchemasSettings { /** * A `Uri` file match which will trigger the schema validation. This may be a glob or an exact @@ -35,7 +106,7 @@ export interface SchemasSettings { * The JSON schema which will be used for validation. If not specified, it will be downloaded from * `uri`. */ - schema?: JSONSchema4 | JSONSchema6 | JSONSchema7 + schema?: JSONSchema /** * The source URI of the JSON schema. The JSON schema will be downloaded from here if no schema