使用swagger的动态请求主体REST API方法

时间:2018-01-11 22:15:47

标签: java rest swagger-ui

我有用例我需要根据field的选择得到requestBody。下面是相同的代码,我能够得到动态responseBody基于选择ProtocolType.Is有任何方式swagger可以动态读取RequestBody。 / p>

Controller.Java

import country_data

for code in country_data.countrycodes:
    print(country_data.codemap[code], ':')
    print('\t', 'Head honcho:', country_data.countries[country_data.codemap[code]]['head honcho'])
    print('\t', 'Population:', country_data.countries[country_data.codemap[code]]['population'], 'million')

Service.Java

=IF(OR(REGEXMATCH('Sheet'!AJ2;"ok");REGEXMATCH('Sheet'!AE2;"ok"));"1";"2")

的POJO

@ApiOperation(value = "Protocol Account", tags = {"ProtocolAccount"}) 
@RequestMapping(value = "/protocolAccount/{protocolName}",
    method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) 
@ResponseBody public ProtocolAccount getProtocol(@PathVariable String protocolName)
{ 
    return service.getProtocol(protocolName);
}

枚举

public ProtocolAccount getProtocol(String protocolName){                    
    ProtocolAccount protocolAccount=new ProtocolAccount();
    Object object=ProtocolType.fromMap(protocolName);
    protocolAccount.setProtocol(object);
    return protocolAccount;
}

0 个答案:

没有答案