@@ -160,21 +160,41 @@ export class YAMLSchemaService extends JSONSchemaService {
160
160
let schema : JSONSchema = schemaToResolve . schema ;
161
161
const contextService = this . contextService ;
162
162
163
- if ( typeof schema !== 'object' || schema === null || Array . isArray ( schema ) ) {
164
- const invalidSchemaType = Array . isArray ( schema ) ? 'array' : typeof schema ;
165
- resolveErrors . push (
166
- `Schema '${ getSchemaTitle ( schemaToResolve . schema , schemaURL ) } ' is not valid:\nWrong schema: "${ invalidSchemaType } ", it MUST be an Object or Boolean`
167
- ) ;
168
- } else {
169
- try {
170
- const schemaVersion = this . detectSchemaVersion ( schema ) ;
171
- const validator = this . getValidatorForVersion ( schemaVersion ) ;
172
- const metaSchemaUrl = this . getSchemaMetaSchema ( schemaVersion ) ;
173
- if ( ! validator . hasSchema ( schema ) ) {
174
- validator . registerSchema ( { $schema : metaSchemaUrl , type : 'string' } , schema ) ;
175
- }
163
+ // Validate schema type before processing
164
+ if ( schema === null ) {
165
+ resolveErrors . push ( `Wrong schema: "null", it MUST be an Object or Boolean` ) ;
166
+ return new ResolvedSchema ( { } , resolveErrors ) ;
167
+ }
168
+
169
+ if ( Array . isArray ( schema ) ) {
170
+ resolveErrors . push ( `Wrong schema: "array", it MUST be an Object or Boolean` ) ;
171
+ return new ResolvedSchema ( { } , resolveErrors ) ;
172
+ }
173
+
174
+ if ( typeof schema === 'string' ) {
175
+ resolveErrors . push ( `Wrong schema: "string", it MUST be an Object or Boolean` ) ;
176
+ return new ResolvedSchema ( { } , resolveErrors ) ;
177
+ }
176
178
177
- // Validate the schema against its meta-schema using the URL directly
179
+ if ( typeof schema === 'number' ) {
180
+ resolveErrors . push ( `Wrong schema: "number", it MUST be an Object or Boolean` ) ;
181
+ return new ResolvedSchema ( { } , resolveErrors ) ;
182
+ }
183
+
184
+ // Only proceed if schema is an object or boolean
185
+ if ( typeof schema !== 'object' && typeof schema !== 'boolean' ) {
186
+ resolveErrors . push ( `Wrong schema: "${ typeof schema } ", it MUST be an Object or Boolean` ) ;
187
+ return new ResolvedSchema ( { } , resolveErrors ) ;
188
+ }
189
+
190
+ const schemaVersion = this . detectSchemaVersion ( schema ) ;
191
+ const validator = this . getValidatorForVersion ( schemaVersion ) ;
192
+ const metaSchemaUrl = this . getSchemaMetaSchema ( schemaVersion ) ;
193
+
194
+ // Only validate object schemas against their meta-schema
195
+ // Boolean schemas (true/false) are valid by definition and don't need meta-schema validation
196
+ if ( typeof schema === 'object' && schema !== null ) {
197
+ try {
178
198
const result = await validator . validate ( metaSchemaUrl , schema , 'BASIC' ) ;
179
199
if ( ! result . valid && result . errors ) {
180
200
const errs : string [ ] = [ ] ;
@@ -187,9 +207,11 @@ export class YAMLSchemaService extends JSONSchemaService {
187
207
resolveErrors . push ( `Schema '${ getSchemaTitle ( schemaToResolve . schema , schemaURL ) } ' is not valid:\n${ errs . join ( '\n' ) } ` ) ;
188
208
}
189
209
}
190
- } catch ( error ) {
191
- // If meta-schema validation fails, log but don't block schema loading
192
- console . error ( `Failed to validate schema meta-schema: ${ error . message } ` ) ;
210
+ } catch ( validationError ) {
211
+ // If validation fails due to incompatible data, add a generic error
212
+ resolveErrors . push (
213
+ `Schema '${ getSchemaTitle ( schemaToResolve . schema , schemaURL ) } ' validation failed: ${ validationError . message } `
214
+ ) ;
193
215
}
194
216
}
195
217
@@ -761,6 +783,9 @@ export class YAMLSchemaService extends JSONSchemaService {
761
783
* Detect the JSON Schema version from the $schema property
762
784
*/
763
785
private detectSchemaVersion ( schema : JSONSchema ) : SupportedSchemaVersion {
786
+ if ( ! schema || typeof schema !== 'object' ) {
787
+ return 'draft-07' ;
788
+ }
764
789
const schemaProperty = schema . $schema ;
765
790
if ( typeof schemaProperty === 'string' ) {
766
791
if ( schemaProperty . includes ( '2020-12' ) ) {
0 commit comments