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

后端 未结 1 1854
抹茶落季
抹茶落季 2020-12-21 04:06

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 defi

相关标签:
1条回答
  • 2020-12-21 04:19

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

    Notes:

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

    • 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 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/

    0 讨论(0)
提交回复
热议问题