Skip to content

Unable to generate correct definition for request parameter containing JSON #791

Closed
@runenielsen

Description

@runenielsen

Thanks for a great library! :-)

Describe the bug

I wish to send an object as a JSON string in a query parameter to a GET-request.

I would expect the OpenAPI Description for the query parameter to be defined using the content attribute as described on https://swagger.io/docs/specification/describing-parameters/ under the heading "schema vs content", but instead it uses the schema attribute. It seems a specified media type is ignored for query parameters.

To Reproduce

Using Spring Boot version 2.3.1.RELEASE and springdoc-openapi-ui version 1.4.3

Sample RestController code:

    package com.example.springboottest;

    import io.swagger.v3.oas.annotations.Parameter;
    import io.swagger.v3.oas.annotations.media.Content;
    import io.swagger.v3.oas.annotations.media.Schema;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.bind.annotation.RestController;

    @RestController
    @RequestMapping("/api")
    public class HelloController {

        @GetMapping("/some-method")
        public SomeResponse someMethod(@Parameter(content = @Content(mediaType = "application/json", schema = @Schema(implementation = SomeRequest.class))) @RequestParam String request) {
            return new SomeResponse();
        }

        public static class SomeRequest {
            public String requestString;
        }

        public static class SomeResponse {
            public String responseString;
        }
    }

Expected behavior

Expected OpenAPI Description:

    "parameters": [
      {
        "name": "request",
        "in": "query",
        "required": true,
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/SomeRequest"
            }
          }
        }
      }
    ],

Actual OpenAPI Description:

    "parameters": [
      {
        "name": "request",
        "in": "query",
        "required": true,
        "schema": {
          "$ref": "#/components/schemas/SomeRequest"
        }
      }
    ],

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions