2016-08-23 363 views
2

我试图使用swagger - confluence独立tool将我的Swagger JSON模式(myapi.json)上传到Atlassian Confluence。如何以编程方式将Swagger API文档发布到Atlassian Confluence? (使用Swagger Confluence工具和Confluence REST API)

的独立CLI的.jar should(根据我的理解),这样操作(使用this页凭据Base64编码):

java -jar <system path root>/swagger-confluence-cli-all-2.2-RELEASE.jar -u "http(s)://<server>:<port>/confluence/rest/api/" -b "<base64 encoded userid:password string" -a "<parent page id>" -k "<space key>" -g "true" -i "true" -s "<myschema.json>" -t "<Title for generated page>" -m "single" 

输出(404未找到):

2016-08-23 15:08:12.177 INFO - [main] n.s.s.c.s.i.SwaggerToAsciiDocServiceImpl : AsciiDoc Conversion Complete! 
2016-08-23 15:08:12.178 INFO - [main] n.s.s.c.s.i.AsciiDocToXHtmlServiceImpl : Converting AsciiDoc to XHTML5... 
io/console not supported; tty will not be manipulated 
2016-08-23 15:08:16.888 INFO - [main] n.s.s.c.s.i.AsciiDocToXHtmlServiceImpl : XHTML5 Conversion Complete! 
2016-08-23 15:08:17.728 INFO - [main] n.s.s.c.s.i.XHtmlToConfluenceServiceImpl : Posting XHTML to Confluence... 
Exception in thread "main" org.springframework.web.client.HttpClientErrorException: 404 Not Found 

在搜索Confluence REST API示例时,引起了一些混淆,例如在Stackoverflow中,API似乎在改变一些。然而,Confluence REST API page表明,从Confluence Server 5.5开始,当前的API应该是相同的。这也被描述为swagger-confluence概述page中的一个要求。

相同的要求提到“有权访问REST API的Confluence用户”。这是如何确定的?我正在使用管理员用户。我在article中找到了常规配置 - >进一步配置下的常规“启用远程API”配置(似乎默认启用)。同一篇文章说这个设置启用的XML-RPC和SOAP API在Confluence 5.5+上被弃用。 REST API是否默认启用,并且是否有控制使用情况的方法?

当尝试调用REST API时也会出现一些奇怪的结果(尽管我做了获得了响应,因此导致我认为该URL是正确的)。

curl -v -u userid:pass http://<server>:<port>/confluence/rest/api/ 
... 
HTTP/1.1 302 Found 
... 

但在调用URL http://<server>:<port>/confluence/rest/api/与高枕无忧(Firefox插件)用GET和提供用户ID &通作为基本身份验证返回200种OK HTTP状态,似乎给我回合流仪表板(空格的父母;顶级页)。使用浏览器访问URL时也会出现这种情况。

还有许多其他尝试用调用Confluence REST API导致404.开始认为这是一个授权问题..我做错了什么?还是有另一种方式来产生类似于Swagger Confluence demo的结果?

回答

5

那么,即使http://<server>:<port>/confluence/rest/api/返回HTTP 200确定,URL是错误的。 以上是所谓的“带上下文的URL”(/ confluence/part),我需要的是没有上下文的URL(URL中没有/ confluence /)。

下面是如何测试的URL通过接收200工作时,头(-v)和页面内容作为JSON响应: curl -v -u user:pass http://<server>:<port>/rest/api/content/{id}
页面ID可以通过按下被检查(或鼠标do sth对)“编辑” Confluence页面上的按钮。

而以下是我终于得到了自动上传合流工作:
java -jar <system path root>/swagger-confluence-cli-all-2.2-RELEASE.jar -u "http(s)://<server>:<port>/rest/api/" -b "<base64 encoded userid:password string>" -a "<parent page id>" -k "<space key>" -g "true" -i "true" -s "<myschema.json>" -t "<Title for generated page>" -m "single"

招摇合流tool是真棒,顺便说一下,结果是作为demo好!

[编辑补充]:
确认扬鞭合流库/工具(V2.2)到我的两个目标合流服务器,版本一起使用5.8.14和5.9.2