From 3869b6f1cf2822b2912a247bbcdde9e820c98a0b Mon Sep 17 00:00:00 2001 From: John Kleijn Date: Sat, 12 Mar 2016 09:51:45 +0100 Subject: [PATCH] Update README, add JSON Swagger def tests --- README.md | 4 +- src/Tests/Functional/JsonDataApiTest.php | 35 ++++ .../Functional/PetStore/app/swagger/data.json | 166 ++++++++++++++++++ 3 files changed, 203 insertions(+), 2 deletions(-) create mode 100644 src/Tests/Functional/JsonDataApiTest.php create mode 100644 src/Tests/Functional/PetStore/app/swagger/data.json diff --git a/README.md b/README.md index 4cf9364..577c506 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Invert your workflow (contract first) using Swagger ([Open API](https://openapis Aimed to be lightweight, this bundle does not depend on FOSRestBundle or Twig. ## Important Notes - * SwaggerBundle only supports json in- and output, and only YAML Swagger definitions + * SwaggerBundle only supports json in- and output * This bundle is currently actively maintained. * Go to the [release page](https://github.com/kleijnweb/swagger-bundle/releases) to find details about the latest release. @@ -18,6 +18,7 @@ A minimal example is also [available](https://github.com/kleijnweb/symfony-swagg ## This bundle will.. + * Handle both JSON and YAML swagger specs transparently. * Configure routing based on your Swagger documents(s), accounting for things like type, enums and pattern matches. * Validate body and parameters based on your Swagger documents(s). * Coerce query and path parameters to their defined types when possible. @@ -31,7 +32,6 @@ A minimal example is also [available](https://github.com/kleijnweb/symfony-swagg * Handle Form posts. * Generate your API documentation. Use your Swagger documents, plenty of options. * Mix well with GUI bundles. The bundle is biased towards lightweight API-only apps. - * Work with JSON Swagger documents. * Do content negotiation or support XML. # Usage diff --git a/src/Tests/Functional/JsonDataApiTest.php b/src/Tests/Functional/JsonDataApiTest.php new file mode 100644 index 0000000..7641234 --- /dev/null +++ b/src/Tests/Functional/JsonDataApiTest.php @@ -0,0 +1,35 @@ + + */ +class JsonDataApiTest extends WebTestCase +{ + use ApiTestCase; + + /** + * Use config_basic.yml + * + * @var bool + */ + protected $env = 'basic'; + + /** + * @test + */ + public function canInitSchemaManager() + { + static::initSchemaManager(__DIR__ . '/PetStore/app/swagger/data.json'); + } +} diff --git a/src/Tests/Functional/PetStore/app/swagger/data.json b/src/Tests/Functional/PetStore/app/swagger/data.json new file mode 100644 index 0000000..5fa10b9 --- /dev/null +++ b/src/Tests/Functional/PetStore/app/swagger/data.json @@ -0,0 +1,166 @@ +{ + "swagger": "2.0", + "info": { + "description": "Data api", + "version": "1.0.0" + }, + "basePath": "/data/v1", + "paths": { + "/entity/{type}": { + "get": { + "operationId": "find", + "parameters": [ + { + "in": "query", + "name": "lastModified", + "required": true, + "type": "string", + "format": "date-time" + } + ], + "responses": { + "200": { + "description": "Found resources", + "schema": { + "type": "array", + "items": { + "type": "object" + } + } + } + } + }, + "post": { + "parameters": [ + { + "in": "body", + "name": "data", + "required": true, + "schema": { + "type": "object" + } + } + ], + "responses": { + "200": { + "description": "The created resource", + "schema": { + "type": "object" + } + } + } + } + }, + "/entity/{type}/findByCriteria": { + "post": { + "operationId": "findByCriteria", + "parameters": [ + { + "in": "body", + "name": "criteria", + "required": true, + "schema": { + "$ref": "#/definitions/Criteria" + } + } + ], + "responses": { + "200": { + "description": "Found resources", + "schema": { + "type": "array", + "items": { + "type": "object" + } + } + } + } + } + }, + "/entity/{type}/{id}": { + "put": { + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "type": "integer" + }, + { + "in": "body", + "name": "data", + "required": true, + "schema": { + "type": "object" + } + } + ], + "responses": { + "200": { + "description": "The modified resource", + "schema": { + "type": "object" + } + } + } + }, + "delete": { + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "type": "integer" + } + ], + "responses": { + "204": { + "description": "Empty response", + "schema": { + "type": null + } + } + } + }, + "get": { + "parameters": [ + { + "in": "path", + "name": "id", + "required": true, + "type": "integer" + } + ], + "responses": { + "200": { + "description": "The requested resource", + "schema": { + "type": "object" + } + } + } + } + } + }, + "definitions": { + "Criteria": { + "type": "array", + "items": { + "$ref": "#/definitions/FieldCriteria" + } + }, + "FieldCriteria": { + "properties": { + "fieldName": { + "type": "string" + }, + "operator": { + "type": "string" + }, + "value": { + "type": "string" + } + } + } + } +} \ No newline at end of file