mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-09 02:59:27 +03:00
fixed compiler pass, updated README
This commit is contained in:
parent
b9e8d61082
commit
89f2044581
@ -18,9 +18,11 @@ class RegisterExtractorParsersPass implements CompilerPassInterface
|
|||||||
|
|
||||||
//find registered parsers and sort by priority
|
//find registered parsers and sort by priority
|
||||||
$sortedParsers = array();
|
$sortedParsers = array();
|
||||||
foreach ($container->findTaggedServiceIds('nelmio_api_doc.extractor.parser') as $id => $attributes) {
|
foreach ($container->findTaggedServiceIds('nelmio_api_doc.extractor.parser') as $id => $tagAttributes) {
|
||||||
$priority = isset($attributes['priority']) ? $attributes['priority'] : 0;
|
foreach ($tagAttributes as $attributes) {
|
||||||
$sortedParsers[$priority][] = $id;
|
$priority = isset($attributes['priority']) ? $attributes['priority'] : 0;
|
||||||
|
$sortedParsers[$priority][] = $id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//add parsers if any
|
//add parsers if any
|
||||||
|
@ -83,7 +83,7 @@ class FormTypeParser implements ParserInterface
|
|||||||
'dataType' => $bestType,
|
'dataType' => $bestType,
|
||||||
'required' => $config->getRequired(),
|
'required' => $config->getRequired(),
|
||||||
'description' => $config->getAttribute('description'),
|
'description' => $config->getAttribute('description'),
|
||||||
'readonly' => false,
|
'readonly' => $config->getDisabled(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
README.md
18
README.md
@ -82,7 +82,7 @@ class YourController extends Controller
|
|||||||
/**
|
/**
|
||||||
* @ApiDoc(
|
* @ApiDoc(
|
||||||
* description="Create a new Object",
|
* description="Create a new Object",
|
||||||
* formType="Your\Namespace\Form\Type\YourType"
|
* input="Your\Namespace\Form\Type\YourType"
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
public function postAction()
|
public function postAction()
|
||||||
@ -99,16 +99,16 @@ The following properties are available:
|
|||||||
|
|
||||||
* `filters`: an array of filters;
|
* `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)
|
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
|
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.
|
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.
|
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
|
||||||
<?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
|
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 ##
|
## Credits ##
|
||||||
|
|
||||||
The design is heavily inspired by the [swagger-ui](https://github.com/wordnik/swagger-ui) project.
|
The design is heavily inspired by the [swagger-ui](https://github.com/wordnik/swagger-ui) project.
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
<services>
|
<services>
|
||||||
<service id="nelmio_api_doc.parser.form_type_parser" class="%nelmio_api_doc.parser.form_type_parser.class%">
|
<service id="nelmio_api_doc.parser.form_type_parser" class="%nelmio_api_doc.parser.form_type_parser.class%">
|
||||||
<argument type="service" id="form.factory" />
|
<argument type="service" id="form.factory" />
|
||||||
<tag name="nelmio_api_doc.extractor.parser" priority="0" />
|
<tag name="nelmio_api_doc.extractor.parser" />
|
||||||
</service>
|
</service>
|
||||||
<service id="nelmio_api_doc.formatter.abstract_formatter" class="%nelmio_api_doc.formatter.abstract_formatter.class%" />
|
<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%"
|
<service id="nelmio_api_doc.formatter.markdown_formatter" class="%nelmio_api_doc.formatter.markdown_formatter.class%"
|
||||||
|
@ -35,7 +35,7 @@ class TestController
|
|||||||
/**
|
/**
|
||||||
* @ApiDoc(
|
* @ApiDoc(
|
||||||
* description="create test",
|
* description="create test",
|
||||||
* inputClass="Nelmio\ApiDocBundle\Tests\Fixtures\Form\TestType"
|
* input="Nelmio\ApiDocBundle\Tests\Fixtures\Form\TestType"
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
public function postTestAction()
|
public function postTestAction()
|
||||||
@ -76,7 +76,7 @@ class TestController
|
|||||||
/**
|
/**
|
||||||
* @ApiDoc(
|
* @ApiDoc(
|
||||||
* description="create another test",
|
* description="create another test",
|
||||||
* inputClass="dependency_type"
|
* input="dependency_type"
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
public function anotherPostAction()
|
public function anotherPostAction()
|
||||||
|
@ -81,18 +81,21 @@ class SimpleFormatterTest extends WebTestCase
|
|||||||
'dataType' => 'string',
|
'dataType' => 'string',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'description' => 'A nice description',
|
'description' => 'A nice description',
|
||||||
|
'readonly' => false
|
||||||
),
|
),
|
||||||
'b' =>
|
'b' =>
|
||||||
array(
|
array(
|
||||||
'dataType' => 'string',
|
'dataType' => 'string',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'description' => '',
|
'description' => '',
|
||||||
|
'readonly' => false
|
||||||
),
|
),
|
||||||
'c' =>
|
'c' =>
|
||||||
array(
|
array(
|
||||||
'dataType' => 'boolean',
|
'dataType' => 'boolean',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'description' => '',
|
'description' => '',
|
||||||
|
'readonly' => false
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'description' => 'create test',
|
'description' => 'create test',
|
||||||
@ -108,18 +111,21 @@ class SimpleFormatterTest extends WebTestCase
|
|||||||
'dataType' => 'string',
|
'dataType' => 'string',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'description' => 'A nice description',
|
'description' => 'A nice description',
|
||||||
|
'readonly' => false
|
||||||
),
|
),
|
||||||
'b' =>
|
'b' =>
|
||||||
array(
|
array(
|
||||||
'dataType' => 'string',
|
'dataType' => 'string',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'description' => '',
|
'description' => '',
|
||||||
|
'readonly' => false
|
||||||
),
|
),
|
||||||
'c' =>
|
'c' =>
|
||||||
array(
|
array(
|
||||||
'dataType' => 'boolean',
|
'dataType' => 'boolean',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'description' => '',
|
'description' => '',
|
||||||
|
'readonly' => false
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'description' => 'create test',
|
'description' => 'create test',
|
||||||
@ -138,6 +144,7 @@ class SimpleFormatterTest extends WebTestCase
|
|||||||
'dataType' => 'string',
|
'dataType' => 'string',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'description' => 'A nice description',
|
'description' => 'A nice description',
|
||||||
|
'readonly' => false
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'description' => 'create another test',
|
'description' => 'create another test',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user