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

Pet*_*son 5 curl wso2 wso2-api-manager swagger-2.0

我的目标是在 WSO2 发布者中自动为新的 Web 服务创建 API,这些 Web 服务目前使用 swagger 2 进行了记录。为了尽可能高效地做到这一点,我想使用一个指向 的 URL swagger.json,就像使用UI 下:WSO2 发布者,添加现有 API;最好以这样的方式使用 swagger 填充名称和其他必填字段(如果它们存在于 swagger json 中)。


解决方案的可能途径:

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


我尝试过的:

“找到的资源”部分中的所有链接详细说明了如何使用显式 swagger json 来帮助创建 api - 并且仍然需要名称、上下文等必填字段(即使在 json 中找到)。我无法获得像上面那样的命令来处理 url,我已经尝试过使用该字段swagger_url="urlToSwaggerJson"(请参阅下一节末尾)。

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

在“使用正常创建流程创建 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}
Run Code Online (Sandbox Code Playgroud)

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"}
Run Code Online (Sandbox Code Playgroud)

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 "}
Run Code Online (Sandbox Code Playgroud)

[如果添加-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"}';
Run Code Online (Sandbox Code Playgroud)

可以改为:

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"}';
Run Code Online (Sandbox Code Playgroud)

这使得 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"}';
Run Code Online (Sandbox Code Playgroud)

失败。


找到的资源:

小智 0

在 WSO2 APIM 1.10.0 ++ 中,有一堆 RESTful API 可以实现此目的。我尝试通过 REST API 传入 Swagger JSON,它会准确地获取 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
Run Code Online (Sandbox Code Playgroud)

data.json除其他要素外,还具有以下要素:

    "provider": "admin",
    "version": "1.0.0",
    "description": "Verify a phone number",
    "name": "PhoneVerification3",
    "context": "/phoneverify3"
Run Code Online (Sandbox Code Playgroud)

请参阅此处的 API:
https://docs.wso2.com/display/AM1100/apidocs/publisher/# !/operations#APIsApi#apisGet