问题
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?
回答1:
Yes, SwaggerHub has an API:
https://api.swaggerhub.com
Integrating with the SwaggerHub API
You can update your API definitions in SwaggerHub like this:
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:
...
Use Content-Type: application/yaml if uploading YAML and Content-Type: application/json if uploading JSON.
Notes:
If you API definition is in the OpenAPI 3.0 format (
openapi: 3.0.x), add the?openapi=3.0.0parameter to the request URL:POST https://api.swaggerhub.com/apis/OWNER/API_NAME?openapi=3.0.0When uploading YAML files using cURL, use the
--data-binaryargument (not-d/--data) to specify the file path: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
There are also Maven and Gradle plugins for downloading/uploading API definitions from/to SwaggerHub.
来源:https://stackoverflow.com/questions/52650853/is-there-an-api-in-swaggerhub-to-update-the-file-definition