Skip to content

fix: No maxLength label is displayed for arrays of items #1701#1765

Merged
Oprysk merged 9 commits into
masterfrom
fix/No-maxLength-label-is-displayed
Jan 5, 2022
Merged

fix: No maxLength label is displayed for arrays of items #1701#1765
Oprysk merged 9 commits into
masterfrom
fix/No-maxLength-label-is-displayed

Conversation

@zalesky

@zalesky zalesky commented Oct 8, 2021

Copy link
Copy Markdown
Contributor

What/Why/How?

closes: #1701

Reference

Screenshots (optional)

parameters example:

parameters:
  - name: some parameter
    in: path
    schema:
      type: array
      items:
        type: string
        maxLength: 80
        contentEncoding: contentEncoding
  - name: some other parameter
    in: path
    schema:
      type: array
      items:
        type: string
        maxLength: 80
        description: description
        pattern: "^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}$"
  - name: parameter
    in: path
    schema:
      type: string
      maxLength: 80
      description: description
      pattern: "^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}$"
  - name: diff parameter
    in: query
    schema:
      type: array
      items:
        type: string
        description: My start list description
        minLength: 3
        maxLength: 100
      maxItems: 12

Before fix:

Screenshot 2021-10-08 at 13 48 36

After fix:
Screenshot 2021-10-12 at 15 09 16

additional cases:

orderId_0:
  type: array
  minItems: 1
  items:
    type: string
    maxLength: 100
    minLength: 1
    enum: [Jr. Test, Dr. Tester]
    pattern: "^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}$"
    description: "^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}$"
orderId_1:
  type: string
  maxLength: 80
  description: description
  pattern: "^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}$"
orderId_2:
  type: array
  minItems: 1
  items:
    type: array
    minItems: 3
    items:
      type: string
orderId_3:
  type: array
  items:
    type: string
orderId_4:
  type: array
  items:
    type: string
    format: url

Screenshot 2021-10-12 at 15 10 48

Check yourself

  • Code is linted
  • Tested
  • All new/updated code is covered with tests

@zalesky zalesky requested a review from AlexVarchuk October 8, 2021 11:26
@RomanHotsiy

Copy link
Copy Markdown
Member

@zalesky can you update screenshots plz?

@zalesky

zalesky commented Oct 11, 2021

Copy link
Copy Markdown
Contributor Author

@RomanHotsiy updated

@zalesky zalesky marked this pull request as draft October 12, 2021 07:07
@zalesky zalesky self-assigned this Oct 12, 2021
@zalesky zalesky marked this pull request as ready for review October 27, 2021 13:50
@AlexVarchuk

Copy link
Copy Markdown
Collaborator

@RomanHotsiy @zalesky Should we support type as an array: [string] in version openAPI 3.1?

parameters:
  - name: some parameter
    in: path
    schema:
      type: [string]
      items:
        type: string
        maxLength: 80
        contentEncoding: contentEncoding

https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#section-6.1.1

@jeremyfiel

Copy link
Copy Markdown

Can this be merged? @RomanHotsiy

@RomanHotsiy

Copy link
Copy Markdown
Member

@jeremyfiel no, not yet. We're still trying to find an optimal UI for this.

@jeremyfiel

jeremyfiel commented Dec 14, 2021

Copy link
Copy Markdown

can I suggest using the following text blocks?

following use cases of minLength, maxLength, and pattern for strings and range (minimum and maximum), multipleOf for integers. Also, exclusiveMinimum, or exclusiveMaximum can be extended for the range example.
I think the pattern could become very long and messy on the UI, maybe a tooltip over the pattern component might be helpful, just make sure it's accessible by a screen reader.

Array of strings having <= 80 characters

      properties:
        name:
          description: 'this is a description'
          type: array
          items:
            type: string
            maxLength: 80

Array of strings having ^[a-z]$

      properties:
        name:
          description: 'this is a description'
          type: array
          items:
            type: string
            pattern: '^[a-z]$'

Array of strings having >= 2 characters and <= 80 characters

      properties:
        name:
          description: 'this is a description'
          type: array
          items:
            type: string
            minLength: 2
            maxLength: 80

Array of strings having >= 2 characters and <= 80 characters and ^[a-z]$

      properties:
        name:
          description: 'this is a description'
          type: array
          items:
            type: string
            minLength: 2
            maxLength: 80
            pattern: '^[a-z]$'

Array of integers as a multipleOf 5

      properties:
        name:
          description: 'this is a description'
          type: array
          items:
            type: integer
            multipleOf: 5

Array of integers as a multipleOf 5 with a maximum of 10

      properties:
        name:
          description: 'this is a description'
          type: array
          items:
            type: integer
            multipleOf: 5
            maximum: 10

Array of integers as a multipleOf 5 with a minimum of 5 and maximum of 10

      properties:
        name:
          description: 'this is a description'
          type: array
          items:
            type: integer
            multipleOf: 5
            minimum: 5
            maximum: 10

Array of integers between [1 ... 100]

      properties:
        name:
          description: 'this is a description'
          type: array
          items:
            type: integer
            minimum: 1
            maximum: 100

Valid in both OAS3.0.x AND OAS3.1.x
Array of integers between [1 ... 99]

      properties:
        name:
          description: 'this is a description'
          type: array
          items:
            type: integer
            minimum: 1
            exclusiveMaximum: true
            maximum: 100

Valid only for OAS3.1.x
OAS3.1.x aligned with JSON-Schema to allow exclusiveMaximum to hold the maximum integer value rather than boolean.

Array of integers between [1 ... 99]

      properties:
        name:
          description: 'this is a description'
          type: array
          items:
            type: integer
            minimum: 1
            exclusiveMaximum: 100

@RomanHotsiy RomanHotsiy assigned Oprysk and unassigned zalesky Jan 5, 2022
@Oprysk

Oprysk commented Jan 5, 2022

Copy link
Copy Markdown
Contributor

updated to:
image

@Oprysk Oprysk merged commit 6c7685e into master Jan 5, 2022
@Oprysk Oprysk deleted the fix/No-maxLength-label-is-displayed branch January 5, 2022 15:11
export function ArrayItemDetails({ schema }: { schema: SchemaModel }) {
if (!schema || (schema.type === 'string' && !schema.constraints.length)) return null;

return (

@roberfi roberfi Feb 11, 2022

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi. This is causing that type label of arrays of any type except string is always followed by [ items ], even if no information about items is provided:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: No maxLength label is displayed for arrays of items

6 participants