Skip to content

Commit 31a4417

Browse files
committed
Sync open source content 🐝 (from fd76fdc4bed478dc4d812f0cc65f254d4ba0f624)
1 parent 25c8aa4 commit 31a4417

File tree

81 files changed

+629
-646
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+629
-646
lines changed

api-design/developer-experience.mdx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ Stripe offers well-maintained SDKs for major programming languages and framework
2727

2828
For example, here's how to create a payment intent using Stripe's Python SDK compared to making a raw API request:
2929

30-
<div className="md:flex gap-10">
31-
<div className="md:w-1/2">
32-
```python stripe_sdk_example.py
30+
<div className="min-[1660px]:flex gap-6 justify-center [&>div]:min-[1660px]:max-w-[50%]">
31+
<div>
32+
```python filename="stripe_sdk_example.py"
3333
import stripe
3434

3535
stripe.api_key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"
@@ -39,12 +39,10 @@ amount=1000,
3939
currency="usd",
4040
payment_method_types=["card"],
4141
)
42-
43-
````
44-
42+
```
4543
</div>
46-
<div className="md:w-1/2">
47-
```python stripe_api_example.py
44+
<div>
45+
```python filename="stripe_api_example.py"
4846
import requests
4947

5048
url = "https://api.stripe.com/v1/payment_intents"
@@ -58,7 +56,7 @@ data = {
5856
}
5957
response = requests.post(url, headers=headers, data=data)
6058
print(response.json())
61-
````
59+
```
6260

6361
</div>
6462
</div>

api-design/picking-architectures.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Beyond authentication, REST's resource-oriented design provides an intuitive and
4242

4343
For example, you can use the Flask framework in Python to build a RESTful API. Here is how you can define a simple endpoint to fetch a list of products:
4444

45-
```python app.py
45+
```python filename="app.py"
4646
from flask import Flask, jsonify, request
4747

4848
app = Flask(__name__)
@@ -262,7 +262,7 @@ This is what a typical WebSocket architecture looks like.
262262

263263
WebSockets is a great choice for our high-frequency trading application. Let's see how this could be implemented in a Node.js application, using channels to allow users to send orders and receive price changes in real time.
264264

265-
```javascript app.js
265+
```javascript filename="app.js"
266266
import {WebSocketServer} from 'ws';
267267
import Redis from 'ioredis';
268268

api-design/testing.mdx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: "Testing Best Practices in REST API Design"
33
description: "Implement comprehensive API testing strategies to ensure reliability, performance, and backward compatibility throughout development cycles."
44
---
55

6+
import Image from "next/image";
7+
68
# Testing your API
79

810
We write tests to build trust. Trust that our software is reliable, safe, and extendable. When it comes to testing public APIs, robust testing gives users confidence that the API *behaves* as expected. This guide not only covers the *how* of API testing, but also how to project externally the confidence brought by testing.
@@ -17,7 +19,7 @@ But for *public* or third-party-consumed APIs, the *why* extends further. Your t
1719

1820
API testing clashes with the traditional test pyramid - you know, the one that says, "Many unit tests at the bottom, fewer integration tests in the middle, and a few end-to-end tests at the top."
1921

20-
![The test pyramid](/assets/api-design/api-testing/pyramid.svg?.url)
22+
<Image src="/assets/api-design/api-testing/pyramid.svg?.url" alt="The test pyramid" width={1000} height={1000} />
2123

2224
This pyramid is a good model for verifying the implementation details of small units of work, but it's a terrible model for verifying an API's behavior. Unit tests, useful on the server when testing complex logic, don't tell us much about how the API behaves as a whole.
2325

@@ -27,7 +29,7 @@ We need a new model for API tests.
2729

2830
The traditional test pyramid (many unit tests, fewer integration tests, fewest E2E tests) is okay for internal implementation details. But for verifying API *behavior* from a consumer's viewpoint, the emphasis shifts.
2931

30-
![API test pyramid](/assets/api-design/api-testing/api-pyramid.svg?.url)
32+
<Image src="/assets/api-design/api-testing/api-pyramid.svg?.url" alt="The API test pyramid" width={1000} height={1000} />
3133

3234
It's not exactly a pyramid, but you get the idea.
3335

@@ -298,7 +300,7 @@ Here's what belongs in the public domain:
298300

299301
**Authentication flow verification:** Tests that demonstrate how authentication works, covering token acquisition, refresh flows, and error handling.
300302

