fixed compiler pass, updated README

This commit is contained in:
Evan Villemez 2012-07-24 14:39:43 -04:00
parent b9e8d61082
commit 89f2044581
6 changed files with 30 additions and 11 deletions

View File

@ -18,10 +18,12 @@ class RegisterExtractorParsersPass implements CompilerPassInterface
//find registered parsers and sort by priority
$sortedParsers = array();
foreach ($container->findTaggedServiceIds('nelmio_api_doc.extractor.parser') as $id => $attributes) {
foreach ($container->findTaggedServiceIds('nelmio_api_doc.extractor.parser') as $id => $tagAttributes) {
foreach ($tagAttributes as $attributes) {
$priority = isset($attributes['priority']) ? $attributes['priority'] : 0;
$sortedParsers[$priority][] = $id;
}
}
//add parsers if any
if (!empty($sortedParsers)) {

View File

@ -83,7 +83,7 @@ class FormTypeParser implements ParserInterface
'dataType' => $bestType,
'required' => $config->getRequired(),
'description' => $config->getAttribute('description'),
'readonly' => false,
'readonly' => $config->getDisabled(),
);
}

View File

@ -82,7 +82,7 @@ class YourController extends Controller
/**
* @ApiDoc(
* description="Create a new Object",
* formType="Your\Namespace\Form\Type\YourType"
* input="Your\Namespace\Form\Type\YourType"
* )
*/
public function postAction()
@ -99,16 +99,16 @@ The following properties are available:
* `filters`: an array of filters;
* `formType`: the Form Type associated to the method, useful for POST|PUT methods, either as FQCN or
* `input`: the input type associated to the method, currently this only supports Form Types, useful for POST|PUT methods, either as FQCN or
as form type (if it is registered in the form factory in the container)
Each _filter_ has to define a `name` parameter, but other parameters are free. Filters are often optional
parameters, and you can document them as you want, but keep in mind to be consistent for the whole documentation.
If you set a `formType`, then the bundle automatically extracts parameters based on the given type,
If you set `input`, then the bundle automatically extracts parameters based on the given type,
and determines for each parameter its data type, and if it's required or not.
You can add an extra option named `description` on each field:
For Form Types, you can add an extra option named `description` on each field:
``` php
<?php
@ -181,6 +181,16 @@ configure this sandbox using the following parameters:
endpoint: http://sandbox.example.com/ # default: /app_dev.php, use this parameter to define which URL to call through the sandbox
The bundle provides a way to register multiple `input` parsers. The first parser that can handle the specified
input is used, so you can configure their priorities via container tags. Here's an example parser service registration:
#app/config/config.yml
services:
mybundle.api_doc.extractor.custom_parser:
class: MyBundle\Parser\CustomDocParser;
tags:
- {name: nelmio_api_doc.extractor.parser, priority: 2}
## Credits ##
The design is heavily inspired by the [swagger-ui](https://github.com/wordnik/swagger-ui) project.

View File

@ -14,7 +14,7 @@
<services>
<service id="nelmio_api_doc.parser.form_type_parser" class="%nelmio_api_doc.parser.form_type_parser.class%">
<argument type="service" id="form.factory" />
<tag name="nelmio_api_doc.extractor.parser" priority="0" />
<tag name="nelmio_api_doc.extractor.parser" />
</service>
<service id="nelmio_api_doc.formatter.abstract_formatter" class="%nelmio_api_doc.formatter.abstract_formatter.class%" />
<service id="nelmio_api_doc.formatter.markdown_formatter" class="%nelmio_api_doc.formatter.markdown_formatter.class%"

View File

@ -35,7 +35,7 @@ class TestController
/**
* @ApiDoc(
* description="create test",
* inputClass="Nelmio\ApiDocBundle\Tests\Fixtures\Form\TestType"
* input="Nelmio\ApiDocBundle\Tests\Fixtures\Form\TestType"
* )
*/
public function postTestAction()
@ -76,7 +76,7 @@ class TestController
/**
* @ApiDoc(
* description="create another test",
* inputClass="dependency_type"
* input="dependency_type"
* )
*/
public function anotherPostAction()

View File

@ -81,18 +81,21 @@ class SimpleFormatterTest extends WebTestCase
'dataType' => 'string',
'required' => true,
'description' => 'A nice description',
'readonly' => false
),
'b' =>
array(
'dataType' => 'string',
'required' => false,
'description' => '',
'readonly' => false
),
'c' =>
array(
'dataType' => 'boolean',
'required' => true,
'description' => '',
'readonly' => false
),
),
'description' => 'create test',
@ -108,18 +111,21 @@ class SimpleFormatterTest extends WebTestCase
'dataType' => 'string',
'required' => true,
'description' => 'A nice description',
'readonly' => false
),
'b' =>
array(
'dataType' => 'string',
'required' => false,
'description' => '',
'readonly' => false
),
'c' =>
array(
'dataType' => 'boolean',
'required' => true,
'description' => '',
'readonly' => false
),
),
'description' => 'create test',
@ -138,6 +144,7 @@ class SimpleFormatterTest extends WebTestCase
'dataType' => 'string',
'required' => true,
'description' => 'A nice description',
'readonly' => false
),
),
'description' => 'create another test',