SwaggerHub中是否有API可以更新文件定义? [英] Is there an API in SwaggerHub to update the file definition?

查看:181
本文介绍了SwaggerHub中是否有API可以更新文件定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有用于更新文件定义的API? 我正在寻找一种方法来使我在Git和SwaggerHub中的项目自动保持同步,因此我想在每次合并时更新文件定义. 是否有可能?您如何管理使项目和SwaggerHub定义自动保持同步?

Is there an API to update the file definition? I am looking for a way to keep my project in Git and SwaggerHub in sync automatically, so I would like to update the file definition at every merge. Is it possible? How do you manage keeping your project and SwaggerHub definition in sync automatically?

推荐答案

是的,SwaggerHub有一个API:

Yes, SwaggerHub has an API:

https://api.swaggerhub.com
与SwaggerHub API集成

和一些官方API客户端.

and a number of official API clients.

用于创建或更新API的cURL命令(请注意使用--data-binary代替-d/--data):

cURL command to create or update an API (note the use of --data-binary instead of -d/--data):

curl -X POST "https://api.swaggerhub.com/apis/OWNER/API_NAME" \
     -H "Authorization: YOUR_API_KEY" \
     -H "Content-Type: application/yaml" \
     --data-binary @myapi.yaml

原始HTTP请求供参考:

Raw HTTP request for the reference:

POST https://api.swaggerhub.com/apis/OWNER/API_NAME
Authorization: YOUR_API_KEY
Content-Type: application/yaml

# Request body is your complete YAML/JSON file
swagger: '2.0'
info:
  title: My API
  version: 1.0.0
paths:
  ...

注意:

  • 使用正确的Content-Type标头值:对于YAML,使用application/yaml;对于JSON,使用application/json.

  • Use the correct Content-Type header value: application/yaml for YAML or application/json for JSON.

如果要上传OpenAPI 3.0定义(openapi: 3.0.x),请将openapi=3.0.0查询参数添加到请求URL:

If uploading OpenAPI 3.0 definitions (openapi: 3.0.x), add the openapi=3.0.0 query parameter to the request URL:

POST https://api.swaggerhub.com/apis/OWNER/API_NAME?openapi=3.0.0

围绕SwaggerHub API的命令行包装,可作为npm模块使用./p>

A command-line wrapper around the SwaggerHub API, available as a npm module.

npm install -g swaggerhub-cli

指定您的API密钥(从 https://app.swaggerhub.com/settings/apiKey中获取) ):

Specify your API key (get it from https://app.swaggerhub.com/settings/apiKey):

swaggerhub configure

? SwaggerHub URL: https://api.swaggerhub.com
? API Key: <paste your key>

创建一个新的API:

swaggerhub api:create OWNER/API_NAME --file myapi.yaml

更新现有的API:

swaggerhub api:update OWNER/API_NAME/VERSION --file myapi.yaml --visibility private

Maven插件

https://github.com/swagger-api/swaggerhub-maven-插件/

https://github.com/swagger-api/swaggerhub-gradle-插件/

这篇关于SwaggerHub中是否有API可以更新文件定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