Skip to content

fix(to-json-schema): translate v.file() schema #1119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/to-json-schema/src/convertSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@
type: 'string',
});
});

test('should convert file schema', () => {
expect(
convertSchema({}, v.file(), undefined, createContext())
).toStrictEqual({
type: 'string',
format: 'binary',
});
});
});

describe('complex schemas', () => {
Expand Down Expand Up @@ -869,7 +878,7 @@
undefined,
createContext()
)
).toThrowError(error);

Check failure on line 881 in packages/to-json-schema/src/convertSchema.test.ts

View workflow job for this annotation

GitHub Actions / Run Vitest in packages/to-json-schema

src/convertSchema.test.ts > convertSchema > other schemas > should throw error for unsupported file schema

AssertionError: expected [Function] to throw an error - Expected: null + Received: undefined ❯ src/convertSchema.test.ts:881:9
expect(() =>
convertSchema(
{},
Expand All @@ -885,7 +894,7 @@
expect(
// @ts-expect-error
convertSchema({}, v.file(), { errorMode: 'warn' }, createContext())
).toStrictEqual({});

Check failure on line 897 in packages/to-json-schema/src/convertSchema.test.ts

View workflow job for this annotation

GitHub Actions / Run Vitest in packages/to-json-schema

src/convertSchema.test.ts > convertSchema > other schemas > should warn error for unsupported file schema

AssertionError: expected { type: 'string', format: 'binary' } to strictly equal {} - Expected + Received - {} + { + "format": "binary", + "type": "string", + } ❯ src/convertSchema.test.ts:897:9
expect(console.warn).toHaveBeenLastCalledWith(
'The "file" schema cannot be converted to JSON Schema.'
);
Expand Down
6 changes: 6 additions & 0 deletions packages/to-json-schema/src/convertSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ export function convertSchema(
break;
}

case 'file': {
jsonSchema.type = 'string';
jsonSchema.format = 'binary';
break;
}

// Complex schemas

case 'array': {
Expand Down
Loading