Skip to content

Commit

Permalink
feat: support JSON Schema draft-04
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanders11 committed Dec 30, 2023
1 parent 08467d7 commit 9725851
Show file tree
Hide file tree
Showing 6 changed files with 348 additions and 14 deletions.
42 changes: 42 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,24 @@ describe('action', () => {
}
});

it('fails if schema missing $schema key', async () => {
mockGetBooleanInput({});
mockGetInput({ schema });
mockGetMultilineInput({ files });

jest
.mocked(fs.readFile)
.mockResolvedValueOnce(schemaContents.replace('$schema', '_schema'));

await main.run();
expect(runSpy).toHaveReturned();
expect(process.exitCode).not.toBeDefined();

expect(core.setFailed).toHaveBeenLastCalledWith(
'JSON schema missing $schema key'
);
});

it('fails if no files to validate', async () => {
mockGetBooleanInput({});
mockGetInput({ schema });
Expand Down Expand Up @@ -377,4 +395,28 @@ describe('action', () => {
expect(core.debug).toHaveBeenCalledWith(`𐄂 ${paths[0]} is not valid`);
expect(core.debug).toHaveBeenCalledWith(`✓ ${paths[1]} is valid`);
});

it('supports JSON Schema draft-04', async () => {
mockGetBooleanInput({});
mockGetInput({ schema });
mockGetMultilineInput({ files });

jest
.mocked(fs.readFile)
.mockResolvedValueOnce(
schemaContents.replace(
'http://json-schema.org/draft-07/schema#',
'http://json-schema.org/draft-04/schema#'
)
)
.mockResolvedValueOnce(instanceContents);
mockGlobGenerator(['/foo/bar/baz/config.yml']);

await main.run();
expect(runSpy).toHaveReturned();
expect(process.exitCode).not.toBeDefined();

expect(core.setOutput).toHaveBeenCalledTimes(1);
expect(core.setOutput).toHaveBeenLastCalledWith('valid', true);
});
});
252 changes: 244 additions & 8 deletions dist/index.js

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

25 changes: 25 additions & 0 deletions dist/licenses.txt

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

Loading

0 comments on commit 9725851

Please sign in to comment.