fix: The number of items in the array in the array is incorrect #1762 (#1763)

This commit is contained in:
Andriy Zaleskyy 2021-10-11 13:05:50 +03:00 committed by GitHub
parent 43451ba4cd
commit 3b8d6441bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 55 additions and 12 deletions

View File

@ -533,6 +533,20 @@ paths:
subscriptionId:
type: string
example: AAA-123-BBB-456
'200':
description: Successful operation
content:
application/json:
schema:
type: array
maxItems: 999
minItems: 0
items:
type: array
maxItems: 777
minItems: 111
items:
type: number
callbacks:
orderInProgress:
'{$request.body#/callbackUrl}?event={$request.body#/eventName}':

View File

@ -377,7 +377,9 @@ paths:
application/xml:
schema:
type: array
maxItems: 999
items:
maxItems: 111
$ref: '#/components/schemas/Pet'
'400':
description: Invalid tag value

View File

@ -13,15 +13,12 @@ const PaddedSchema = styled.div`
export class ArraySchema extends React.PureComponent<SchemaProps> {
render() {
const itemsSchema = this.props.schema.items!;
const schema = this.props.schema;
const itemsSchema = schema.items;
const itemConstraintSchema = (
min: number | undefined = undefined,
max: number | undefined = undefined,
) => ({ type: 'array', minItems: min, maxItems: max });
const minMaxItems = humanizeConstraints(itemConstraintSchema(itemsSchema?.schema?.minItems, itemsSchema?.schema?.maxItems));
const minMaxItems = schema.minItems === undefined && schema.maxItems === undefined ?
'' :
`(${humanizeConstraints(schema)})`;
if (schema.displayType && !itemsSchema && !minMaxItems.length) {
return (<div>
@ -31,7 +28,7 @@ export class ArraySchema extends React.PureComponent<SchemaProps> {
return (
<div>
<ArrayOpenningLabel> Array ({minMaxItems})</ArrayOpenningLabel>
<ArrayOpenningLabel> Array {minMaxItems}</ArrayOpenningLabel>
<PaddedSchema>
<Schema {...this.props} schema={itemsSchema} />
</PaddedSchema>

View File

@ -33,6 +33,8 @@ exports[`Components SchemaView discriminator should correctly render discriminat
"format": undefined,
"isCircular": undefined,
"isPrimitive": true,
"maxItems": undefined,
"minItems": undefined,
"options": "<<<filtered>>>",
"pattern": undefined,
"pointer": "#/components/schemas/Dog/properties/packSize",
@ -86,6 +88,8 @@ exports[`Components SchemaView discriminator should correctly render discriminat
"format": undefined,
"isCircular": undefined,
"isPrimitive": true,
"maxItems": undefined,
"minItems": undefined,
"options": "<<<filtered>>>",
"pattern": undefined,
"pointer": "#/components/schemas/Dog/properties/type",

View File

@ -63,6 +63,8 @@ export class SchemaModel {
const: any;
contentEncoding?: string;
contentMediaType?: string;
minItems?: number;
maxItems?: number;
/**
* @param isChild if schema discriminator Child
@ -128,6 +130,8 @@ export class SchemaModel {
this.const = schema.const || '';
this.contentEncoding = schema.contentEncoding;
this.contentMediaType = schema.contentMediaType;
this.minItems = schema.minItems;
this.maxItems = schema.maxItems;
if (!!schema.nullable || schema['x-nullable']) {
if (Array.isArray(this.type) && !this.type.some((value) => value === null || value === 'null')) {

View File

@ -729,7 +729,9 @@ try {
"schema": Object {
"items": Object {
"$ref": "#/components/schemas/Pet",
"maxItems": 111,
},
"maxItems": 999,
"type": "array",
},
},
@ -3245,6 +3247,26 @@ culpa qui officia deserunt mollit anim id est laborum.
},
},
"responses": Object {
"200": Object {
"content": Object {
"application/json": Object {
"schema": Object {
"items": Object {
"items": Object {
"type": "number",
},
"maxItems": 777,
"minItems": 111,
"type": "array",
},
"maxItems": 999,
"minItems": 0,
"type": "array",
},
},
},
"description": "Successful operation",
},
"201": Object {
"content": Object {
"application/json": Object {

View File

@ -412,10 +412,10 @@ describe('Utils', () => {
describe('openapi humanizeConstraints', () => {
const itemConstraintSchema = (
min: number | undefined = undefined,
max: number | undefined = undefined,
multipleOf: number | undefined = undefined,
uniqueItems?: boolean,
min?: number,
max?: number,
multipleOf?: number,
uniqueItems?: boolean
) => ({ type: 'array', minItems: min, maxItems: max, multipleOf, uniqueItems });
it('should not have a humanized constraint without schema constraints', () => {