301-
```python auth_flow_test.py
303+
```python filename="auth_flow_test.py"
302304
def test_invalid_api_key_returns_401():
303305
client = ApiClient(api_key="invalid_key")
304306
response = client.users.list()
@@ -309,7 +311,7 @@ def test_invalid_api_key_returns_401():
309311

310312
**Rate limit behavior tests:** Tests that verify how your API behaves when rate limits are approached or exceeded.
311313

312-
```python rate_limit_test.py
314+
```python filename="rate_limit_test.py"
313315
def test_rate_limit_headers_present():
314316
response = client.resources.list()
315317
assert "X-RateLimit-Limit" in response.headers
@@ -319,7 +321,7 @@ def test_rate_limit_headers_present():
319321

320322
**Error condition handling:** Tests that demonstrate how your API responds to different error states, such as invalid inputs, missing resources, and service errors.
321323

322-
```python error_handling_test.py
324+
```python filename="error_handling_test.py"
323325
def test_resource_not_found():
324326
response = client.products.get(id="nonexistent")
325327
assert response.status_code == 404
@@ -329,7 +331,7 @@ def test_resource_not_found():
329331

330332
**State transition tests:** Tests that verify how resources change state between API operations.
331333

332-
```python order_transition_test.py
334+
```python filename="order_transition_test.py"
333335
def test_order_transition_from_pending_to_processing():
334336
# Create order
335337
order = client.orders.create({"items": [{"product_id": "123", "quantity": 1}]})
@@ -345,7 +347,7 @@ def test_order_transition_from_pending_to_processing():
345347

346348
**Complex business logic validation:** Tests that verify domain-specific rules and constraints.
347349

