Skip to content

Commit

Permalink
Inline the JSONSchema type from yaml-language-server
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
remcohaszing committed Jul 7, 2024
1 parent f32b483 commit b319bf6
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
extends:
- remcohaszing
rules:
eslint-comments/no-use: off

import/no-extraneous-dependencies: off

n/no-extraneous-import: off
1 change: 0 additions & 1 deletion examples/demo/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}
Expand Down
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
75 changes: 73 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { type JSONSchema4, type JSONSchema6, type JSONSchema7 } from 'json-schema'
import {
fromCodeActionContext,
fromFormattingOptions,
Expand All @@ -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<string, string>
default?: unknown
definitions?: Record<string, JSONSchema>
description?: string
properties?: Record<string, JSONSchema | boolean>
patternProperties?: Record<string, JSONSchema | boolean>
additionalProperties?: JSONSchema | boolean
minProperties?: number
maxProperties?: number
dependencies?: Record<string, JSONSchema | string[] | boolean>
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
Expand All @@ -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
Expand Down

0 comments on commit b319bf6

Please sign in to comment.