Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions dev/build_doc_json_responses/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ NOTE: The test names are VERY important and must match up with the expected plur
## Installation

```bash
make install
just install
```

## Usage

First, if you are regenerating response snippets, you will first need to delete the related cassette file(s) in `tests/cassettes`. If a cassette file already exists for a given snippet, it will not be overwritten and the generated response snippet will not be updated.

Next, you will need to run the `make generate` command twice - it will fail the first time through; this is expected.
Next, you will need to run the `just generate` command twice - it will fail the first time through; this is expected.

```bash
# Run the following to save HTTP recordings
EASYPOST_TEST_API_KEY=putrealkeyhere EASYPOST_PROD_API_KEY=putrealkeyhere PARTNER_USER_PROD_API_KEY=putrealkeyhere REFERRAL_CUSTOMER_PROD_API_KEY=putrealkeyhere make generate
EASYPOST_TEST_API_KEY=putrealkeyhere EASYPOST_PROD_API_KEY=putrealkeyhere PARTNER_USER_PROD_API_KEY=putrealkeyhere REFERRAL_CUSTOMER_PROD_API_KEY=putrealkeyhere just generate

# Run the same command again to save the response snippets
EASYPOST_TEST_API_KEY=putrealkeyhere EASYPOST_PROD_API_KEY=putrealkeyhere PARTNER_USER_PROD_API_KEY=putrealkeyhere REFERRAL_CUSTOMER_PROD_API_KEY=putrealkeyhere make generate
EASYPOST_TEST_API_KEY=putrealkeyhere EASYPOST_PROD_API_KEY=putrealkeyhere PARTNER_USER_PROD_API_KEY=putrealkeyhere REFERRAL_CUSTOMER_PROD_API_KEY=putrealkeyhere just generate
```

**NOTE**: Some static data used by this tool, such as the USPS carrier account ID, is associated with the EasyPost Docs Tooling User. You must use that user's API keys to generate these snippets.
Expand All @@ -34,9 +34,9 @@ Generated response snippets are stored in the `responses` directory. Copy this e

## Linting

The `make lint` and `make lint-fix` commands in the Makefile will lint the Python code in this tool, but not the response snippets.
The `just lint` and `just lint-fix` commands in the Makefile will lint the Python code in this tool, but not the response snippets.

After copying the response snippets to `docs/responses`, you can lint them with the `make format-node` command in the root Makefile, which will lint and format all JSON files, including the response snippets, in the `docs` directory.
After copying the response snippets to `docs/responses`, you can lint them with the `just format-node` command in the root Makefile, which will lint and format all JSON files, including the response snippets, in the `docs` directory.

## Troubleshooting

