wkennedy / swagger4spring-web

Swagger support for Spring MVC
89 stars 46 forks source link

Adding @ApiOperation is messing up the resource path #67

Open MartinAhrer opened 10 years ago

MartinAhrer commented 10 years ago

Adding the @ApiOperation to an @Api annotated controller is messing with the path of the resource. Basically the @Api.value attribute is mapped into the resource path. While the JavaDoc of @Api is just saying that the value (default) attribute is a "Short descriptions" it really turns out that it is used as request path here. @Api always requires the value attribute when specifying the description attribute. Also, this effect only shows up after adding a @ApiOperation annotation.

Looks like a clash of swagger core and swagger4spring. Maybe swagger4spring can come up with dedicated @ApiDescription annotations that allow just adding the description without the request mapping?

// swagger4spring takes the description, but value is mandatory
@Api(value = "User Account resource API", description = "User Account resource API")
@Controller
@ExposesResourceFor(UserAccountResource.class)
@RequestMapping(value = UserAccountController.REQUEST_MAPPING_PATH, produces = {"application/json"})
public class UserAccountController {
    public static final String REQUEST_MAPPING_PATH = "/userAccounts";

    @Autowired
    private UserAccountFacade userAccountFacade;

    @ApiOperation(value="Find all user accounts", notes="Find all user accounts")
    @RequestMapping(method = RequestMethod.GET)
    @ResponseBody
    public PagedResources<UserAccountResource> findAll(@NonNull Pageable pageable, @NonNull PagedResourcesAssembler pagedAssembler) {
        return userAccountFacade.findAll(pageable, pagedAssembler);
    }

This turns the output of ...userAccount/resourceList/doc/userAccountsinto

{"apiVersion": "TODO", "swaggerVersion": "1.2", "basePath": "http://localhost:8080", "resourcePath": "/userAccounts", "produces": ["application/json"], "consumes": [], "protocols": [], "authorizations": [], "apis": [
    {
        "path": "/User Account resource API",
        "description": null,
        "operations": [
            {
                "method": "GET",
                "summary": "Find all user accounts",
                "notes": "Find all user accounts",
                "responseClass": "void",
                "nickname": "findAll",
                "position": 0,
                "produces": [],
                "consumes": [],
                "protocols": [],
                "authorizations": [
                    {
                        "type": "",
                        "scopes": [
                            {
                                "scope": "",
                                "description": ""
                            }
                        ]
                    }
                ],
                "parameters": [],
                "responseMessages": [],
                "deprecated": null
            }
        ]
    }
], "models": null, "description": "User Account resource API", "position": 0}

Using 0.3.4-SNAPSHOT (today)