Skip to content

Commit 9725851

Browse files
committed
feat: support JSON Schema draft-04
1 parent 08467d7 commit 9725851

File tree

6 files changed

+348
-14
lines changed

6 files changed

+348
-14
lines changed

__tests__/main.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,24 @@ describe('action', () => {
283283
}
284284
});
285285

286+
it('fails if schema missing $schema key', async () => {
287+
mockGetBooleanInput({});
288+
mockGetInput({ schema });
289+
mockGetMultilineInput({ files });
290+
291+
jest
292+
.mocked(fs.readFile)
293+
.mockResolvedValueOnce(schemaContents.replace('$schema', '_schema'));
294+
295+
await main.run();
296+
expect(runSpy).toHaveReturned();
297+
expect(process.exitCode).not.toBeDefined();
298+
299+
expect(core.setFailed).toHaveBeenLastCalledWith(
300+
'JSON schema missing $schema key'
301+
);
302+
});
303+
286304
it('fails if no files to validate', async () => {
287305
mockGetBooleanInput({});
288306
mockGetInput({ schema });
@@ -377,4 +395,28 @@ describe('action', () => {
377395
expect(core.debug).toHaveBeenCalledWith(`𐄂 ${paths[0]} is not valid`);
378396
expect(core.debug).toHaveBeenCalledWith(`✓ ${paths[1]} is valid`);
379397
});
398+
399+
it('supports JSON Schema draft-04', async () => {
400+
mockGetBooleanInput({});
401+
mockGetInput({ schema });
402+
mockGetMultilineInput({ files });
403+
404+
jest
405+
.mocked(fs.readFile)
406+
.mockResolvedValueOnce(
407+
schemaContents.replace(
408+
'http://json-schema.org/draft-07/schema#',
409+
'http://json-schema.org/draft-04/schema#'
410+
)
411+
)
412+
.mockResolvedValueOnce(instanceContents);
413+
mockGlobGenerator(['/foo/bar/baz/config.yml']);
414+
415+
await main.run();
416+
expect(runSpy).toHaveReturned();
417+
expect(process.exitCode).not.toBeDefined();
418+
419+
expect(core.setOutput).toHaveBeenCalledTimes(1);
420+
expect(core.setOutput).toHaveBeenLastCalledWith('valid', true);
421+
});
380422
});

dist/index.js

Lines changed: 244 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/licenses.txt

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)