Skip to content

"Execute" doesn't work for input model with optional nested object  #7205

@WinniX

Description

@WinniX

Q&A

  • OS: Windows
  • Browser: chrome
  • Version: 89.0.4389.128
  • Swagger-UI version: https://editor.swagger.io/
  • Swagger/OpenAPI version: Swagger 2.0

Content & configuration

Example Swagger/OpenAPI definition:

swagger: '2.0'
info:
  title: swashbuckletest
  version: v1
paths:
  /WeatherForecast:
    put:
      tags:
        - WeatherForecast
      consumes:
        - application/json
        - text/json
        - application/*+json
      parameters:
        - in: body
          name: body
          schema:
            $ref: '#/definitions/TopModel'
      responses:
        '200':
          description: Success
definitions:
  NestedModel:
    required:
      - id
    type: object
    properties:
      id:
        type: string
  TopModel:
    type: object
    properties:
      nested:
        $ref: '#/definitions/NestedModel'

Swagger-UI configuration options:

app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "swashbuckletest v1"));

Describe the bug you're encountering

PUT endpoint uses "TopModel" as input model and inside it there is an optional "nested" field of type "NestedModel".
"nested" object has a required "Id" field. Swagger UI doesn't allow to execute the request without "nested" field.

To reproduce...

Steps to reproduce the behavior:

  1. Go to https://editor.swagger.io/
  2. Click on 'File' -> 'Import file' and pick the YAML (see above)
  3. Expand PUT ​/WeatherForecast, click 'Try out'
  4. Replace 'body' with {} (empty object)
  5. Click 'Execute' button - no request were made

Expected behavior

In previous versions we could have omitted an optional object. So the body input {} should be considered as valid in this case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions