diff --git a/fern/products/openapi-def/openapi-def.yml b/fern/products/openapi-def/openapi-def.yml index 419d75e5b..a843620a7 100644 --- a/fern/products/openapi-def/openapi-def.yml +++ b/fern/products/openapi-def/openapi-def.yml @@ -4,7 +4,7 @@ navigation: - page: Authentication path: ./pages/auth.mdx - page: Servers - path: ./pages/servers.mdx + path: ./pages/servers.mdx - section: Endpoints slug: endpoints contents: @@ -17,6 +17,9 @@ navigation: - page: Server-Sent Events path: ./pages/endpoints/sse.mdx slug: sse + - page: others + title: Other + path: ./pages/extensions/others.mdx - section: Extensions slug: extensions contents: @@ -38,7 +41,7 @@ navigation: - page: Overlay Customizations path: ./pages/overrides.mdx - page: Sync your OpenAPI Specification - path: ./pages/automation.mdx + path: ./pages/automation.mdx - section: Integrate your Server Framework slug: frameworks contents: diff --git a/fern/products/openapi-definition/pages/extensions/others.mdx b/fern/products/openapi-definition/pages/extensions/others.mdx new file mode 100644 index 000000000..4555bd434 --- /dev/null +++ b/fern/products/openapi-definition/pages/extensions/others.mdx @@ -0,0 +1,77 @@ +--- +title: Other Extensions +description: Documentation for various custom OpenAPI extensions used in Fern +--- + +## X-Fern-SDK-Variables + +The `x-fern-sdk-variables` extension allows you to define variables that can be injected into paths across your OpenAPI spec. This enables cleaner path definitions and avoids repetition. + +### Example Usage + +```yaml +openapi: 3.0.0 +x-fern-sdk-variables: + project_id: + type: string + description: "The project ID" + pattern: "^proj_[a-zA-Z0-9]+$" +paths: + /v1/projects/{project_id}/widgets: + parameters: + - name: project_id + in: path + required: true + schema: + type: string + x-fern-sdk-variable: project_id +``` + +When using a generated SDK, the variable will be set in the client constructor rather than passed to individual methods: + +```typescript +const client = new Client({ + projectId: "proj_123" // Set once in constructor +}); + +// projectId automatically injected into path +await client.widgets.list(); +``` + +### Configuration Options + + + The type of the variable (string, integer, etc) + + + + Description of what the variable represents + + + + Optional regex pattern the variable must match + + +### Parameter Setup + +To use a defined variable in a path parameter: + +1. Define the variable in `x-fern-sdk-variables` +2. Add the path parameter normally in your OpenAPI spec +3. Add `x-fern-sdk-variable: variable_name` to the parameter definition + +### Generated SDK Behavior + +- Variables are passed via the SDK client constructor +- The SDK injects variable values automatically into paths +- Type checking and validation happen at the SDK level +- Error handling for missing/invalid variables is built in + +The SDK will validate the variable values match any defined patterns or constraints before making requests. + +### Best Practices + +- Use consistent variable names across your API spec +- Add clear descriptions for what each variable represents +- Define patterns when variables must match specific formats +- Consider SDK usability when choosing variable names \ No newline at end of file diff --git a/fern/products/sdks/guides/configure-global-headers.mdx b/fern/products/sdks/guides/configure-global-headers.mdx index 53ec1bd15..461becf9f 100644 --- a/fern/products/sdks/guides/configure-global-headers.mdx +++ b/fern/products/sdks/guides/configure-global-headers.mdx @@ -77,8 +77,10 @@ If you'd like to see this feature, please upvote [this issue](https://github.com -Use the `x-fern-global-headers` extension to label additional headers as global -or to alias the names of global headers: +Use one of the following extensions to specify global configuration: + +### x-fern-global-headers +Use this to label additional headers as global or to alias header names: ```yaml title="openapi.yml" x-fern-global-headers: @@ -97,5 +99,56 @@ class Client: def __init__(self, *, apiKey: str, userpoolId: typing.Optional[str]) ``` + +### x-fern-sdk-variables +Use this to specify variables that should be part of the SDK client constructor and injected into paths: + +```yaml title="openapi.yml" +x-fern-sdk-variables: + project_id: + type: string + description: "The ID of the project" + pattern: "^proj_[a-zA-Z0-9]+$" +``` + +This will generate a client that accepts the variable in the constructor and automatically injects it into paths: + +```python +class Client: + def __init__(self, *, project_id: str): + # Variable will be injected into paths like /v1/connect/{project_id}/accounts +``` + - \ No newline at end of file + + +## Supported Extension Fields + +The following extension fields are supported for configuring global headers and variables: + + + Array of header configurations with fields: + - `header`: The original header name + - `name`: Optional alias for the header in the SDK + - `optional`: Whether the header is optional + + + + Object mapping variable names to their configuration: + - `type`: The variable type (string, integer, etc) + - `description`: Description of the variable + - `pattern`: Optional regex pattern for validation + + +## Language Support + +Global configuration support varies by language: + +- TypeScript/JavaScript: Full support for global headers and variables +- Python: Full support as of version 4.24.0+ +- Java: Full support for global headers and variables +- Go: Full support for global headers and variables + + +Make sure you're using the latest generator versions to access all global configuration features. You can update your generator versions in `generators.yml`. + \ No newline at end of file