首页 文章

如何通过curl在WSO2 Publisher中创建API,使用url来swagger文档?

提问于
浏览
4

我的目标是在WSO2发布者中自动为新的Web服务创建API,这些Web服务目前用swagger 2进行记录 . 为了尽可能高效地执行此操作,我想使用 swagger.json 的URL,就像在使用以下UI:WSO2 Publisher,添加现有API;优选地,使用swagger填充名称和其他必填字段(如果它们存在于swagger json中) .


解决方案的可能途径:

在“我尝试过的内容”部分下,我们看到步骤1中的响应消息是“已导入”,因此,如果我们可以弄清楚如何在步骤2中调用导入的模板来解决问题 .


我尝试过的:

'Found Resources'部分中的所有链接详细说明了如何使用显式swagger json来帮助创建api - 并且仍然需要名称,上下文等必需字段(即使在json中找到) . 我无法使用上面的命令来处理网址,我已尝试使用字段 swagger_url="urlToSwaggerJson" (请参阅下一节的结尾) .

我猜这个答案在于实际使用UI命令,类似于以下描述:http://yasassriratnayake.blogspot.nl/2015/06/creating-api-with-curl-commands-with.html

根据'Creating the API with Normal Creating Flow' . 使用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","config":null},"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","config":null},"endpoint_type":"http"}';

失败 .


找到的资源:

1 回答

  • 0

    在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:
    https://docs.wso2.com/display/AM1100/apidocs/publisher/#!/operations#APIsApi#apisGet

相关问题