Skip to content

Add support for @ModelAttribute annotations #119

Description

@ckubik-monster

It would be nice to have support also for @ModelAttribute annotation used in a parameter of controller method.

Example:

@RestController
public class ExampleController {

  @GetMapping("/example")
  void get(@ModelAttribute InputDTO input) {
    //...
  }
}

class InputDTO {
  @Schema(required = true, description = "...")
  String first;

  @Schema(description = "...")
  String second;
}

Now is such parameter processed with no special care what leads to false API docs.

For Java example above it would lead to:

//parameters for path /example
"parameters": [
  {
    "name":"input",
    "in":"query",
    "required":true,
    "schema":{"$ref":"#/components/schemas/InputDTO"}
  }
]

//schema for InputDTO
{
  "required":["first"],
  "type": "object",
  "properties": {
    "first": {
      "type": "string",
      "description" :"..."
    },
    "second": {
      "type": "string",
      "description": "..."
    }
  }
}

As a result Spring will handle request parameters in different way than what API doc is declaring and also Swagger UI is unable to call a such endpoint of course.

Expected API docs for the example is following:

"parameters": [
	{
		"name": "first",
		"in": "query",
		"description": "...",
		"required": true,
		"schema": {
			"type": "string"
		}
	},
	{
		"name": "second",
		"in": "query",
		"description": "...",
		"required": true,
		"schema": {
			"type": "string"
		}
	}
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions