Skip to content

Content definition in @ApiResponse remove schema generated based on the returned value #2663

Closed
@MarianaSequeira

Description

@MarianaSequeira

When defining content in the @ApiResponse the default schema is no longer defined in the OpenApi spec.

If we annotate our endpoint using the following:

@ApiResponse(responseCode = "200", description = "OK")
Map<Class1, Map<Class2, Set<String>>> get();

We have the following schema being generated:

"responses": {
  "200": {
    "description": "OK",
    "content": {
      "*/*": {
        "schema": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "additionalProperties": {
              "uniqueItems": true,
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}

However, we automatically lose this valuable information when defining content (even if we use useReturnTypeSchema).
For example, for the following code:

@ApiResponse(
        useReturnTypeSchema = true,
        responseCode = "200",
        description = "OK",
        content = {
                @Content(
                        mediaType = "*/*",
                        examples =
                            @ExampleObject(
                                    name = "success",
                                    value ="..."))
        }
)
Map<Class1, Map<Class2, Set<String>>> get();

We get the following:

"responses": {
  "200": {
    "description": "OK",
    "content": {
      "*/*": {
        "examples": {
          "success": {
            "description": "success",
            "value": "..."
          }
        }
      }
    }
  }
}

This hinders the process of generating concise and enriched documentation. Besides, I could not find in the documentation any reference saying that if content is defined the default schema is not used. This is particularly relevant as it is not possible to achieve this schema description using annotations in the code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions