Skip to content
Closed
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
37 changes: 37 additions & 0 deletions fern/products/openapi-def/pages/extensions/parameter-names.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,40 @@ paths:
type: string
required: false
```

## SDK Variables

You can define variables that can be passed into the SDK constructor and automatically injected into API paths. This is useful for parameters that are common across many endpoints.

```yaml
x-fern-sdk-variables:
project_id:
type: string
description: "The ID of the project"
pattern: "^proj_[a-zA-Z0-9]+$"
```

The variable will be available as a constructor parameter and automatically injected into paths that include it:

```yaml
paths:
"/v1/connect/{project_id}/accounts":
parameters:
- name: project_id
in: path
required: true
schema:
type: string
pattern: "^proj_[a-zA-Z0-9]+$"
```

Now instead of passing `project_id` to every endpoint method, you can provide it once when initializing the SDK client:

```typescript
const client = new Client({
projectId: "proj_123"
});

// project_id will be automatically injected
await client.accounts.list();
```
128 changes: 128 additions & 0 deletions fern/products/openapi-definition/pages/extensions/others.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# OpenAPI Extensions

This page lists all supported OpenAPI extensions in Fern.

## x-fern-sdk-variables

Use this extension to define variables that can be injected into path parameters, query parameters, and headers when making requests through SDKs. This allows you to set values once when instantiating the SDK client rather than passing them in every request.

```yaml
components:
x-fern-sdk-variables:
project_id:
type: string
description: The project ID to use for all requests
pattern: ^proj_[a-zA-Z0-9]+$
```

## x-fern-sdk-method-name

Override the generated SDK method name for an operation:

```yaml
/users:
get:
x-fern-sdk-method-name: listAllUsers
```

## x-fern-sdk-group-name

Group related operations together in the generated SDK:

```yaml
/users:
get:
x-fern-sdk-group-name: users
```

## x-fern-parameter-name

Override the name of path parameters, query parameters or headers in generated SDKs:

```yaml
parameters:
- name: project-id
in: path
x-fern-parameter-name: projectId
```

## x-fern-audiences

Filter endpoints and schemas to specific audiences:

```yaml
/admin:
x-fern-audiences:
- admin
```

## x-fern-auth-override

Override authentication requirements for specific endpoints:

```yaml
/public:
x-fern-auth-override: none
```

## x-fern-enum-name

Set a custom name for an enum type:

```yaml
type: string
enum: [ACTIVE, INACTIVE]
x-fern-enum-name: UserStatus
```

## x-fern-enum-description

Add descriptions for enum values:

```yaml
type: string
enum: [ACTIVE, INACTIVE]
x-fern-enum-description:
ACTIVE: User account is active
INACTIVE: User account is disabled
```

## x-fern-webhook

Mark an endpoint as a webhook that your API will call:

```yaml
/webhooks/user-created:
post:
x-fern-webhook: true
```

## x-fern-streaming

Mark an endpoint as streaming:

```yaml
/events:
get:
x-fern-streaming: true
```

## x-fern-global-headers

Define headers that should be included on every request:

```yaml
x-fern-global-headers:
- name: X-API-Key
type: string
```

## x-fern-idempotency-header

Configure idempotency headers:

```yaml
x-fern-idempotency-header:
name: Idempotency-Key
generator: uuid
```
25 changes: 24 additions & 1 deletion fern/products/sdks/overview/python/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ groups:
version: 0.7.1
config:
client:
class_name: "YourClient"
class_name: "YourClient"
```

## SDK Configuration Options
Expand All @@ -25,6 +25,29 @@ groups:
<ParamField path="client" type="ClientConfiguration" default="ClientConfiguration()" required={false} toc={true}>
</ParamField>

<ParamField path="client.class_name" type="string" required={false} toc={true}>
The name of the generated client class.
</ParamField>

<ParamField path="client.environment_variable_prefix" type="string" required={false} toc={true}>
Prefix to use for environment variables used in configuration.
</ParamField>

<ParamField path="client.sdk_variables" type="object" required={false} toc={true}>
Configure client-level variables that will be available across all requests. The variable value can be provided at instantiation time or via environment variables.

Example:
```yaml
config:
client:
sdk_variables:
project_id:
name: PROJECT_ID
type: string
description: "The project ID"
```
</ParamField>

<ParamField path="default_bytes_stream_chunk_size" type="number" default="null" required={false} toc={true}>
The chunk size to use (if any) when processing a response bytes stream within `iter_bytes` or `aiter_bytes` results in: `for chunk in response.iter_bytes(chunk_size=<default_bytes_stream_chunk_size>):`
</ParamField>
Expand Down
156 changes: 33 additions & 123 deletions fern/products/sdks/overview/typescript/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ Specify extra peer dependencies meta fields in the generated `package.json`:
```yaml
# generators.yml
config:
extraPeerDependencies:
react: ">=16.8.0 <19.0.0"
"react-dom": ">=16.8.0 <19.0.0"
extraPeerDependenciesMeta:
react:
optional: true
```
</ParamField>

