Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an API in SwaggerHub to update the file definition?

Tags:

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?

like image 639
Ludo Avatar asked Oct 04 '18 15:10

Ludo


People also ask

Does SwaggerHub have an API?

SwaggerHub generates interactive API documentation for your API definitions. Use it to explore the API endpoints, parameters, responses, and data models, and test the API calls directly in your browser.

How do I update Swagger definition?

Click the REST API definition that you want to work with. and then click Update. Click Choose File or Browse depending on which is displayed and, in your file system, select the OpenAPI (Swagger 2.0) definition you want to use. Click Update.

How do I add API to SwaggerHub?

In the sidebar on the left, click and select Create New API. Owner – Choose whether to create the API in your personal or organization account (if you are a member of an organization on SwaggerHub). The API owner is part of the API path in SwaggerHub: https://app.swaggerhub.com/apis/owner/api-name/1.0.

What is SwaggerHub API?

SwaggerHub is an integrated API development platform that brings together all the core capabilities of the open source Swagger framework, along with additional advanced capabilities to build, document, manage, and deploy your APIs.


1 Answers

Yes, SwaggerHub has an API:

https://api.swaggerhub.com
Integrating with the SwaggerHub API

and a number of official API clients.

API

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

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:
  ...

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

SwaggerHub CLI

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

npm install -g swaggerhub-cli

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>

Create a new API:

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

Update an existing API:

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

Maven plugin

https://github.com/swagger-api/swaggerhub-maven-plugin/

Gradle plugin

https://github.com/swagger-api/swaggerhub-gradle-plugin/

like image 86
Helen Avatar answered Jan 03 '23 02:01

Helen