Skip to content

Content-type: application/json is not autogenerated for @RestController return type? #659

@antonalechnovic

Description

@antonalechnovic

Example:

@Tag(name = "deployments")
@RestController
public class DeploymentController {
    @PostMapping("/bla")
    @ResponseStatus(HttpStatus.ACCEPTED)
    @Operation(operationId = "deployment")
    public DeploymentPostResponse createDeployment(@Valid @RequestBody DeploymentPostRequest deploymentPostRequest) {
return new DeploymentPostRequest();
}
}

Generates (note missing content-type: application/json, request however has it)

{
  "responses": {
    "202": {
      "description": "Accepted",
      "content": {
        "*/*": {
          "schema": {
            "$ref": "#/components/schemas/DeploymentPostResponse"
          }
        }
      }
    }
  }
}

Then after adding @Opeation with application/json on createDeployment

@Operation(operationId = "deployment", responses=@ApiResponse(content = @Content(mediaType = "application/json")))

I get:

{
  "responses": {
    "default": {
      "description": "default response",
      "content": {
        "application/json": {}
      }
    }
  }
}

Few things which seems unclear:

  1. Why content-type generated for say for request ? but not for response?
  2. Would it make sense to combine autogen with annotations, annotations overriding? Or that would be too verbose?

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