From 13aa7133bc5153d402f96e30f74ff148643fa95f Mon Sep 17 00:00:00 2001 From: Michael Huynh Date: Sun, 18 Oct 2020 09:48:55 +0800 Subject: [PATCH 1/2] Add field constraint indicator for uniqueItems Resolves #1353 --- src/components/Fields/FieldContstraints.tsx | 2 +- src/utils/__tests__/openapi.test.ts | 9 ++++++++- src/utils/openapi.ts | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/Fields/FieldContstraints.tsx b/src/components/Fields/FieldContstraints.tsx index c92e8f5c50..d490c1e9f5 100644 --- a/src/components/Fields/FieldContstraints.tsx +++ b/src/components/Fields/FieldContstraints.tsx @@ -14,7 +14,7 @@ export class ConstraintsView extends React.PureComponent { {' '} {this.props.constraints.map(constraint => ( - {constraint} + {constraint} ))} ); diff --git a/src/utils/__tests__/openapi.test.ts b/src/utils/__tests__/openapi.test.ts index 94fb1e0c93..9e511259f1 100644 --- a/src/utils/__tests__/openapi.test.ts +++ b/src/utils/__tests__/openapi.test.ts @@ -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); @@ -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', () => { diff --git a/src/utils/openapi.ts b/src/utils/openapi.ts index ad98c811b3..e20dbef9d6 100644 --- a/src/utils/openapi.ts +++ b/src/utils/openapi.ts @@ -448,6 +448,10 @@ export function humanizeConstraints(schema: OpenAPISchema): string[] { res.push(numberRange); } + if (schema.uniqueItems) { + res.push('unique'); + } + return res; } From d438bbc237576eba0186889cb050ab3704e03a1f Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Tue, 27 Oct 2020 10:50:26 +0200 Subject: [PATCH 2/2] Update src/components/Fields/FieldContstraints.tsx --- src/components/Fields/FieldContstraints.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Fields/FieldContstraints.tsx b/src/components/Fields/FieldContstraints.tsx index d490c1e9f5..c92e8f5c50 100644 --- a/src/components/Fields/FieldContstraints.tsx +++ b/src/components/Fields/FieldContstraints.tsx @@ -14,7 +14,7 @@ export class ConstraintsView extends React.PureComponent { {' '} {this.props.constraints.map(constraint => ( - {constraint} + {constraint} ))} );