Skip to content

Commit

Permalink
refactor #12257 [API] change new-api prefix to api (SirDomin)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.9-dev branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | master
| Bug fix?        | no
| New feature?    | no
| BC breaks?      | i think yes
| Deprecations?   | no
| Related tickets | 
| License         | MIT

<!--
 - Bug fixes must be submitted against the 1.7 or 1.8 branch (the lowest possible)
 - Features and deprecations must be submitted against the master branch
 - Make sure that the correct base branch is set

 To be sure you are not breaking any Backward Compatibilities, check the documentation:
 https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html
-->


Commits
-------

4d03e0d [API] change new-api to api
746eede [Doc] UPGRADE file updated
078cac2 [Spec] added new test to work with long api routes
c71d11f [Doc] upgrade file info added
d02f20d hardcode api/v1 + test fix
  • Loading branch information
pamil committed Jan 21, 2021
2 parents f13dbff + d02f20d commit aaea4c0
Show file tree
Hide file tree
Showing 45 changed files with 78 additions and 90 deletions.
24 changes: 23 additions & 1 deletion UPGRADE-1.9.md
Expand Up @@ -55,7 +55,7 @@
+ - JSON_PRESERVE_ZERO_FRACTION
```

1. Replace key in `config/packages/jms_serializer.yaml`:
1. Replace key in `config/packages/jms_serializer.yaml`:

```diff
jms_serializer:
Expand All @@ -64,6 +64,25 @@
+ xml_serialization:
```

1. Unified API parameters have been changed in `config/packages/security.yaml` to:

```diff
parameters:
- sylius.security.api_regex: "^/api"
- sylius.security.shop_regex: "^/(?!%sylius_admin.path_name%|new-api|api/.*|api$|media/.*)[^/]++"
- sylius.security.new_api_route: "/new-api"
+ sylius.security.api_regex: "^/api/v1"
+ sylius.security.shop_regex: "^/(?!%sylius_admin.path_name%|api/.*|api$|media/.*)[^/]++"
+ sylius.security.new_api_route: "/api/v2"
```
1. `config/packages/fos_rest.yaml` rules have been changed to:

```diff
rules:
- - { path: '^/api/.*', priorities: ['json', 'xml'], fallback_format: json, prefer_extension: true }
+ - { path: '^/api/v1/.*', priorities: ['json', 'xml'], fallback_format: json, prefer_extension: true }
```

### Data migrations

1. The `CoreBundle/Migrations/Version20201208105207.php` migration was added which extends existing adjustments with additional details (context).
Expand Down Expand Up @@ -135,3 +154,6 @@
1. We've replaced deprecated Symfony Translator API with the new one.

Replace `Symfony\Component\Translation\TranslatorInterface` with `Symfony\Contracts\Translation\TranslatorInterface` in your codebase.

1. `/new-api` prefix has been changed to `/api/v2`. Please adjust your routes accordingly.
Admin API is hardcoded to `/api/v1` instead of `/api/v{version}`.
2 changes: 1 addition & 1 deletion config/packages/fos_rest.yaml
Expand Up @@ -7,5 +7,5 @@ fos_rest:
empty_content: 204
format_listener:
rules:
- { path: '^/api/.*', priorities: ['json', 'xml'], fallback_format: json, prefer_extension: true }
- { path: '^/api/v1/.*', priorities: ['json', 'xml'], fallback_format: json, prefer_extension: true }
- { path: '^/', stop: true }
6 changes: 3 additions & 3 deletions config/packages/security.yaml
@@ -1,8 +1,8 @@
parameters:
sylius.security.admin_regex: "^/%sylius_admin.path_name%"
sylius.security.api_regex: "^/api"
sylius.security.shop_regex: "^/(?!%sylius_admin.path_name%|new-api|api/.*|api$|media/.*)[^/]++"
sylius.security.new_api_route: "/new-api"
sylius.security.api_regex: "^/api/v1"
sylius.security.shop_regex: "^/(?!%sylius_admin.path_name%|api/.*|api$|media/.*)[^/]++"
sylius.security.new_api_route: "/api/v2"
sylius.security.new_api_regex: "^%sylius.security.new_api_route%"
sylius.security.new_api_admin_route: "%sylius.security.new_api_route%/admin"
sylius.security.new_api_admin_regex: "^%sylius.security.new_api_admin_route%"
Expand Down
2 changes: 1 addition & 1 deletion docs/api/unified_api/authorization.rst
Expand Up @@ -2,7 +2,7 @@ Authorization
=============

In the new API all admin routes are protected by JWT authentication. If you would like to test these endpoints
`in our Swagger UI docs <http://master.demo.sylius.com/new-api/docs>`_, you need to retrieve a JWT token first.
`in our Swagger UI docs <http://master.demo.sylius.com/api/v2/docs>`_, you need to retrieve a JWT token first.
You could do that by using an endpoint with default credentials for API administrators:

