Skip to content

Commit

Permalink
Update requests with a Json body
Browse files Browse the repository at this point in the history
Previously we were assuming that any POST or PATCH request would have a
Json body, but this had many false positives and false negatives.

This commit builds on highsidelabs/saloon-sdk-generator#3
to look for request bodies with the `application/json` content type and
is a PUT, POST or PATCH request.

As a result, some requests have the trait removed and others have it
added.
  • Loading branch information
dpash committed Jun 10, 2024
1 parent f821b7b commit d3a3cde
Show file tree
Hide file tree
Showing 38 changed files with 216 additions and 102 deletions.
2 changes: 1 addition & 1 deletion resources/models/seller/orders/v0.json
Original file line number Diff line number Diff line change
Expand Up @@ -5232,4 +5232,4 @@
}
},
"x-original-swagger-version": "2.0"
}
}
3 changes: 1 addition & 2 deletions src/Generator/Generators/RequestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ protected function generateRequestClass(Endpoint $endpoint): PhpFile
$classType->setExtends($baseRequestClass)
->setComment($endpoint->name);

// TODO: We assume JSON body if post/patch, make these assumptions configurable in the future.
if ($endpoint->method->isPost() || $endpoint->method->isPatch()) {
if ($endpoint->bodySchema?->bodyContentType === 'application/json' && ($endpoint->method->isPut() || $endpoint->method->isPost() || $endpoint->method->isPatch())) {
$classType
->addImplement(HasBody::class)
->addTrait(HasJsonBody::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
namespace SellingPartnerApi\Seller\APlusContentV20201101\Requests;

use Exception;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;
use SellingPartnerApi\Request;
use SellingPartnerApi\Seller\APlusContentV20201101\Responses\ErrorList;
use SellingPartnerApi\Seller\APlusContentV20201101\Responses\PostContentDocumentApprovalSubmissionResponse;

/**
* postContentDocumentApprovalSubmission
*/
class PostContentDocumentApprovalSubmission extends Request implements HasBody
class PostContentDocumentApprovalSubmission extends Request
{
use HasJsonBody;

protected Method $method = Method::POST;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
namespace SellingPartnerApi\Seller\APlusContentV20201101\Requests;

use Exception;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;
use SellingPartnerApi\Request;
use SellingPartnerApi\Seller\APlusContentV20201101\Responses\ErrorList;
use SellingPartnerApi\Seller\APlusContentV20201101\Responses\PostContentDocumentSuspendSubmissionResponse;

/**
* postContentDocumentSuspendSubmission
*/
class PostContentDocumentSuspendSubmission extends Request implements HasBody
class PostContentDocumentSuspendSubmission extends Request
{
use HasJsonBody;

protected Method $method = Method::POST;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
namespace SellingPartnerApi\Seller\ApplicationManagementV20231130\Requests;

use Exception;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;
use SellingPartnerApi\EmptyResponse;
use SellingPartnerApi\Request;
use SellingPartnerApi\Seller\ApplicationManagementV20231130\Responses\ErrorList;

/**
* rotateApplicationClientSecret
*/
class RotateApplicationClientSecret extends Request implements HasBody
class RotateApplicationClientSecret extends Request
{
use HasJsonBody;

protected Method $method = Method::POST;

public function resolveEndpoint(): string
Expand Down
6 changes: 1 addition & 5 deletions src/Seller/FBAInboundV0/Requests/ConfirmTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@
namespace SellingPartnerApi\Seller\FBAInboundV0\Requests;

use Exception;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;
use SellingPartnerApi\Request;
use SellingPartnerApi\Seller\FBAInboundV0\Responses\ConfirmTransportResponse;

/**
* confirmTransport
*/
class ConfirmTransport extends Request implements HasBody
class ConfirmTransport extends Request
{
use HasJsonBody;

protected Method $method = Method::POST;

/**
Expand Down
6 changes: 1 addition & 5 deletions src/Seller/FBAInboundV0/Requests/EstimateTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@
namespace SellingPartnerApi\Seller\FBAInboundV0\Requests;

use Exception;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;
use SellingPartnerApi\Request;
use SellingPartnerApi\Seller\FBAInboundV0\Responses\EstimateTransportResponse;

/**
* estimateTransport
*/
class EstimateTransport extends Request implements HasBody
class EstimateTransport extends Request
{
use HasJsonBody;

protected Method $method = Method::POST;

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Seller/FBAInboundV0/Requests/PutTransportDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
namespace SellingPartnerApi\Seller\FBAInboundV0\Requests;

use Exception;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;
use SellingPartnerApi\Request;
use SellingPartnerApi\Seller\FBAInboundV0\Dto\PutTransportDetailsRequest;
use SellingPartnerApi\Seller\FBAInboundV0\Responses\PutTransportDetailsResponse;

/**
* putTransportDetails
*/
class PutTransportDetails extends Request
class PutTransportDetails extends Request implements HasBody
{
use HasJsonBody;

protected Method $method = Method::PUT;

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Seller/FBAInboundV0/Requests/UpdateInboundShipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
namespace SellingPartnerApi\Seller\FBAInboundV0\Requests;

use Exception;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;
use SellingPartnerApi\Request;
use SellingPartnerApi\Seller\FBAInboundV0\Dto\InboundShipmentRequest;
use SellingPartnerApi\Seller\FBAInboundV0\Responses\InboundShipmentResponse;

/**
* updateInboundShipment
*/
class UpdateInboundShipment extends Request
class UpdateInboundShipment extends Request implements HasBody
{
use HasJsonBody;

protected Method $method = Method::PUT;

/**
Expand Down
6 changes: 1 addition & 5 deletions src/Seller/FBAInboundV0/Requests/VoidTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@
namespace SellingPartnerApi\Seller\FBAInboundV0\Requests;

use Exception;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;
use SellingPartnerApi\Request;
use SellingPartnerApi\Seller\FBAInboundV0\Responses\VoidTransportResponse;

/**
* voidTransport
*/
class VoidTransport extends Request implements HasBody
class VoidTransport extends Request
{
use HasJsonBody;

protected Method $method = Method::POST;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
namespace SellingPartnerApi\Seller\FBAInboundV20240320\Requests;

use Exception;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;
use SellingPartnerApi\Request;
use SellingPartnerApi\Seller\FBAInboundV20240320\Dto\CancelSelfShipAppointmentRequest;
use SellingPartnerApi\Seller\FBAInboundV20240320\Responses\CancelSelfShipAppointmentResponse;
Expand All @@ -15,8 +17,10 @@
/**
* cancelSelfShipAppointment
*/
class CancelSelfShipAppointment extends Request
class CancelSelfShipAppointment extends Request implements HasBody
{
use HasJsonBody;

protected Method $method = Method::PUT;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
namespace SellingPartnerApi\Seller\FBAInboundV20240320\Requests;

use Exception;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;
use SellingPartnerApi\Request;
use SellingPartnerApi\Seller\FBAInboundV20240320\Responses\ConfirmDeliveryWindowOptionsResponse;
use SellingPartnerApi\Seller\FBAInboundV20240320\Responses\ErrorList;

/**
* confirmDeliveryWindowOptions
*/
class ConfirmDeliveryWindowOptions extends Request implements HasBody
class ConfirmDeliveryWindowOptions extends Request
{
use HasJsonBody;

protected Method $method = Method::POST;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
namespace SellingPartnerApi\Seller\FBAInboundV20240320\Requests;

use Exception;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;
use SellingPartnerApi\Request;
use SellingPartnerApi\Seller\FBAInboundV20240320\Responses\ConfirmPackingOptionResponse;
use SellingPartnerApi\Seller\FBAInboundV20240320\Responses\ErrorList;

/**
* confirmPackingOption
*/
class ConfirmPackingOption extends Request implements HasBody
class ConfirmPackingOption extends Request
{
use HasJsonBody;

protected Method $method = Method::POST;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
namespace SellingPartnerApi\Seller\FBAInboundV20240320\Requests;

use Exception;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;
use SellingPartnerApi\Request;
use SellingPartnerApi\Seller\FBAInboundV20240320\Responses\ConfirmPlacementOptionResponse;
use SellingPartnerApi\Seller\FBAInboundV20240320\Responses\ErrorList;

/**
* confirmPlacementOption
*/
class ConfirmPlacementOption extends Request implements HasBody
class ConfirmPlacementOption extends Request
{
use HasJsonBody;

protected Method $method = Method::POST;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
namespace SellingPartnerApi\Seller\FBAInboundV20240320\Requests;

use Exception;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;
use SellingPartnerApi\Request;
use SellingPartnerApi\Seller\FBAInboundV20240320\Responses\ConfirmShipmentContentUpdatePreviewResponse;
use SellingPartnerApi\Seller\FBAInboundV20240320\Responses\ErrorList;

/**
* confirmShipmentContentUpdatePreview
*/
class ConfirmShipmentContentUpdatePreview extends Request implements HasBody
class ConfirmShipmentContentUpdatePreview extends Request
{
use HasJsonBody;

protected Method $method = Method::POST;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
namespace SellingPartnerApi\Seller\FBAInboundV20240320\Requests;

use Exception;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;
use SellingPartnerApi\Request;
use SellingPartnerApi\Seller\FBAInboundV20240320\Responses\ErrorList;
use SellingPartnerApi\Seller\FBAInboundV20240320\Responses\GenerateDeliveryWindowOptionsResponse;

/**
* generateDeliveryWindowOptions
*/
class GenerateDeliveryWindowOptions extends Request implements HasBody
class GenerateDeliveryWindowOptions extends Request
{
use HasJsonBody;

protected Method $method = Method::POST;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
namespace SellingPartnerApi\Seller\FBAInboundV20240320\Requests;

use Exception;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;
use SellingPartnerApi\Request;
use SellingPartnerApi\Seller\FBAInboundV20240320\Responses\ErrorList;
use SellingPartnerApi\Seller\FBAInboundV20240320\Responses\GeneratePackingOptionsResponse;

/**
* generatePackingOptions
*/
class GeneratePackingOptions extends Request implements HasBody
class GeneratePackingOptions extends Request
{
use HasJsonBody;

protected Method $method = Method::POST;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
namespace SellingPartnerApi\Seller\FBAInboundV20240320\Requests;

use Exception;
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;
use SellingPartnerApi\EmptyResponse;
use SellingPartnerApi\Request;
use SellingPartnerApi\Seller\FBAInboundV20240320\Dto\UpdateInboundPlanNameRequest;
Expand All @@ -15,8 +17,10 @@
/**
* updateInboundPlanName
*/
class UpdateInboundPlanName extends Request
class UpdateInboundPlanName extends Request implements HasBody
{
use HasJsonBody;

protected Method $method = Method::PUT;

/**
Expand Down
Loading

0 comments on commit d3a3cde

Please sign in to comment.