Skip to content

Commit

Permalink
[DEVX-636] dynamically add discriminator when creating a transaction …
Browse files Browse the repository at this point in the history
…so the response will serialize to the correct response type (#39)

* [DEVX-636] dynamically add discriminator when creating a transaction, so the response will serialize to the correct response type

* ci: regenerated with OpenAPI Doc , Speakeasy CLI 1.259.0 (#40)

Co-authored-by: speakeasybot <[email protected]>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: speakeasybot <[email protected]>
  • Loading branch information
3 people authored Apr 18, 2024
1 parent 744fb96 commit 5244277
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 19 deletions.
14 changes: 8 additions & 6 deletions .speakeasy/gen.lock
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
lockVersion: 2.0.0
id: 986026b6-d725-4b86-9c4d-67f6e6904a30
management:
docChecksum: 1dd065f0b69fdf1f392a15d7d7cd4e7b
docChecksum: c1432566bb0f190d84ea60211789b4e9
docVersion: "2018-02-08"
speakeasyVersion: 1.258.2
generationVersion: 2.309.2
releaseVersion: 3.2.7
configChecksum: 18e5e7665d39581a649de439f222f6af
speakeasyVersion: 1.259.0
generationVersion: 2.310.0
releaseVersion: 3.2.8
configChecksum: 7e72c6b5e6163d4a3085d6fce09bb1ca
repoURL: https://github.com/goshippo/shippo-python-sdk.git
installationURL: https://github.com/goshippo/shippo-python-sdk.git
published: true
features:
python:
constsAndDefaults: 0.1.3
core: 4.6.4
core: 4.6.5
flattening: 2.81.1
globalSecurity: 2.83.5
globalServerURLs: 2.82.2
Expand Down Expand Up @@ -442,10 +442,12 @@ generatedFiles:
- docs/models/components/tracksrequest.md
- docs/models/components/transactionpaginatedlist.md
- docs/models/components/transactionmessages.md
- docs/models/components/responsetype.md
- docs/models/components/transaction.md
- docs/models/components/transactionstatusenum.md
- docs/models/components/transactioncreateresponse.md
- docs/models/components/instanttransactioncreateresponsemessages.md
- docs/models/components/instanttransactioncreateresponseresponsetype.md
- docs/models/components/instanttransactioncreateresponse.md
- docs/models/components/instanttransactionrate.md
- docs/models/components/transactioncreaterequest.md
Expand Down
2 changes: 1 addition & 1 deletion .speakeasy/gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ generation:
auth:
oAuth2ClientCredentialsEnabled: true
python:
version: 3.2.7
version: 3.2.8
additionalDependencies:
dependencies: {}
extraDependencies:
Expand Down
2 changes: 2 additions & 0 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ workflow:
openapi:
inputs:
- location: https://docs.goshippo.com/spec/shippoapi/public-api.yaml
overlays:
- location: https://docs.goshippo.com/spec/shippoapi/client-sdk-overlay.yaml
targets:
first-target:
target: python
Expand Down
2 changes: 2 additions & 0 deletions .speakeasy/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ sources:
openapi:
inputs:
- location: https://docs.goshippo.com/spec/shippoapi/public-api.yaml
overlays:
- location: https://docs.goshippo.com/spec/shippoapi/client-sdk-overlay.yaml
targets:
first-target:
target: python
Expand Down
12 changes: 11 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,14 @@ Based on:
### Generated
- [python v3.2.7] .
### Releases
- [PyPI v3.2.7] https://pypi.org/project/shippo/3.2.7 - .
- [PyPI v3.2.7] https://pypi.org/project/shippo/3.2.7 - .

## 2024-04-18 16:03:45
### Changes
Based on:
- OpenAPI Doc
- Speakeasy CLI 1.259.0 (2.310.0) https://github.com/speakeasy-api/speakeasy
### Generated
- [python v3.2.8] .
### Releases
- [PyPI v3.2.8] https://pypi.org/project/shippo/3.2.8 - .
3 changes: 2 additions & 1 deletion docs/models/components/instanttransactioncreateresponse.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
| `tracking_number` | *Optional[str]* | :heavy_minus_sign: | The carrier-specific tracking number that can be used to track the Shipment. <br/>A value will only be returned if the Rate is for a trackable Shipment and if the Transactions has been processed successfully. | 9499907123456123456781 |
| `tracking_status` | [Optional[components.TrackingStatusEnum]](../../models/components/trackingstatusenum.md) | :heavy_minus_sign: | Indicates the high level status of the shipment. | DELIVERED |
| `tracking_url_provider` | *Optional[str]* | :heavy_minus_sign: | A link to track this item on the carrier-provided tracking website. <br/>A value will only be returned if tracking is available and the carrier provides such a service. | https://tools.usps.com/go/TrackConfirmAction_input?origTrackNum=9499907123456123456781 |
| `rate` | [Optional[components.InstantTransactionRate]](../../models/components/instanttransactionrate.md) | :heavy_minus_sign: | N/A | |
| `rate` | [Optional[components.InstantTransactionRate]](../../models/components/instanttransactionrate.md) | :heavy_minus_sign: | N/A | |
| `response_type` | [Optional[components.InstantTransactionCreateResponseResponseType]](../../models/components/instanttransactioncreateresponseresponsetype.md) | :heavy_minus_sign: | N/A | |
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# InstantTransactionCreateResponseResponseType


## Values

| Name | Value |
| --------- | --------- |
| `INSTANT` | instant |
8 changes: 8 additions & 0 deletions docs/models/components/responsetype.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ResponseType


## Values

| Name | Value |
| ---------- | ---------- |
| `STANDARD` | standard |
3 changes: 2 additions & 1 deletion docs/models/components/transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
| `tracking_number` | *Optional[str]* | :heavy_minus_sign: | The carrier-specific tracking number that can be used to track the Shipment. <br/>A value will only be returned if the Rate is for a trackable Shipment and if the Transactions has been processed successfully. | 9499907123456123456781 |
| `tracking_status` | [Optional[components.TrackingStatusEnum]](../../models/components/trackingstatusenum.md) | :heavy_minus_sign: | Indicates the high level status of the shipment. | DELIVERED |
| `tracking_url_provider` | *Optional[str]* | :heavy_minus_sign: | A link to track this item on the carrier-provided tracking website. <br/>A value will only be returned if tracking is available and the carrier provides such a service. | https://tools.usps.com/go/TrackConfirmAction_input?origTrackNum=9499907123456123456781 |
| `rate` | *Optional[str]* | :heavy_minus_sign: | ID of the Rate object for which a Label has to be obtained. <br/>Please note that only rates that are not older than 7 days can be purchased in order to ensure up-to-date pricing. | ec9f0d3adc9441449c85d315f0997fd5 |
| `rate` | *Optional[str]* | :heavy_minus_sign: | ID of the Rate object for which a Label has to be obtained. <br/>Please note that only rates that are not older than 7 days can be purchased in order to ensure up-to-date pricing. | ec9f0d3adc9441449c85d315f0997fd5 |
| `response_type` | [Optional[components.ResponseType]](../../models/components/responsetype.md) | :heavy_minus_sign: | N/A | |
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

setuptools.setup(
name='shippo',
version='3.2.7',
version='3.2.8',
author='Shippo',
description='Python Client SDK Generated by Speakeasy',
url='https://github.com/goshippo/shippo-python-sdk.git',
Expand Down
22 changes: 21 additions & 1 deletion src/shippo/_hooks/registration.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import Union, Tuple

import json
import requests

from .types import Hooks, BeforeRequestHook, BeforeRequestContext, SDKInitHook
from .types import Hooks, BeforeRequestHook, BeforeRequestContext, SDKInitHook, AfterSuccessHook, AfterSuccessContext


# This file is only ever generated once on the first generation and then is free to be modified.
Expand Down Expand Up @@ -38,9 +39,28 @@ def custom_send(request, **kwargs):
return base_url, client


class TransactionCreateResponseAddDiscriminatorAfterSuccessHook(AfterSuccessHook):

def after_success(self, hook_ctx: AfterSuccessContext, response: requests.Response) -> Union[requests.Response, Exception]:
if hook_ctx.operation_id == "CreateTransaction":
if response.status_code == 201:
content: dict = response.json()
rate = content.get("rate")
response_type = None
if isinstance(rate, str):
response_type = "standard"
elif isinstance(rate, dict):
response_type = "instant"
if response_type is not None:
content["responseType"] = response_type
updated_content = json.dumps(content)
response._content = updated_content.encode(response.encoding)
return response

def init_hooks(hooks: Hooks):
# pylint: disable=unused-argument
"""Add hooks by calling hooks.register{sdk_init/before_request/after_success/after_error}Hook
with an instance of a hook that implements that specific Hook interface
Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance"""
hooks.register_sdk_init_hook(ShippoAuthTokenInitHook())
hooks.register_after_success_hook(TransactionCreateResponseAddDiscriminatorAfterSuccessHook())
Loading

0 comments on commit 5244277

Please sign in to comment.