protected getFirstPropertyMatches()

in language-service/src/parser/jsonParser.ts [1063:1113]


	protected getFirstPropertyMatches(subSchemas: JSONSchema[]): JSONSchema[] {
		const firstProperty = this.properties[0];
		if (!firstProperty?.key?.value) {
			return [];
		}

		const firstPropKey: string = firstProperty.key.value;

		const matches: JSONSchema[] = [];

		subSchemas.forEach((schema:JSONSchema) => {
			if (schema.firstProperty && schema.firstProperty.length) {
				let firstPropSchemaName: string = null;
				if (schema.firstProperty.indexOf(firstPropKey) >= 0) {
					firstPropSchemaName = firstPropKey;
				}
				else if (ASTNode.getIgnoreKeyCase(schema)) {
					const firstPropCompareKey: string = firstPropKey.toUpperCase();

					schema.firstProperty.some( (schemaProp: string) => {
						if (schemaProp.toUpperCase() === firstPropCompareKey) {
							firstPropSchemaName = schemaProp;
							return true;
						}
						return false;
					});
				}

				if (firstPropSchemaName != null) {
					if (!schema.properties) {
						matches.push(schema);
					}
					else {
						const propertySchema: JSONSchema = schema.properties[firstPropSchemaName];
						if (!propertySchema) {
							matches.push(schema);
						}
						else {
							let propertyValidationResult = new ValidationResult();
							firstProperty.validate(propertySchema, propertyValidationResult, new SchemaCollector(-1, null));
							if (!propertyValidationResult.hasProblems()) {
								matches.push(schema);
							}
						}
					}
				}
			}
		});

		return matches;
	}