Open adietish opened 1 year ago
It very much looks like the current platform schema validation framework only supports using a single schema file per editor. It seems unable to use multiple schema files per json/yaml file that is edited (multi-resource files contains multiple individual resources separated by ---
and each resource should be validated against it's own schema). If this is confirmed we'd have to get away from using or extending the platform implementation.
in vscode this was requested and they found a workaround indicating the schemas: https://github.com/redhat-developer/vscode-yaml/issues/702#issuecomment-1048518781
I tried to provide KubernetesSchemaProvider
s which would return true
if one of the resources in the file match the typeinfo in the schema provider:
override fun isAvailable(file: VirtualFile): Boolean {
return ApplicationManager.getApplication().runReadAction(
Computable {
/*
val psiFile = PsiManager.getInstance(project!!).findFile(file)
if (psiFile == null) {
false
} else {
val fileInfo = KubernetesTypeInfo.extractMeta(psiFile)
info == fileInfo
}
*/
val fileContent = String(file.contentsToByteArray(true))
val resources = EditorResourceSerialization.deserialize(fileContent, file.fileType, null)
resources.any { resource ->
info.kind == resource.kind
&& info.apiGroup == resource.apiVersion
}
})
}
But this results in no schema being considered at all.
I dug into the json plugin/platform and found out that the validation is done on behalf of JsonSchemaComplianceChecker
.
Interestingly JsonSchemaComplianceChecker#annotate()
is called 3 times for the 3 resources. The root schema is the deployment schema though. Maybe if we can provide a composite schema which holds the 3 schema would help work around it.
JsonSchemaComplianceChecker
is created by JsonSchemaComplianceInspection
which is declared as local inspection in the json plugin:
<localInspection language="JSON" shortName="JsonSchemaCompliance"
bundle="messages.JsonBundle" key="json.schema.inspection.compliance.name" groupKey="json.inspection.group"
enabledByDefault="true" level="WARNING"
implementationClass="com.jetbrains.jsonSchema.impl.inspections.JsonSchemaComplianceInspection"/>
I talked to Yann Cébron on Jetbrains Slack #intellij-platform and he told me that he'd investigate the possibilities to use several schemas to validate a single json/yaml file.
Steps:
Deployment
Result: The schema that is applied still is
Service
(first resource in the document)