.. image:: ../../_images/sylius_api/api_platform_authentication_endpoint.png
Expand Down
2 changes: 1 addition & 1 deletion docs/api/unified_api/introduction.rst
Expand Up @@ -13,4 +13,4 @@ We will be supporting API Platform out-of-the-box. Secondly, it means that both
be deprecated. We are not dropping them right now, but they will not receive further development. In the later phase,
we should provide an upgrade path for currently working apps. Last, but not least, you can already track our progress.
All the PR’s will be aggregated `in this issue <https://github.com/Sylius/Sylius/issues/11250>`_ and the documentation
can be already found `here <http://master.demo.sylius.com/new-api/docs>`_.
can be already found `here <http://master.demo.sylius.com/api/v2/docs>`_.
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Client/ApiPlatformSecurityClient.php
Expand Up @@ -40,7 +40,7 @@ public function __construct(AbstractBrowser $client, string $section, SharedStor

public function prepareLoginRequest(): void
{
$this->request['url'] = sprintf('/new-api/%s/authentication-token', $this->section);
$this->request['url'] = sprintf('/api/v2/%s/authentication-token', $this->section);
$this->request['method'] = 'POST';
}

Expand Down
16 changes: 8 additions & 8 deletions src/Sylius/Behat/Client/Request.php
Expand Up @@ -51,7 +51,7 @@ public static function index(
$headers = $token ? ['HTTP_' . $authorizationHeader => 'Bearer ' . $token] : [];

return new self(
sprintf('/new-api/%s%s', self::prepareSection($section), $resource),
sprintf('/api/v2/%s%s', self::prepareSection($section), $resource),
HttpRequest::METHOD_GET,
$headers
);
Expand All @@ -60,7 +60,7 @@ public static function index(
public static function subResourceIndex(?string $section, string $resource, string $id, string $subResource): RequestInterface
{
return new self(
sprintf('/new-api/%s%s/%s/%s', self::prepareSection($section), $resource, $id, $subResource),
sprintf('/api/v2/%s%s/%s/%s', self::prepareSection($section), $resource, $id, $subResource),
HttpRequest::METHOD_GET
);
}
Expand All @@ -75,7 +75,7 @@ public static function show(
$headers = $token ? ['HTTP_' . $authorizationHeader => 'Bearer ' . $token] : [];

return new self(
sprintf('/new-api/%s%s/%s', self::prepareSection($section), $resource, $id),
sprintf('/api/v2/%s%s/%s', self::prepareSection($section), $resource, $id),
HttpRequest::METHOD_GET,
$headers
);
Expand All @@ -93,7 +93,7 @@ public static function create(
}

return new self(
sprintf('/new-api/%s%s', self::prepareSection($section), $resource),
sprintf('/api/v2/%s%s', self::prepareSection($section), $resource),
HttpRequest::METHOD_POST,
$headers
);
Expand All @@ -112,7 +112,7 @@ public static function update(
}

return new self(
sprintf('/new-api/%s%s/%s', self::prepareSection($section), $resource, $id),
sprintf('/api/v2/%s%s/%s', self::prepareSection($section), $resource, $id),
HttpRequest::METHOD_PUT,
$headers
);
Expand All @@ -128,7 +128,7 @@ public static function delete(
$headers = $token ? ['HTTP_' . $authorizationHeader => 'Bearer ' . $token] : [];

return new self(
sprintf('/new-api/%s%s/%s', self::prepareSection($section), $resource, $id),
sprintf('/api/v2/%s%s/%s', self::prepareSection($section), $resource, $id),
HttpRequest::METHOD_DELETE,
$headers
);
Expand All @@ -142,7 +142,7 @@ public static function transition(?string $section, string $resource, string $id
public static function customItemAction(?string $section, string $resource, string $id, string $type, string $action): RequestInterface
{
return new self(
sprintf('/new-api/%s%s/%s/%s', self::prepareSection($section), $resource, $id, $action),
sprintf('/api/v2/%s%s/%s/%s', self::prepareSection($section), $resource, $id, $action),
$type,
['CONTENT_TYPE' => 'application/merge-patch+json']
);
Expand All @@ -160,7 +160,7 @@ public static function upload(
}

return new self(
sprintf('/new-api/%s%s', self::prepareSection($section), $resource),
sprintf('/api/v2/%s%s', self::prepareSection($section), $resource),
HttpRequest::METHOD_POST,
$headers
);
Expand Down
Expand Up @@ -87,15 +87,15 @@ public function iSpecifyItsRatioAs(?string $ratio = null): void
*/
public function iChooseAsTheSourceCurrency(string $currencyCode): void
{
$this->client->addRequestData('sourceCurrency', '/new-api/admin/currencies/' . $currencyCode);
$this->client->addRequestData('sourceCurrency', '/api/v2/admin/currencies/' . $currencyCode);
}

/**
* @When I choose :currencyCode as the target currency
*/
public function iChooseAsTheTargetCurrency(string $currencyCode): void
{
$this->client->addRequestData('targetCurrency', '/new-api/admin/currencies/' . $currencyCode);
$this->client->addRequestData('targetCurrency', '/api/v2/admin/currencies/' . $currencyCode);
}

/**
Expand Down Expand Up @@ -349,12 +349,12 @@ private function assertIfNotBeAbleToEditItCurrency(string $currencyType): void
{
$this->client->buildUpdateRequest($this->sharedStorage->get('exchange_rate_id'));

$this->client->addRequestData($currencyType, '/new-api/admin/currencies/EUR');
$this->client->addRequestData($currencyType, '/api/v2/admin/currencies/EUR');
$this->client->update();

Assert::false(
$this->responseChecker->hasItemOnPositionWithValue(
$this->client->index(), 0, $currencyType, '/new-api/admin/currencies/EUR'
$this->client->index(), 0, $currencyType, '/api/v2/admin/currencies/EUR'
),
sprintf('It was possible to change %s', $currencyType)
);
Expand All @@ -367,8 +367,8 @@ private function getExchangeRateFromResponse(
/** @var array $item */
foreach ($this->responseChecker->getCollection($this->client->index()) as $item) {
if (
$item['sourceCurrency'] === '/new-api/admin/currencies/' . $sourceCurrency->getCode() &&
$item['targetCurrency'] === '/new-api/admin/currencies/' . $targetCurrency->getCode()
$item['sourceCurrency'] === '/api/v2/admin/currencies/' . $sourceCurrency->getCode() &&
$item['targetCurrency'] === '/api/v2/admin/currencies/' . $targetCurrency->getCode()
) {
return $item;
}
Expand Down
Expand Up @@ -140,7 +140,7 @@ public function thePaymentOfTheOrderShouldBeFor(
public function iShouldSeePaymentForTheOrderInTheList(OrderInterface $order, int $position): void
{
Assert::true($this->responseChecker->hasItemOnPositionWithValue(
$this->client->getLastResponse(), $position - 1, 'order', sprintf('/new-api/admin/orders/%s', $order->getTokenValue())
$this->client->getLastResponse(), $position - 1, 'order', sprintf('/api/v2/admin/orders/%s', $order->getTokenValue())
));
}

Expand Down
Expand Up @@ -400,7 +400,7 @@ public function iShouldNotBeAbleToEditItsCode(): void
$this->client->getLastResponse(),
0,
'code',
'/new-api/admin/products/_NEW'
'/api/v2/admin/products/_NEW'
),
sprintf('It was possible to change %s', '_NEW')
);
Expand Down
4 changes: 2 additions & 2 deletions src/Sylius/Behat/Context/Api/Shop/HomepageContext.php
Expand Up @@ -46,7 +46,7 @@ public function __construct(
public function iCheckLatestProducts(): void
{
$this->productsClient->customAction(
'new-api/shop/products?itemsPerPage=3&order[createdAt]=desc',
'api/v2/shop/products?itemsPerPage=3&order[createdAt]=desc',
HttpRequest::METHOD_GET
);
}
Expand All @@ -56,7 +56,7 @@ public function iCheckLatestProducts(): void
*/
public function iCheckAvailableTaxons(): void
{
$this->taxonsClient->customAction('new-api/shop/taxons', HttpRequest::METHOD_GET);
$this->taxonsClient->customAction('api/v2/shop/taxons', HttpRequest::METHOD_GET);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Sylius/Behat/Context/Api/Shop/OrderContext.php
Expand Up @@ -67,7 +67,7 @@ public function iChangeMyPaymentMethodTo(PaymentMethodInterface $paymentMethod):

$request = Request::custom(
\sprintf(
'/new-api/shop/account/orders/%s/payments/%s',
'/api/v2/shop/account/orders/%s/payments/%s',
$order->getTokenValue(),
(string) $order->getPayments()->first()->getId()
),
Expand Down Expand Up @@ -321,7 +321,7 @@ private function getAdjustmentsForOrder(): array
private function getAdjustmentsForOrderItem(string $itemId): array
{
$response = $this->client->customAction(
sprintf('/new-api/shop/orders/%s/items/%s/adjustments', $this->sharedStorage->get('cart_token'), $itemId),
sprintf('/api/v2/shop/orders/%s/items/%s/adjustments', $this->sharedStorage->get('cart_token'), $itemId),
HttpRequest::METHOD_GET
);

Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Context/Api/Shop/RegistrationContext.php
Expand Up @@ -112,7 +112,7 @@ public function iRegisterThisAccount(): void
{
$this->client->request(
'POST',
'/new-api/shop/customers/',
'/api/v2/shop/customers/',
[],
[],
['HTTP_ACCEPT' => 'application/ld+json', 'CONTENT_TYPE' => 'application/ld+json'],
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Service/ApiSecurityService.php
Expand Up @@ -41,7 +41,7 @@ public function logIn(UserInterface $user): void
{
$this->client->request(
'POST',
sprintf('/new-api/%s/authentication-token', $this->loginEndpoint),
sprintf('/api/v2/%s/authentication-token', $this->loginEndpoint),
[],
[],
['CONTENT_TYPE' => 'application/json', 'HTTP_ACCEPT' => 'application/json'],
Expand Down
Expand Up @@ -25,4 +25,3 @@ Sylius\Component\Addressing\Model\Country:
route: sylius_admin_api_country_show
parameters:
code: expr(object.getCode())
version: 1
Expand Up @@ -34,14 +34,12 @@ Sylius\Component\Addressing\Model\Province:
parameters:
countryCode: expr(object.getCountry().getCode())
code: expr(object.getCode())
version: 1
exclusion:
groups: [Default, Detailed]
- rel: country
href:
route: sylius_admin_api_country_show
parameters:
code: expr(object.getCountry().getCode())
version: 1
exclusion:
groups: [Detailed]
Expand Up @@ -41,4 +41,3 @@ Sylius\Component\Addressing\Model\Zone:
route: sylius_admin_api_zone_show
parameters:
code: expr(object.getCode())
version: 1
Expand Up @@ -6,4 +6,4 @@ fos_oauth_server_token:

sylius_admin_api:
resource: "@SyliusAdminApiBundle/Resources/config/routing/main.yml"
prefix: /v{version}
prefix: /v1
Expand Up @@ -15,6 +15,5 @@ Sylius\Component\Core\Model\Channel:
route: sylius_admin_api_channel_show
parameters:
code: expr(object.getCode())
version: 1
exclusion:
groups: [Default, Detailed, DetailedCart]
Expand Up @@ -11,6 +11,5 @@ Sylius\Component\Core\Model\Customer:
route: sylius_admin_api_customer_show
parameters:
id: expr(object.getId())
version: 1
exclusion:
groups: [Default, Detailed, DetailedCart]
Expand Up @@ -11,15 +11,13 @@ Sylius\Component\Core\Model\OrderItem:
route: sylius_admin_api_order_show
parameters:
id: expr(object.getOrder().getId())
version: 1
exclusion:
groups: [Default, Detailed, DetailedCart]
- rel: product
href:
route: sylius_admin_api_product_show
parameters:
code: expr(object.getVariant().getProduct().getCode())
version: 1
exclusion:
exclude_if: expr(!object.getVariant())
groups: [Default, Detailed, DetailedCart]
Expand All @@ -29,7 +27,6 @@ Sylius\Component\Core\Model\OrderItem:
parameters:
code: expr(object.getVariant().getCode())
productCode: expr(object.getVariant().getProduct().getCode())
version: 1
exclusion:
exclude_if: expr(!object.getVariant())
groups: [Default, Detailed, DetailedCart]
Expand Up @@ -9,20 +9,17 @@ Sylius\Component\Core\Model\Payment:
route: sylius_admin_api_order_show
parameters:
id: expr(object.getOrder().getId())
version: 1
- rel: self
exclusion:
exclude_if: expr(!object.getId())
href:
route: sylius_admin_api_payment_show
parameters:
id: expr(object.getId())
version: 1
- rel: payment-method
exclusion:
exclude_if: expr(!object.getMethod())
href:
route: sylius_admin_api_payment_method_show
parameters:
code: expr(object.getMethod().getCode())
version: 1
Expand Up @@ -11,4 +11,3 @@ Sylius\Component\Core\Model\PaymentMethod:
route: sylius_admin_api_payment_method_show
parameters:
code: expr(object.getCode())
version: 1
Expand Up @@ -34,12 +34,10 @@ Sylius\Component\Core\Model\Product:
route: sylius_admin_api_product_show
parameters:
code: expr(object.getCode())
version: 1
- rel: variants
href:
route: sylius_admin_api_product_variant_index
parameters:
productCode: expr(object.getCode())
version: 1
exclusion:
groups: [Detailed]
Expand Up @@ -51,12 +51,10 @@ Sylius\Component\Core\Model\ProductVariant:
parameters:
code: expr(object.getCode())
productCode: expr(object.getProduct().getCode())
version: 1
- rel: product
href:
route: sylius_admin_api_product_show
parameters:
code: expr(object.getProduct().getCode())
version: 1
exclusion:
groups: [Detailed]

0 comments on commit aaea4c0

Please sign in to comment.