We have a Swagger file for our API, but in our API documentation, we want to show valid responses for each endpoint. I coded up this little recursive function in PHP which takes our Swagger file and spits out a valid response. I use it as follows, for each individual endpoint: // $swagger is the entire swagger file $swagger = file_get_contents('/path-to-swagger.json'); For the below code within our PHP template, `$endpoint` can be assumed to be a single endpoint with method (e.g. a single POST request to a URI) such that json_decode() was used to convert it from the Swagger file …

Member Avatar
+0 forum 0

The End.