Skip to content

Commit

Permalink
fix: default yaml version for schema validation
Browse files Browse the repository at this point in the history
  • Loading branch information
galargh committed Mar 16, 2023
1 parent 7ccb137 commit 3372e55
Show file tree
Hide file tree
Showing 6 changed files with 353 additions and 152 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [1.0.1] - 2023-03-16
### Fixed
- provided default YAML version for schema validation

## [1.0.0] - 2023-03-09
### Changed
- released v1.0.0 from pl-strflt org since https://github.com/nwisbeta/validate-yaml-schema is archived
Expand Down
365 changes: 282 additions & 83 deletions lib/index.js

Large diffs are not rendered by default.

109 changes: 53 additions & 56 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"homepage": "https://github.com/pl-strflt/validate-yaml-schema",
"dependencies": {
"@actions/core": "^1.6.0",
"@actions/core": "^1.10.0",
"glob": "^7.2.0",
"yaml-language-server": "1.2.2"
},
Expand Down
4 changes: 2 additions & 2 deletions src/file-reader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from 'fs';
import { TextDocument } from 'vscode-languageserver';
import { TextDocument } from 'vscode-languageserver-textdocument';
import { InvalidFileError } from './errors';

export const getYaml = async (filePath: string): Promise<TextDocument> => {
Expand All @@ -25,4 +25,4 @@ export const getJson = async (filePath: string): Promise<any> => {
} catch (ex) {
throw new InvalidFileError(filePath, ex);
}
};
};
21 changes: 11 additions & 10 deletions src/schema-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { YAMLValidation } from 'yaml-language-server/lib/umd/languageservice/ser
import { YAMLSchemaService } from 'yaml-language-server/lib/umd/languageservice/services/yamlSchemaService'
import { schemaRequestHandler } from './services/schemaRequestHandler'

export class SchemaValidator {
export class SchemaValidator {

constructor(schemaSettings : any, workspaceRoot : string) {
this.addSchemaSettings(schemaSettings);
this.addSchemaSettings(schemaSettings);
this.buildValidator(workspaceRoot);
}

Expand All @@ -21,14 +21,15 @@ export class SchemaValidator {
format: false,
isKubernetes: false,
schemas: [],
customTags: []
customTags: [],
yamlVersion: '1.2'
};

private addSchemaSettings(schemaSettings) {

for (const uri in schemaSettings) {
const globPattern = schemaSettings[uri];

const schemaObj = {
'fileMatch': Array.isArray(globPattern) ? globPattern : [globPattern],
'uri': uri
Expand All @@ -41,11 +42,11 @@ export class SchemaValidator {

// Request Service: Fetches file content from given location
const requestService = schemaRequestHandler.bind(null, workspaceRoot);

// Context Service: Resolves relative file locations (not sure why it's needed as request service handles that too...)
const contextService = {
resolveRelativePath: (relativePath: string, resource: string) =>
URL.resolve(resource, relativePath)
resolveRelativePath: (relativePath: string, resource: string) =>
URL.resolve(resource, relativePath)
};

/////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -86,8 +87,8 @@ export class SchemaValidator {
console.log(JSON.stringify(results));
return false;
}

return true;
}

};
};

0 comments on commit 3372e55

Please sign in to comment.