如何将 Swagger 的默认"Response content type"更改为 "application/json" ?



SAP Commerce Cloud版本:1905.9

目前,Swagger的默认"响应内容类型"有两个值:"application/xml"one_answers"application/json"。默认选择为"application/xml"。有没有办法将默认选择更改为"application/json"?

香草代码示例如下:

@ApiOperation(hidden = true, value = "Updates the total amount of a specific product", notes = "Updates the total amount of a specific product in the cart based on the entryNumber.")
@RequestMappingOverride(priorityProperty = "b2bocc.CartResource.updateCartEntry.priority")
@RequestMapping(value = "/{cartId}/entries/{entryNumber}", method = RequestMethod.PUT)
@ResponseBody
@ApiBaseSiteIdUserIdAndCartIdParam
public CartModificationWsDTO updateCartEntry(@ApiParam(value = "Base site identifier.") @PathVariable final String baseSiteId,
@ApiParam(value = "The id of the entry in the cart.") @PathVariable final int entryNumber,
@ApiParam(value = "New quantity for this entry.") @RequestParam(required = true) final Long quantity,
@ApiParam(value = "Response configuration. This is the list of fields that should be returned in the response body.", allowableValues = "BASIC, DEFAULT, FULL") @RequestParam(required = false, defaultValue = FieldSetLevelHelper.DEFAULT_LEVEL) final String fields)
{
return updateCartEntry(baseSiteId, null, entryNumber, quantity, fields);
}

您可以在springmvcservlet.xml中切换转换器的顺序

<mvc:annotation-driven>
<mvc:message-converters>
<ref bean="jsonHttpMessageConverter"/>
<ref bean="xmlHttpMessageConverter"/>
<!--            <ref bean="customJsonHttpMessageConverter" /> -->
<!--            <ref bean="customXmlHttpMessageConverter" /> -->
</mvc:message-converters>
</mvc:annotation-driven>    

相关内容

最新更新