348-
```python discount_test.py
350+
```python filename="discount_test.py"
349351
def test_discount_applied_only_to_eligible_items():
350352
# Create cart with mixed eligible and non-eligible items
351353
cart = client.carts.create({

docs/create-terraform.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ Speakeasy helps you autogenerate documentation using the HashiCorp `terraform-pl
8989

9090
The Swagger Petstore generates a usage snippet for the pet resource similar to the following:
9191

92-
```go "petstore_pet" "my_pet" {
92+
```go
93+
"petstore_pet" "my_pet" {
9394
id = 10
9495
name = "doggie"
9596
photo_urls = [
@@ -158,7 +159,7 @@ Speakeasy natively supports the direct import of resources with multiple ID fiel
158159

159160
An import block allows you to import a resource into the Terraform state by generating the corresponding Terraform configuration. Using a composite key, the import block will look like this:
160161

161-
```hcl test.tf
162+
```hcl filename="test.tf"
162163
import {
163164
id = jsonencode({
164165
primary_key_one: "9cedad30-2a8a-40f7-9d65-4fabb04e54ff"

docs/customize/code/code-regions/java.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description: "Learn how to use custom code regions in Java SDKs."
88
To enable custom code regions for Java SDKs, update the project's
99
`.speakeasy/gen.yaml` file as follows:
1010

11-
```diff .speakeasy/gen.yaml
11+
```diff filename=".speakeasy/gen.yaml"
1212
configVersion: 2.0.0
1313
generation:
1414
# ...
@@ -51,7 +51,7 @@ Java model classes can also have custom code regions:
5151

5252
When adding custom code that requires external packages, configure these dependencies in the `.speakeasy/gen.yaml` file to prevent them from being removed during SDK regeneration. Use the `additionalDependencies` configuration to specify package dependencies:
5353

54-
```yaml .speakeasy/gen.yaml
54+
```yaml filename=".speakeasy/gen.yaml"
5555
java:
5656
additionalDependencies:
5757
- implementation:org.commonmark:commonmark:0.21.0
@@ -62,7 +62,7 @@ java:
6262
6363
This ensures that dependencies persist across SDK regenerations and are properly included in the generated `build.gradle`.
6464

65-
```java src/main/java/com/example/sdk/Todos.java
65+
```java filename="src/main/java/com/example/sdk/Todos.java"
6666
/*
6767
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
6868
*/
@@ -115,7 +115,7 @@ public class Todos implements
115115

116116
You can also add custom methods to model classes. This example adds a `render()` method to a `Todo` model class:
117117

118-
```java src/main/java/com/example/sdk/models/components/Todo.java
118+
```java filename="src/main/java/com/example/sdk/models/components/Todo.java"
119119
/*
120120
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
121121
*/

docs/customize/code/code-regions/python.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description: "Learn how to use custom code regions in Python SDKs."
88
To enable custom code regions for Python SDKs, update the project's
99
`.speakeasy/gen.yaml` file as follows:
1010

11-
```diff .speakeasy/gen.yaml
11+
```diff filename=".speakeasy/gen.yaml"
1212
configVersion: 2.0.0
1313
generation:
1414
# ...
@@ -40,7 +40,7 @@ Python SDK classes can have two code regions:
4040

4141
When adding custom code that requires external packages, configure these dependencies in the `.speakeasy/gen.yaml` file to prevent them from being removed during SDK regeneration. Use the `additionalDependencies` configuration to specify package dependencies:
4242

43-
```yaml .speakeasy/gen.yaml
43+
```yaml filename=".speakeasy/gen.yaml"
4444
python:
4545
additionalDependencies:
4646
main:
@@ -53,7 +53,7 @@ python:
5353
5454
This ensures that dependencies persist across SDK regenerations and are properly included in the generated `pyproject.toml`.
5555

56-
```python src/todos_sdk/todos.py
56+
```python filename="src/todos_sdk/todos.py"
5757
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
5858
5959
from .basesdk import BaseSDK

docs/customize/code/code-regions/typescript.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description: "Learn how to use custom code regions in TypeScript SDKs."
88
To enable custom code regions for TypeScript SDKs, update the project's
99
`.speakeasy/gen.yaml` file as follows:
1010

11-
```diff .speakeasy/gen.yaml
11+
```diff filename=".speakeasy/gen.yaml"
1212
configVersion: 2.0.0
1313
generation:
1414
# ...
@@ -40,7 +40,7 @@ TypeScript SDK classes can have two code regions:
4040

4141
When adding custom code that requires external packages, configure these dependencies in the `.speakeasy/gen.yaml` file to prevent them from being removed during SDK regeneration. Use the `additionalDependencies` configuration to specify package dependencies:
4242

43-
```yaml .speakeasy/gen.yaml
43+
```yaml filename=".speakeasy/gen.yaml"
4444
typescript:
4545
additionalDependencies:
4646
dependencies:
@@ -54,7 +54,7 @@ typescript:
5454
5555
This ensures that dependencies persist across SDK regenerations and are properly included in the generated `package.json`.
5656

57-
```typescript src/sdk/todos.ts
57+
```typescript filename="src/sdk/todos.ts"
5858
/*
5959
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
6060
*/

docs/customize/data-model/additionalproperties.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Speakeasy sets `additionalProperties` to `false` by default unless explicitly de
1919

2020
Set `additionalProperties: true` to accept arbitrary fields beyond the defined properties. This is useful for accepting unpredictable fields or allowing future extensions without schema updates.
2121

22-
```yaml openapi.yaml
22+
```yaml filename="openapi.yaml"
2323
components:
2424
schemas:
2525
FlexibleObject:
@@ -58,7 +58,7 @@ await sdk.items.create({
5858

5959
Constrain additional properties to a specific type:
6060

61-
```yaml openapi.yaml
61+
```yaml filename="openapi.yaml"
6262
components:
6363
schemas:
6464
StringOnlyObject:

docs/customize/structure/imports.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ You can customize these paths to any path that exists relative to the root of th
179179

180180
Different buckets can also be configured to use the same path, for example:
181181

182-
```yaml gen.yaml
182+
```yaml filename="gen.yaml"
183183
typescript:
184184
...
185185
imports:

docs/customize/structure/namespaces.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Each method will then be added to namespaces corresponding with its `tags`. If a
1818

1919
The following example illustrates the method `sdk.Drinks.ListDrinks()` assigned to the `Drinks` namespace and another method `sdk.ListLocations()` kept in the default class:
2020

21-
```yaml Tags
21+
```yaml filename="Tags"
2222
paths:
2323
/bar_locations:
2424
get:
@@ -70,7 +70,7 @@ Sometimes the `tags` in an OpenAPI spec may already be used for an unrelated pur
7070

7171
The `x-speakeasy-group` field allows defining custom namespaces. Add this field to any operation in the OpenAPI spec to override any `tags` associated with that method. For example:
7272

73-
```yaml x-speakeasy-group
73+
```yaml filename="x-speakeasy-group"
7474
paths:
7575
/drinks/{drink_type}/get_vintage:
7676
get:

0 commit comments

Comments
 (0)