如何通过curl在WSO2 Publisher中创建API,使用url来swagger文档?
我的目标是在WSO2发布者中自动为新Web服务创建API,这些Web服务目前用swagger 2记录.为了尽可能高效地执行此操作,我想使用swagger.json的URL,因为在使用UI下完成:WSO2 Publisher,添加现有API;优选地,使用swagger填充名称和其他必填字段(如果它们存在于swagger json中).
解决方案的可能途径: 在“我尝试过的内容”部分下,我们看到步骤1中的响应消息是“已导入”,因此,如果我们可以弄清楚如何在步骤2中调用导入的模板来解决问题. 我尝试过的: “Found Resources”部分中的所有链接详细说明了如何使用显式swagger json来帮助创建api – 并且仍然需要名称,上下文等必需字段(即使在json中找到).我无法使用上面的命令来处理url,我尝试使用字段swagger_url =“urlToSwaggerJson”(参见下一节的结尾). 我猜这个答案在于实际使用UI命令,类似于下面的描述: 在“使用正常创建流程创建API”下.使用UI时,第一步是从swagger url创建模板描述,因此我尝试通过添加下面的步骤1来调整过程.问题:设计步骤未找到步骤1中启动的api. 0)登录: curl -k -X POST -c cookies URLtoWSO2/publisher/site/blocks/user/login/ajax/login.jag -d 'action=login&username=admin&password=admin' Response: {"error" : false} 1)开始流程: curl -k -X POST -b cookies URLtoWSO2/publisher/site/blocks/item-design/ajax/add.jag -F import-definition="swagger-url" -F swagger-url="URLtoSwagger" -F swagger-file="" -F action="start" Response: {"error" : false,"message" : "imported"} 2)设计API: curl -k -X POST -b cookies URLtoWSO2/publisher/site/blocks/item-design/ajax/add.jag -F action="design" -F name="NameOfAPI" -F context="/URItoAPI" Response: {"error" : true,"message" : " Error in adding API "} [如果添加-F version = 1.0.0,我不会收到错误,但这只会创建一个不使用swagger信息的空API.它也是swagger中存在的信息,并在使用UI时自动填写] 额外的信息: 似乎使用WSO2 api调用创建API只使用swagger来获取资源信息,并且仍然需要显式的swagger json. 命令: curl -k -X POST -b cookies URLtoWSO2/publisher/site/blocks/item-add/ajax/add.jag -d "action=addAPI&name=PhoneVerification&context=/phoneverify&version=1.0.0&tiersCollection=Gold,Bronze&resourceCount=0&resourceMethod-0=GET&resourceMethodAuthType-0=Application&resourceMethodThrottlingTier-0=Unlimited&uriTemplate-0=/*" -d'endpoint_config={"production_endpoints":{"url":"URL","config":null},"endpoint_type":"http"}'; 可以改为: curl -k -X POST -b cookies URLtoWSO2/publisher/site/blocks/item-add/ajax/add.jag -d "action=addAPI&name=PhoneVerification&context=/phoneverify&version=1.0.0&tiersCollection=Gold,Bronze&uriTemplate-0=/*" -d'swagger=SwaggerJson' -d'endpoint_config={"production_endpoints":{"url":"URL","endpoint_type":"http"}'; 这使得WSO2使用了swagger资源信息,但在它无法识别名称,版本或其他swagger信息的意义上失败了.此外,它失败,因为它需要显式的swagger json,而不是它的URL,即: curl -k -X POST -b cookies URLtoWSO2/publisher/site/blocks/item-add/ajax/add.jag -d "action=addAPI&name=PhoneVerification&context=/phoneverify&version=1.0.0&tiersCollection=Gold,Bronze&uriTemplate-0=/*" -d'swagger=URLtoSwagger' -d'endpoint_config={"production_endpoints":{"url":"URL","endpoint_type":"http"}'; 失败. 找到的资源: > https://docs.wso2.com/display/AM190/Publisher+APIs 解决方法
在WSO2 APIM 1.10.0中,有许多RESTful API来实现这一目标.我尝试通过传递Swagger JSON的REST API,并准确地获取API名称,上下文等:因此这样的调用将创建您的API.例如,下面
curl -H "Authorization: Bearer <token>" -H "Content-Type: application/json" -X POST -d @data.json http://127.0.0.1:9763/api/am/publisher/v0.9/apis data.json具有以下其他元素: "provider": "admin","version": "1.0.0","description": "Verify a phone number","name": "PhoneVerification3","context": "/phoneverify3" 请参阅此处获取API: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |