Skip to content

It's impossible to send request with selected value by default #6621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AlexeyKorkoza opened this issue Nov 16, 2020 · 3 comments · Fixed by #6874
Closed

It's impossible to send request with selected value by default #6621

AlexeyKorkoza opened this issue Nov 16, 2020 · 3 comments · Fixed by #6874

Comments

@AlexeyKorkoza
Copy link

AlexeyKorkoza commented Nov 16, 2020

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

I was redirected to here by the author of the swagger-ui-express (scottie1984/swagger-ui-express#219 (comment))
So, below is my description.

Current behavior

I have an endpoint that allows me to upload stats for different types of sports matches and select the type. Right now, I can upload the statistics file only for hockey matches that's why only one item is added to the select. So, I attach the statistics file and press on the execute button as the select has only one item. However, the request isn't sent to my backend via the swagger. I can see that the border of the select is red colour and something went wrong but what?
I attached the screenshot below the view of my endpoint.

Screenshot_48

I would say before creating this issue I was looking through various issues on both stackoverflow and here. Unfortunately, I couldn't find a solution. I read through the documentation but the result is the same.

Expected behavior

I expect I will be able to send a request to my backend to upload stats without any issues in spite of that the select has only one item now.

Minimal reproduction of the problem with instructions

I decided to create the repository where I reproduced my issue.
Link: https://github.com/AlexeyKorkoza/nestjs-swagger-reproduce-issue

Environment


Nest version: 7.5.1

 
For Tooling issues:
- Node version: 12.16.3
- Platform:  Windows

Others:
Operating system version: Windows 10 Pro
OS build: 19041.450
IDE: Webstorm 2020.1.4
Package manager: yarn, 1.22.4
@hkosova
Copy link
Contributor

hkosova commented Nov 16, 2020

Please post your API definition file (YAML or JSON). You can export it from Swagger UI as explained here: https://stackoverflow.com/q/48525546.

@AlexeyKorkoza
Copy link
Author

@hkosova
The definition file:

{
  "openapi": "3.0.0",
  "info": {
    "title": "",
    "description": "",
    "version": "1.0",
    "contact": {}
  },
  "tags": [],
  "servers": [],
  "components": {
    "schemas": {
      "SportDto": {
        "type": "object",
        "properties": {
          "typeSport": {
            "type": "string",
            "enum": [
              "HOCKEY"
            ]
          },
          "stats": {
            "type": "string",
            "format": "binary"
          }
        },
        "required": [
          "typeSport",
          "stats"
        ]
      },
      "ResponseDto": {
        "type": "object",
        "properties": {}
      }
    }
  },
  "paths": {
    "/sports": {
      "post": {
        "operationId": "AppController_postHello",
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/SportDto"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResponseDto"
                }
              }
            }
          }
        }
      }
    }
  }
}

If somebody has a NestJS application and wants to export the definition he should add the api-json to the end of the url.
The issue link where is mentioned about it:
nestjs/swagger#158 (comment)

@hkosova
Copy link
Contributor

hkosova commented Nov 17, 2020

Confirmed a bug: if an OAS3 form field is required and has a single-value enum, "try it out" doesn't work.

The workaround is to add an example value for the typeSport property:

          "typeSport": {
            "type": "string",
            "enum": [
              "HOCKEY"
            ],
            "example": "HOCKEY"    <-----------
          },

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

Successfully merging a pull request may close this issue.

2 participants