swagger-api / swagger-api/swagger-ui

Array length validation issue

Open
#8,208 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Q&A (please complete the following information)
  • OS: macOS
  • Browser: chrome
  • Version: 106.0.5249.61
  • Method of installation: npm
  • Swagger-UI version: 4.14.0
  • Swagger/OpenAPI version: OpenAPI 3.0
Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.0.0
info:
  title: Hello world swagger
  version: 1.0.0
  description: Hello world swagger description
paths:
  /:
    post:
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/String'
      parameters: []
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file2:
                  type: array
                  items:
                    type: string
                    format: binary
                  maxItems: 2
        required: true
components:
  schemas:
    Object:
      type: object
      example: {}
    Boolean:
      type: boolean
      example: true
    Number:
      type: number
      example: 1
    String:
      type: string
      example: string
    Function:
      type: string
      example: Function
    Undefined:
      type: string
      example: undefined
security: []
tags: []

Swagger-UI configuration options:

SwaggerUIBundle({
        spec: {"openapi":"3.0.0","info":{"title":"Hello world swagger","version":"1.0.0","description":"Hello world swagger description"},"paths":{"/":{"post":{"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/String"}}}}},"parameters":[],"requestBody":{"content":{"multipart/form-data":{"schema":{"type":"object","properties":{"file2":{"type":"array","items":{"type":"string","format":"binary"},"maxItems":2}}}}},"required":true}}}},"components":{"schemas":{"Object":{"type":"object","example":{}},"Boolean":{"type":"boolean","example":true},"Number":{"type":"number","example":1},"String":{"type":"string","example":"string"},"Function":{"type":"string","example":"Function"},"Undefined":{"type":"string","example":"undefined"}}},"security":[],"tags":[]},
        dom_id: '#swagger-ui',
        deepLinking: true,
        presets: [
            SwaggerUIBundle.presets.apis,
            SwaggerUIStandalonePreset
        ],
        plugins: [
            SwaggerUIBundle.plugins.DownloadUrl
        ],
        layout: "StandaloneLayout",
        displayRequestDuration: false,
        filter: false,
        tryItOutEnabled: false,      
    });
?yourQueryStringConfig - ??
Describe the bug you're encountering
To reproduce...

Steps to reproduce the behavior:

  1. Go to https://editor.swagger.io/
  2. Paste YML open api defination
  3. Click on the POST API and then click on "Try it out"
  4. Now try adding multiple files, you can actually add more than 2 files.
Expected behavior

The swagger UI should not allow adding more than 2 files with this YML specification

Screenshots

Screenshot 2022-09-29 at 10 59 03 AM

Additional context or thoughts

I have found this issue https://github.com/swagger-api/swagger-ui/issues/6327 and it is closed when this PR was merged - https://github.com/swagger-api/swagger-ui/pull/6878. But this doesn't seem to work, don't know why?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue at https://editor.swagger.io/ using the provided OpenAPI 3.0 definition, then open the POST operation, choose Try it out, and add files to file2. Compare the behavior with maxItems: 2 and inspect the existing handling related to issue #6327 and pull request #6878. Done means the UI prevents adding more than two files for this schema and the behavior is covered by an appropriate test.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.