2016-08-22 5 views
10

最近、私が書いた安らかなAPIを闊歩APIをエクスポートして、威張っ-UIは(V2).Todayは、私はちょうどボタンpostman.And私はそれをクリックし、I上記インポートに気づいする方法ちょうどコメントを見た "輸入ポストマンコレクション、環境、データ・ダンプ、curlコマンド、またはRAML/WADL/SWAGGER(V1/V2)/ Runscopeファイルを。" 私はgooledていた最初は enter image description here<em>SpringMvc</em>で郵便配達員へ

が、答えは私の状況を満たしていません。

私の質問は、郵便配達員が必要とするファイルを作成する方法です。。私は甘やかすことに慣れていません。

答えて

11

私はPHPを使用しており、Swagger 2.0を使用してAPIを文書化しています。 Swaggerドキュメントはその場で作成されます(少なくともPHPで使用しています)。ドキュメントはJSON形式で生成されます。

サンプル文書

{ 
    "swagger": "2.0", 
    "info": { 
    "title": "Company Admin Panel", 
     "description": "Converting the Magento code into core PHP and RESTful APIs for increasing the performance of the website.", 
     "contact": { 
     "email": "[email protected]" 
     }, 
     "version": "1.0.0" 
    }, 
    "host": "localhost/cv_admin/api", 
    "schemes": [ 
    "http" 
], 
    "paths": { 
    "/getCustomerByEmail.php": { 
     "post": { 
      "summary": "List the details of customer by the email.", 
       "consumes": [ 
       "string", 
       "application/json", 
       "application/x-www-form-urlencoded" 
      ], 
       "produces": [ 
       "application/json" 
      ], 
       "parameters": [ 
        { 
         "name": "email", 
         "in": "body", 
         "description": "Customer email to ge the data", 
         "required": true, 
         "schema": { 
         "properties": { 
          "id": { 
           "properties": { 
            "abc": { 
             "properties": { 
              "inner_abc": { 
               "type": "number", 
                "default": 1, 
                "example": 123 
               } 
              }, 
              "type": "object" 
             }, 
             "xyz": { 
             "type": "string", 
              "default": "xyz default value", 
              "example": "xyz example value" 
             } 
            }, 
            "type": "object" 
           } 
          } 
         } 
        } 
       ], 
       "responses": { 
       "200": { 
        "description": "Details of the customer" 
        }, 
        "400": { 
        "description": "Email required" 
        }, 
        "404": { 
        "description": "Customer does not exist" 
        }, 
        "default": { 
        "description": "an \"unexpected\" error" 
        } 
       } 
      } 
     }, 
     "/getCustomerById.php": { 
     "get": { 
      "summary": "List the details of customer by the ID", 
       "parameters": [ 
        { 
         "name": "id", 
         "in": "query", 
         "description": "Customer ID to get the data", 
         "required": true, 
         "type": "integer" 
        } 
       ], 
       "responses": { 
       "200": { 
        "description": "Details of the customer" 
        }, 
        "400": { 
        "description": "ID required" 
        }, 
        "404": { 
        "description": "Customer does not exist" 
        }, 
        "default": { 
        "description": "an \"unexpected\" error" 
        } 
       } 
      } 
     }, 
     "/getShipmentById.php": { 
     "get": { 
      "summary": "List the details of shipment by the ID", 
       "parameters": [ 
        { 
         "name": "id", 
         "in": "query", 
         "description": "Shipment ID to get the data", 
         "required": true, 
         "type": "integer" 
        } 
       ], 
       "responses": { 
       "200": { 
        "description": "Details of the shipment" 
        }, 
        "404": { 
        "description": "Shipment does not exist" 
        }, 
        "400": { 
        "description": "ID required" 
        }, 
        "default": { 
        "description": "an \"unexpected\" error" 
        } 
       } 
      } 
     } 
    }, 
    "definitions": { 

    } 
} 

これは、次のようにポストマンにインポートすることができます。ポストマンUIの左上隅の「インポート」ボタンを

  1. クリックします。
  2. APIドキュメントをインポートするオプションが複数表示されます。 'ペースト生テキスト'をクリックします。
  3. JSON形式をテキスト領域に貼り付け、インポートをクリックします。
  4. すべてのAPIは「Postman Collection」と表示され、郵便配達員から使用できます。あなたはまた、 'リンクからのインポート' を使用することができます

Importing the JSON into Postman

Imported APIs

。スワッガーや他のAPIドキュメントツールからAPIのJSON形式を生成するURLを貼り付けます。

これは私のドキュメント(JSON)生成ファイルです。それはPHPにあります。私はSwaggerと一緒にJAVAを知りません。オレンジ色のボタン上

<?php 
require("vendor/autoload.php"); 
$swagger = \Swagger\scan('path_of_the_directory_to_scan'); 
header('Content-Type: application/json'); 
echo $swagger; 
+0

ありがとうございましたが、今問題はどのようにswagger-uiからファイルをエクスポートできますか?リンクが役に立たないことです。 –

+0

@DemonColdmist APIを生成するコードを追加しました。基本的には、ディレクトリ全体をスキャンし、アノテーションをチェックしてJSON/YAML出力を作成します。申し訳ありませんが、私はJavaでSwaggerを使用していません。 – JDpawar

+0

ありがとう、もしそれがPHPでエクスポートすることができれば、Javaもそうです。私はそれをJavaに変換します。 –

0
  • をクリックして、ファイルを選択した後闊歩ドキュメント(swagger.yaml)
  • から
  • 参照を( "ファイルを選択")、新しいコレクションはPOSTMANで作成されます。エンドポイントに基づくフォルダが含まれます。

また、いくつかのサンプルスワッガーファイルをオンラインで入手して、これを確認することもできます(スガーガードにエラーがある場合)。

+0

に移動することで、この回答の説明に従ってPostmanにインポートするJSONを取得できます私はswagger.yamlをどのようにエクスポートするのですか?私はSpringMvcでswagger-uiを使用しています。 –

+0

ここからswaggerをエクスポートしますか?あなたはすでにあなたのYAMLをオーサリングするためにスワッガーを使用していますか? –

関連する問題