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의 왼쪽 상단 모서리에있는 '가져 오기'버튼을
는
- 을 클릭합니다.
- API 문서를 가져 오는 데 여러 옵션이 표시됩니다. '풀 텍스트 붙여 넣기'을 클릭하십시오.
- JSON 형식을 텍스트 영역에 붙여넣고 가져 오기를 클릭하십시오.
- 모든 API는 '우편 배달부'으로 표시되며 우편 배달부에서 사용할 수 있습니다.
또한 '링크에서 가져 오기'를 사용할 수 있습니다
. 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;
감사합니다.하지만 이제는 문제가 어떻게 swagger-ui에서 파일을 내보낼 수 있습니까? 그리고 링크가 쓸모가 없습니다. –
@DemonColdmist API를 생성하는 코드를 추가했습니다. 기본적으로 디렉토리 전체를 검사하고 주석을 확인하고 JSON/YAML 출력을 만듭니다.죄송 합니다만, Java에서 Swagger를 사용하지 않았습니다. – JDpawar
감사합니다. PHP로 내보내기가 가능하다면 Java도 마찬가지입니다. 나는 이것을 자바로 번역 할 것이다. –