swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.58k stars 8.96k forks source link

Inaccurate error message when an out-of-range integer value is entered for a parameter #8035

Open bluelight773 opened 2 years ago

bluelight773 commented 2 years ago

Q&A (please complete the following information)

Content & configuration

You can simply use Swagger Editor (https://editor.swagger.io/), use the following YAML, then just try entering 0 or 11 for int_parameter via the "Try it out" feature then check the inaccurate error message.

Example Swagger/OpenAPI definition:

openapi: 3.0.3
info:
  title: Test API
  version: 1.0.0
paths:
  /test_endpoint/:
    get:
      parameters:
      - in: query
        name: int_parameter
        schema:
          type: integer
          minimum: 1
          maximum: 10
      responses:
        '200':
            description: Success response

Swagger-UI configuration options: Not sure, but you can simply use https://editor.swagger.io/ to reproduce the error.

Describe the bug you're encountering

The error message shown for entering an integer that is above the maximum or below the minimum is in accurate. Instead of stating, "Value must be greater than or equal to 1", it states "Value must be greater than 1". Instead of stating "Value must be less than or equal to 10", it states "Value must be less than 10".

Note, however, that the actual validation, that is, checking that the value is within 1 to 10 inclusive is done correctly. The problem is just with the error message shown when you enter a value out of range.

To reproduce...

Steps to reproduce the behavior:

  1. Enter the provided YAML into https://editor.swagger.io/
  2. Click on /test_endpoint/ to expand it
  3. Click "Try it out"
  4. Enter the value 0 or 11 into int_parameter textbox
  5. Click "Execute"
  6. Hover over the red-filled int_parameter textbox to see the error message. You'll see "Value must be greater than 1" if 0 was entered, and "Value must be less than 10" if 11 was entered.

Expected behavior

The error message should state "Value must be greater than or equal to 1" if 0 was entered, and state "Value must be less than or equal to 10" if 11 was entered.

klajok commented 2 weeks ago

This problem still occurs on v5.17.14. Occurs for both Swagger 2.0 and OAS 3.1. For example:

{
    "paths": {
         "/v1/some/endpoint": {
            "get": {
                "parameters": [
                    {
                        "description": "Some int param with accepted values: 5 - 12",
                        "in": "query",
                        "name": "some_int_param",
                        "schema": {
                            "default": 7,
                            "maximum": 12,
                            "minimum": 5,
                            "type": "integer"
                        }

Validation error on Swagger UI: Screenshot from 2024-10-31 15-24-44

Are there any plans to address it in near future? Thank you in advance.