Swagger With Static Documentation

后端 未结 2 782
野的像风
野的像风 2020-12-23 02:06

I am looking to use Swagger to document my restful interface. The problem is that I do not want to automatically generate my documentation by annotating my code. Basically I

2条回答
  •  心在旅途
    2020-12-23 03:10

    I have created json from PHP files using swagger PHP here is my code if anyone is looking for, hope it helps

    Model code:

    }

    here us JSON code for swagger UI:

     {
    "basePath": "http://192.168.3.42/swagger/api",
    "swaggerVersion": "1.2",
    "apiVersion": "1.0.0",
    "resourcePath": "/car",
    "apis": [
        {
            "path": "/car/add.php",
            "operations": [
                {
                    "method": "POST",
                    "summary": "Add Car",
                    "nickname": "addCar",
                    "type": "array",
                    "items": {
                        "$ref": "car"
                    },
                    "parameters": [
                        {
                            "paramType": "form",
                            "name": "parking_section_id",
                            "type": "integer",
                            "required": true,
                            "allowMultiple": false,
                            "description": "Parking Area ID",
                            "format": "int64"
                        },
                        {
                            "paramType": "form",
                            "name": "car_number",
                            "type": "integer",
                            "required": true,
                            "allowMultiple": false,
                            "description": "Car Number",
                            "format": "int64"
                        },
                        {
                            "paramType": "form",
                            "name": "cost",
                            "type": "integer",
                            "required": true,
                            "allowMultiple": false,
                            "description": "Cost of Parking",
                            "format": "int64"
                        }
                    ],
                    "responseMessages": [
                        {
                            "code": 400,
                            "message": "Invalid ID supplied"
                        },
                        {
                            "code": 404,
                            "message": "car not found"
                        }
                    ],
                    "notes": "Add car to parking",
                    "authorizations": {
    
                    }
                }
            ]
        },
        {
            "path": "/car/car.php?carId={carId}",
            "operations": [
                {
                    "method": "GET",
                    "summary": "Find car by ID",
                    "nickname": "getCarById",
                    "type": "Car",
                    "parameters": [
                        {
                            "paramType": "path",
                            "name": "carId",
                            "type": "integer",
                            "required": true,
                            "allowMultiple": false,
                            "description": "ID of car that needs to be fetched",
                            "format": "int64"
                        }
                    ],
                    "responseMessages": [
                        {
                            "code": 400,
                            "message": "Invalid ID supplied"
                        },
                        {
                            "code": 404,
                            "message": "car not found"
                        }
                    ],
                    "notes": "Returns a car based on ID",
                    "authorizations": {
    
                    }
                }
            ]
        },
        {
            "path": "/car/carJsonTest.php",
            "operations": [
                {
                    "method": "POST",
                    "summary": "Send and parse JSON",
                    "nickname": "carJsonTest",
                    "type": "void",
                    "parameters": [
                        {
                            "paramType": "body",
                            "name": "body",
                            "type": "Car",
                            "required": true,
                            "allowMultiple": false,
                            "description": "Sample JSON need to be passed"
                        }
                    ],
                    "responseMessages": [
                        {
                            "code": 405,
                            "message": "Invalid input"
                        }
                    ],
                    "notes": "Send and parse JSON",
                    "authorizations": {
    
                    }
                }
            ]
        },
        {
            "path": "/car/delete.php",
            "operations": [
                {
                    "method": "DELETE",
                    "summary": "Deletes a Car",
                    "nickname": "deleteCar",
                    "type": "void",
                    "parameters": [
                        {
                            "paramType": "form",
                            "name": "carId",
                            "type": "integer",
                            "required": true,
                            "allowMultiple": false,
                            "description": "ID of car that needs to be deleted",
                            "format": "int64"
                        }
                    ],
                    "responseMessages": [
                        {
                            "code": 400,
                            "message": "Invalid ID supplied"
                        },
                        {
                            "code": 404,
                            "message": "car not found"
                        }
                    ],
                    "notes": "Delete a parked car",
                    "consumes": [
                        "application/x-www-form-urlencoded"
                    ],
                    "authorizations": {
    
                    }
                }
            ]
        },
        {
            "path": "/car/deleteAll.php",
            "operations": [
                {
                    "method": "DELETE",
                    "summary": "Delete all car parking",
                    "nickname": "deleteAll",
                    "type": "void",
                    "notes": "Delete all car parking",
                    "consumes": [
                        "application/x-www-form-urlencoded"
                    ],
                    "authorizations": {
    
                    }
                }
            ]
        },
        {
            "path": "/car/fetchAll.php",
            "operations": [
                {
                    "method": "GET",
                    "summary": "Fetch all parked cars",
                    "nickname": "getAllParkedCars",
                    "type": "Car",
                    "responseMessages": [
                        {
                            "code": 404,
                            "message": "car not found"
                        }
                    ],
                    "notes": "Returns all cars parked",
                    "authorizations": {
    
                    }
                }
            ]
        },
        {
            "path": "/car/getCost.php",
            "operations": [
                {
                    "method": "POST",
                    "summary": "Parking Cost of the Car Parked",
                    "nickname": "getCost",
                    "type": "void",
                    "parameters": [
                        {
                            "paramType": "form",
                            "name": "carId",
                            "type": "integer",
                            "required": true,
                            "allowMultiple": false,
                            "description": "Parking Area ID",
                            "format": "int64"
                        }
                    ],
                    "responseMessages": [
                        {
                            "code": 405,
                            "message": "Invalid input"
                        }
                    ],
                    "notes": "Parking Cost of the Car Parked",
                    "authorizations": {
    
                    }
                }
            ]
        },
        {
            "path": "/car/testPatch.php",
            "operations": [
                {
                    "method": "PATCH",
                    "summary": "Testing Patch",
                    "nickname": "testWithFormPatch",
                    "type": "void",
                    "parameters": [
                        {
                            "paramType": "form",
                            "name": "firstPara",
                            "type": "integer",
                            "required": true,
                            "allowMultiple": false,
                            "description": "First Parameter",
                            "format": "int64"
                        },
                        {
                            "paramType": "form",
                            "name": "secondPara",
                            "type": "integer",
                            "required": true,
                            "allowMultiple": false,
                            "description": "Second Parameter",
                            "format": "int64"
                        }
                    ],
                    "responseMessages": [
                        {
                            "code": 405,
                            "message": "Invalid input"
                        }
                    ],
                    "notes": "Testing Patch",
                    "consumes": [
                        "application/x-www-form-urlencoded"
                    ],
                    "authorizations": {
    
                    }
                }
            ]
        },
        {
            "path": "/car/testPut.php",
            "operations": [
                {
                    "method": "PUT",
                    "summary": "Testing Put",
                    "nickname": "testWithFormPut",
                    "type": "void",
                    "parameters": [
                        {
                            "paramType": "form",
                            "name": "firstPara",
                            "type": "integer",
                            "required": true,
                            "allowMultiple": false,
                            "description": "First Parameter",
                            "format": "int64"
                        },
                        {
                            "paramType": "form",
                            "name": "secondPara",
                            "type": "integer",
                            "required": true,
                            "allowMultiple": false,
                            "description": "Second Parameter",
                            "format": "int64"
                        }
                    ],
                    "responseMessages": [
                        {
                            "code": 405,
                            "message": "Invalid input"
                        }
                    ],
                    "notes": "Testing Put",
                    "consumes": [
                        "application/x-www-form-urlencoded"
                    ],
                    "authorizations": {
    
                    }
                }
            ]
        }
    ],
    "models": {
        "Car": {
            "id": "Car",
            "required": [
                "car_number",
                "cost",
                "parking_section_id"
            ],
            "properties": {
                "parking_section_id": {
                    "description": "unique identifier for the parking",
                    "type": "integer",
                    "format": "int64",
                    "minimum": "0.0",
                    "maximum": "100.0"
                },
                "car_number": {
                    "description": "unique identifier for the car",
                    "type": "integer",
                    "format": "int64"
                },
                "cost": {
                    "description": "cost for the parking",
                    "type": "integer",
                    "format": "int64"
                }
            }
        }
    },
    "produces": [
        "application/json",
        "application/xml",
        "text/plain",
        "text/html"
    ]
    }
    

    Give the json path in api-doc.json

提交回复
热议问题