2016-08-22 2 views
10

최근에 내가 쓴 한 편안한 API를 자신감 API를 수출하고 자신감-UI는 (V2) .Today, 나는 그냥 버튼을 postman.And 내가 그것을 클릭, 나는 위의 가져 오기을 발견하는 방법 단지 주석 보았다 "가져 오기 우체부 컬렉션, 환경, 데이터 덤프, 컬 명령, 또는 RAML/WADL/자신감 (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는 '우편 배달부'으로 표시되며 우편 배달부에서 사용할 수 있습니다.

    Importing the JSON into Postman

    Imported APIs

    또한 '링크에서 가져 오기'를 사용할 수 있습니다

. Swagger 또는 다른 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도 마찬가지입니다. 나는 이것을 자바로 번역 할 것이다. –

0
  • 을 클릭하여 파일을 선택한 후 자신감의 문서 (swagger.yaml)
  • -
  • 찾아보기를 ("파일 선택"), 새로운 컬렉션 POSTMAN에서 생성됩니다. 엔드 포인트를 기반으로하는 폴더가 포함됩니다.

또한 온라인에서 몇 가지 샘플 양각 파일을 온라인으로 가져 와서 확인할 수 있습니다 (흔들리지 않는 문서에 오류가있는 경우).

+0

으로 이동하여이 대답에서 설명한대로 Postman에서 가져올 JSON을 가져올 수 있습니다 swagger.yaml을 내보내는 방법을 알려주세요. SpringMvc에서 swagger-ui를 사용하고 있습니다. –

+0

어디에서 swagger를 내보내시겠습니까? 당신은 이미 당신의 YAML을 저작하기 위해 swagger를 사용하고 있습니까? –