Skip to content
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

Added conditional properties and required field assignment in uniforms-bridge-json-schema (closing #919). #936

Merged
merged 7 commits into from
Apr 22, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,23 @@ describe('JSONSchemaBridge', () => {
},
],
},
nonObjectAnyOfRequired: {
anyOf: [
{
const: 'alphabetic',
type: 'string',
},
{
enum: ['top', 'middle', 'bottom'],
type: 'string',
},
{
type: 'number',
minimum: 0,
},
],
required: true,
radekmie marked this conversation as resolved.
Show resolved Hide resolved
},
},
required: ['dateOfBirth'],
};
Expand Down Expand Up @@ -735,6 +752,13 @@ describe('JSONSchemaBridge', () => {
);
});

it('works with anyOf for a non-object computed property (required)', () => {
expect(bridge.getProps('nonObjectAnyOfRequired')).toHaveProperty(
'required',
true,
);
});

it('works with anyOf for a non-object computed property (properties not defined)', () => {
expect(bridge.getProps('nonObjectAnyOf')).toHaveProperty(
'properties',
Expand Down Expand Up @@ -784,6 +808,7 @@ describe('JSONSchemaBridge', () => {
'recursive',
'arrayWithAllOf',
'nonObjectAnyOf',
'nonObjectAnyOfRequired',
]);
});

Expand Down
10 changes: 8 additions & 2 deletions packages/uniforms-bridge-json-schema/src/JSONSchemaBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,14 @@ export default class JSONSchemaBridge extends Bridge {
.filter(Boolean);

if (combinedPartials.length) {
const localProperties = definition.properties ? { ...definition.properties } : {};
const localRequired = definition.required ? definition.required.slice() : [];
const localProperties = definition.properties
? { ...definition.properties }
: {};
const localRequired = definition.required
? Array.isArray(definition.required)
? definition.required.slice()
: definition.required
: [];
radekmie marked this conversation as resolved.
Show resolved Hide resolved

combinedPartials.forEach(({ properties, required, type }) => {
if (properties) {
Expand Down