Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 95b0f0a

Browse files
committed
[Docs] fixes
1 parent 011444a commit 95b0f0a

2 files changed

Lines changed: 39 additions & 24 deletions

File tree

docs/api/unified_api/sylius_api_paths.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ Sylius API paths
22
================
33

44
All paths in new API have the same prefix structure: ``/api/v2/admin/`` or ``/api/v2/shop/``
5-
Part ``/api/v2`` indicates the API version and ``/admin/`` or ``/shop/`` is necessary for authorization purpose.
6-
5+
The ``/api/v2`` prefix part indicates the API version and the ``/admin/`` or ``/shop/`` prefixes are necessary for authorization purposes.
76
When you are adding a new path to API resource configuration, you should remember to add also proper prefix.
87

98
You can declare the entire path for each operation (without ``/api/v2/`` as this part is configured globally):

docs/customization/api.rst

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
Customizing API
22
===============
33

4-
For create all endpoints in Sylius API we are using the API Platform.
5-
API Platform allows to configure endpoint by ``yaml`` and ``xml`` files or in ``annotations``.
6-
In these guide we will show you how to customize Sylius API endpoint with ``xml``.
4+
We are using the API Platform to create all endpoints in Sylius API.
5+
API Platform allows configuring an endpoint by ``yaml`` and ``xml`` files or by annotations.
6+
In this guide, you will learn how to customize Sylius API endpoints using ``xml`` configuration.
77

8-
How to prepare project to customization?
8+
How to prepare project for customization?
99
========================================
1010

11-
For any kind of customization firstly you need to configure location of your configs.
11+
For any kind of customization firstly you need to configure directory with your configs.
1212

1313
.. code-block:: yaml
1414
# config/packages/api_platform.yaml
@@ -22,41 +22,51 @@ For any kind of customization firstly you need to configure location of your con
2222
swagger:
2323
versions: [3]
2424
25-
And now if you want to customize any API resource you need copy entire configuration of this resource from ``%kernel.project_dir%/vendor/sylius/sylius/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/`` to ``%kernel.project_dir%/config/api_platform``
25+
And now if you want to customize any API resource you need to copy the entire configuration of this resource from ``%kernel.project_dir%/vendor/sylius/sylius/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/`` to ``%kernel.project_dir%/config/api_platform``
2626

27-
How to add an additional endpoint to a resource?
28-
================================================
27+
How to add an additional endpoint?
28+
==================================
2929

30-
Let's assume that you want to add new endpoint to ``order`` which will dispatch a command.
30+
Let's assume that you want to add a new endpoint to the ``Order`` resource that will be dispatching a command.
3131
You need to add proper configuration in ``config/api_platform/Order.xml``:
3232

3333
.. code-block:: xml
3434
3535
<collectionOperations>
3636
<collectionOperation name="custom_operation">
3737
<attribute name="method">POST</attribute>
38-
<attribute name="path">/shop/order/custom-operation</attribute>
38+
<attribute name="path">/shop/orders/custom-operation</attribute>
3939
<attribute name="messenger">input</attribute>
4040
<attribute name="input">App\Command\CustomCommand</attribute>
4141
</collectionOperation>
4242
</collectionOperations>
4343
44-
And that's all, now you have new endpoint with your custom logic.
44+
And that's all, now you have a new endpoint with your custom logic.
4545

4646
.. tip::
4747

4848
Read more about API Platform endpoint configuration `here <https://api-platform.com/docs/core/operations/>`_
4949

50-
How to remove a resource endpoint?
51-
==================================
50+
How to remove an endpoint?
51+
==========================
52+
53+
Let's assume that your shop is offering only digital products. Therefore, while checking out,
54+
your customers do not need to choose a shipping method for their orders.
5255

53-
Let's assume that your shop offer only digital products so you don't need setting shipment method at all.
54-
To remove endpoint you only need to delete unnecessary configuration from ``config/api_platform/Order.xml``
56+
Thus you will need to modify the configuration file of the ``Order`` resource and remove the shipping method choosing endpoint from it.
57+
To remove the endpoint you only need to delete the unnecessary configuration from your ``config/api_platform/Order.xml`` which is a copied configuration file, that overwrites the one from Sylius.
58+
59+
.. code-block:: xml
5560
56-
How to rename the resource endpoint's path?
61+
<!-- delete this configuration -->
62+
<itemOperation name="shop_select_shipping_method">
63+
<!-- ... -->
64+
</itemOperation>
65+
66+
How to rename an endpoint's path?
5767
===========================================
5868

59-
If you want to change endpoint's path, only what you need to do is change ``path`` attribute in your config:
69+
If you want to change an endpoint's path, you just need to change the ``path`` attribute in your config:
6070

6171
.. code-block:: xml
6272
@@ -67,14 +77,20 @@ If you want to change endpoint's path, only what you need to do is change ``path
6777
</itemOperation>
6878
</itemOperations>
6979
70-
How to modify the endpoints prefixes? "shop" to "retail" rename.
71-
===============================================================
80+
How to modify the endpoints prefixes?
81+
=====================================
7282

73-
Let's assume that you want to have your own prefixes on paths (for example to be more consistent with rest of your application)
74-
As a first step you need to change ``paths`` or ``route_prefix`` attribute in all needed resources.
75-
Next step is modify security configuration in ``config/packages/security.yaml``, you need to overwrite parameter:
83+
Let's assume that you want to have your own prefixes on paths (for example to be more consistent with the rest of your application).
84+
As the first step you need to change the ``paths`` or ``route_prefix`` attribute in all needed resources.
85+
The next step is to modify the security configuration in ``config/packages/security.yaml``, you need to overwrite the parameter:
7686

7787
.. code-block:: xml
7888
7989
parameters:
8090
sylius.security.new_api_shop_route: "%sylius.security.new_api_route%/retail"
91+
92+
.. warning::
93+
94+
Changing prefixed without security configuration update can expose confidential data (like customers addresses)
95+
96+
After these two steps you can start to use endpoints with new prefixes

0 commit comments

Comments
 (0)