Expand Down
27 changes: 23 additions & 4 deletions dev/build_doc_json_responses/builder/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,25 @@ def save_response_snippet(
"""Saves the response content of a cassette to a standalone snippet file."""
response_snippet_folder, bare_snippet_name = _setup_saving_response_snippet(response_snippet_filename)

with open(os.path.join(RESPONSES_DIR, response_snippet_folder, bare_snippet_name), "w") as response_snippet_file:
with open(
os.path.join(RESPONSES_DIR, response_snippet_folder, bare_snippet_name),
"w",
encoding="utf-8",
) as response_snippet_file:
if objects_to_persist:
json.dump(
json.loads(response_snippet_content)[:objects_to_persist],
response_snippet_file,
indent=2,
ensure_ascii=False, # It's possible we have non-ASCII characters in the response that we want preserved
)
else:
json.dump(json.loads(response_snippet_content), response_snippet_file, indent=2)
json.dump(
json.loads(response_snippet_content),
response_snippet_file,
indent=2,
ensure_ascii=False, # It's possible we have non-ASCII characters in the response that we want preserved
)

response_snippet_file.write("\n")

Expand All @@ -148,7 +158,16 @@ def save_raw_json(response_snippet_filename: str, response_dict: dict[str, Any])
"""
response_snippet_folder, bare_snippet_name = _setup_saving_response_snippet(response_snippet_filename)

with open(os.path.join(RESPONSES_DIR, response_snippet_folder, bare_snippet_name), "w") as response_snippet_file:
json.dump(response_dict, response_snippet_file, indent=2)
with open(
os.path.join(RESPONSES_DIR, response_snippet_folder, bare_snippet_name),
"w",
encoding="utf-8",
) as response_snippet_file:
json.dump(
response_dict,
response_snippet_file,
indent=2,
ensure_ascii=False, # It's possible we have non-ASCII characters in the response that we want preserved
)

response_snippet_file.write("\n")
27 changes: 14 additions & 13 deletions docs/responses/carrier-metadata/retrieve.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"carriers": [
{
"human_readable": "USPS",
"human_readable": "USPS BYOCA",
"name": "usps",
"predefined_packages": [
{
Expand Down Expand Up @@ -205,7 +205,7 @@
"Cards, Letters and Flats only (no Parcels)",
"See Predefined Packages (Card, Letter, Flat) for details"
],
"human_readable": "First-Class Mail\u00ae",
"human_readable": "First-Class Mail®",
"max_weight": 13.0,
"name": "First"
},
Expand All @@ -215,7 +215,7 @@
"dimensions": [
"Combined Length and Girth < 108in"
],
"human_readable": "Priority Mail\u00ae",
"human_readable": "Priority Mail®",
"max_weight": 1120.0,
"name": "Priority"
},
Expand All @@ -225,7 +225,7 @@
"dimensions": [
"Combined Length and Girth < 108in"
],
"human_readable": "Priority Mail Express\u00ae",
"human_readable": "Priority Mail Express®",
"max_weight": 1120.0,
"name": "Express"
},
Expand All @@ -235,8 +235,8 @@
"dimensions": [
"Combined Length and Girth < 130in"
],
"human_readable": "USPS Ground Advantage\u00ae",
"max_weight": 70.0,
"human_readable": "USPS Ground Advantage®",
"max_weight": 1120.0,
"name": "GroundAdvantage"
},
{
Expand All @@ -245,7 +245,7 @@
"dimensions": [
"Combined Length and Girth < 108in"
],
"human_readable": "Library Mail\u00ae",
"human_readable": "Library Mail®",
"max_weight": 1120.0,
"name": "LibraryMail"
},
Expand All @@ -255,7 +255,7 @@
"dimensions": [
"Combined Length and Girth < 108in"
],
"human_readable": "Media Mail\u00ae",
"human_readable": "Media Mail®",
"max_weight": 1120.0,
"name": "MediaMail"
},
Expand All @@ -265,7 +265,7 @@
"dimensions": [
"Must be rectangular, otherwise an additional charge may apply."
],
"human_readable": "First-Class Mail International\u00ae",
"human_readable": "First-Class Mail International®",
"max_weight": 15.994,
"name": "FirstClassMailInternational"
},
Expand All @@ -277,7 +277,7 @@
"Rolls (Tubes): Length: min 4in; max 36 in. Length plus twice the diameter (combined): min 6.75 in; max 42in.",
"Some countries have specific prohibitions and restrictions"
],
"human_readable": "First-Class Package International Service\u00ae",
"human_readable": "First-Class Package International Service®",
"max_weight": 64.0,
"name": "FirstClassPackageInternationalService"
},
Expand All @@ -287,7 +287,7 @@
"dimensions": [
"Combined Length and Girth < 108in"
],
"human_readable": "Priority Mail International\u00ae",
"human_readable": "Priority Mail International®",
"max_weight": 1120.0,
"name": "PriorityMailInternational"
},
Expand All @@ -297,11 +297,12 @@
"dimensions": [
"Combined Length and Girth < 108in"
],
"human_readable": "Priority Mail Express International\u00ae",
"human_readable": "Priority Mail Express International®",
"max_weight": 1120.0,
"name": "ExpressMailInternational"
}
]
],
"type": "UspsAccount"
}
]
}
Loading