Expand Down Expand Up @@ -257,6 +257,35 @@ await service.getFoo({ pathParamName: "pathParamValue", id: "SOME_ID" });

</ParamField>

<ParamField path="injectServicePathAsParameterOverride" type="boolean" default="false" toc={true}>
When enabled, path parameters can be set globally via the client constructor.

For example, with this extension header defined:

```yaml {4-5}
x-fern-sdk-variables:
project_id:
type: string
description: Project ID
pattern: "^proj_[a-zA-Z0-9]+$"
```

And paths in the API spec containing {project_id}:
```yaml
/v1/connect/{project_id}/accounts:
get:
...
```

You can pass project_id once in the constructor:

```typescript
const client = new MyApiClient({
projectId: "proj_123"
});
```
</ParamField>

<ParamField path="namespaceExport" type="string" toc={true}>
By default, names are based on the organization and API names in the Fern Definition:

Expand Down Expand Up @@ -422,123 +451,4 @@ Fern Definition).

If `skipResponseValidation` is set to `true`, the client will never throw if the response is misshapen. Instead, the client will log the issue using `console.warn` and return the data (casted to the expected response type).

<Warning>Response validation only occurs when the Serde layer is enabled (`noSerdeLayer: false`). The Serde layer is disabled by default (`noSerdeLayer: true`).</Warning>

</ParamField>

<ParamField path="streamType" type="'wrapper' | 'web'" toc={true}>
Change the type of stream that is used in the generated SDK.

* `wrapper`: The streams use a wrapper with multiple underlying implementations to support versions of Node.js before Node.js 18.
* `web`: The streams use the web standard `ReadableStream`.

The default is `web`.
</ParamField>

<ParamField path="treatUnknownAsAny" type="boolean" default="false" toc={true}>
When `treatUnknownAsAny` is enabled, [unknown types from Fern are generated into TypeScript using `any` instead of the `unknown` type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-0.html#new-unknown-top-type).
</ParamField>

<ParamField path="useBigInt" type="boolean" default="false" toc={true}>
When `useBigInt` is set to `true`, a customized JSON serializer & deserializer is used that will preserve the precision of `bigint`'s, as opposed to the native `JSON.stringify` and `JSON.parse` function which converts `bigint`'s to number's losing precision.

When combining `useBigInt` with our serialization layer (`no-serde: false`), both the request and response properties that are marked as `long` and `bigint` in OpenAPI/Fern spec, will consistently be `bigint`'s.
However, when disabling the serialization layer (`no-serde: true`), they will be typed as `number | bigint`.

Here's an overview of what to expect from the generated types when combining `useBigInt` and `noSerde` with the following Fern definition:

*Fern definition*:

```yaml
types:
ObjectWithOptionalField:
properties:
longProp: long
bigIntProp: bigint
```

*TypeScript output*:

```typescript
// useBigInt: true
// noSerde: false
interface ObjectWithLongAndBigInt {
longProp: bigint;
bigIntProp: bigint;
}

// useBigInt: true
// noSerde: true
interface ObjectWithLongAndBigInt {
longProp: bigint | number;
bigIntProp: bigint | number;
}

// useBigInt: false
// noSerde: false
interface ObjectWithLongAndBigInt {
longProp: number;
bigIntProp: string;
}

// useBigInt: false
// noSerde: true
interface ObjectWithLongAndBigInt {
longProp: number;
bigIntProp: string;
}
```
</ParamField>

<ParamField path="useBrandedStringAliases" type="boolean" default="false" toc={true}>

When `useBrandedStringAliases` is disabled (the default), string aliases are generated as
normal TypeScript aliases:

```typescript
// generated code

export type MyString = string;

export type OtherString = string;
```
When `useBrandedStringAliases` is enabled, string aliases are generated as branded strings. This makes each alias feel like its own type and improves compile-time safety.

```yaml
# fern definition

types:
MyString: string
OtherString: string
```

```typescript
// generated code

export type MyString = string & { __MyString: void };
export const MyString = (value: string): MyString => value as MyString;

export type OtherString = string & { __OtherString: void };
export const OtherString = (value: string): OtherString => value as OtherString;
```

```typescript
// consuming the generated type

function printMyString(s: MyString): void {
console.log("MyString: " + s);
}

// doesn't compile, "foo" is not assignable to MyString
printMyString("foo");

const otherString = OtherString("other-string");
// doesn't compile, otherString is not assignable to MyString
printMyString(otherString);

// compiles
const myString = MyString("my-string");
printMyString(myString);
```

</ParamField>
<Warning>Response validation only occurs when the
Loading