Skip to content

Commit

Permalink
Add field constraint indicator for uniqueItems (#1423)
Browse files Browse the repository at this point in the history
* Add field constraint indicator for uniqueItems

Resolves #1353

* Update src/components/Fields/FieldContstraints.tsx

Co-authored-by: Roman Hotsiy <gotsijroman@gmail.com>
  • Loading branch information
miqh and RomanHotsiy committed Oct 27, 2020
1 parent e2de5b0 commit d4ae371
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/utils/__tests__/openapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ describe('Utils', () => {
min: number | undefined = undefined,
max: number | undefined = undefined,
multipleOf: number | undefined = undefined,
) => ({ type: 'array', minItems: min, maxItems: max, multipleOf });
uniqueItems?: boolean,
) => ({ type: 'array', minItems: min, maxItems: max, multipleOf, uniqueItems });

it('should not have a humanized constraint without schema constraints', () => {
expect(humanizeConstraints(itemConstraintSchema())).toHaveLength(0);
Expand Down Expand Up @@ -372,6 +373,12 @@ describe('Utils', () => {
'multiple of 0.5',
);
});

it('should have a humanized constraint when uniqueItems is set', () => {
expect(humanizeConstraints(itemConstraintSchema(undefined, undefined, undefined, true))).toContain(
'unique',
);
});
});

describe('OpenAPI pluralizeType', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,10 @@ export function humanizeConstraints(schema: OpenAPISchema): string[] {
res.push(numberRange);
}

if (schema.uniqueItems) {
res.push('unique');
}

return res;
}

Expand Down

0 comments on commit d4ae371

Please sign in to comment.