java系统找不到指定文件怎么解决
375
2022-10-05
【Azure API 管理】通过Java APIM SDK创建一个新的API,如何为Reqeust的Representation设置一个内容示例(Sample)?
问题描述
在使用API Management服务时,以Echo API(默认创建)举例,它会在Request的body部分默认设置一个SAMPLE指,这样在测试接口时候,就会有默认的Body内容,我们只需要根据JSON值就可以了。测试非常便捷。
那么,如果需要通过Java APIM的SDK来创建一个新接口,并且为它设置SAMPLE值,如何来实现呢?
问题解答
查看源代码文件,可以使用 withExamples 方法来实现 public RepresentationContract withExamples(Map
源文件路径:vehicle = new Vehicle().withVehicleType("vehicleType").withSpeedUnit("KM").withMaxSpeed(125).withAvgSpeed(90);ParameterExampleContract parameterExample = new ParameterExampleContract().withValue(vehicle);
第二部分:把第一部分生成的对象,加入到Map对象
Map
注意:一定要设置Map的Key,第一个参数一定要为 default。
第三部分:在APIM的manager创建函数中使用map对象
manager .apiOperations() .define("newoperations") .withExistingApi("rg1", "apimService2", "echo-api") .withDisplayName("test sample") .withMethod("POST") .withUrlTemplate("/user1") .withTemplateParameters(Arrays.asList()) .withDescription("This can only be done by the logged in user.") .withRequest( new RequestContract() .withDescription("Created user object") .withQueryParameters(Arrays.asList()) .withHeaders(Arrays.asList()) .withRepresentations( Arrays .asList( new RepresentationContract() .withContentType("application/json") .withExamples(map) .withTypeName("User")))) .withResponses( Arrays.asList( new ResponseContract() .withStatusCode(200) .withDescription("successful operation") .withRepresentations( Arrays.asList( new RepresentationContract() .withContentType("application/xml"), new RepresentationContract() .withContentType("application/json"))) .withHeaders(Arrays.asList()))) .create();
附录一:第一部分中Vehicle 类的定义截图
附录二:创建成功后的截图
参考资料
Azure Resource Manager ApiManagement client library for Java: examples) Method : 云中,恰是如此!
分类: 【Azure API 管理】
标签: APIM, APIM JAVA Create API, Map map, RepresentationContract withExamples
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~