diff --git a/fern/products/openapi-def/openapi-def.yml b/fern/products/openapi-def/openapi-def.yml index 419d75e5b..699bd8659 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: ./others - 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-def/pages/extensions/parameter-names.mdx b/fern/products/openapi-def/pages/extensions/parameter-names.mdx index ff60bf613..8b92732ea 100644 --- a/fern/products/openapi-def/pages/extensions/parameter-names.mdx +++ b/fern/products/openapi-def/pages/extensions/parameter-names.mdx @@ -1,16 +1,19 @@ --- title: Customize parameter names -description: Use `x-fern-parameter-name` to customize query parameter, header and path parameter naming. +description: Use Fern's parameter extensions to customize naming and behavior of parameters in your OpenAPI definition. --- - The `x-fern-parameter-name` extension allows you to customize the variable names of parameters in your generated SDKs. + Fern provides several extensions that let you customize how parameters are handled in your OpenAPI definition and generated SDKs. -## Headers +## x-fern-parameter-name -In the example below, the header `X-API-Version` is renamed to `version` in the -generated SDK. The rename makes the SDK more human readable. +The `x-fern-parameter-name` extension allows you to customize the variable names of parameters in your generated SDKs. + +### Headers + +In the example below, the header `X-API-Version` is renamed to `version` in the generated SDK. The rename makes the SDK more human readable. ```yaml {8} paths: @@ -26,10 +29,9 @@ paths: required: true ``` -## Query parameters +### Query parameters -In the example below, the query parameter `q` is renamed to `search_terms` in the -generated SDK. The rename makes the parameter more approachable for end users. +In the example below, the query parameter `q` is renamed to `search_terms` in the generated SDK. The rename makes the parameter more approachable for end users. ```yaml {8} paths: @@ -45,10 +47,9 @@ paths: required: false ``` -## Path parameters +### Path parameters -In the example below, the path parameter `userId` is renamed to `id` in the -generated SDK. The rename makes the SDK less verbose. +In the example below, the path parameter `userId` is renamed to `id` in the generated SDK. The rename makes the SDK less verbose. ```yaml {8} paths: @@ -63,3 +64,41 @@ paths: type: string required: false ``` + +## x-fern-sdk-variables + +The `x-fern-sdk-variables` extension allows you to define variables that will be injected into paths when making requests. These variables can be provided once during client initialization rather than passing them with every request. + +For example, to automatically inject a project ID into all paths: + +```yaml +components: + x-fern-sdk-variables: + project_id: + type: string + description: "The ID of the project" + pattern: "^proj_[a-zA-Z0-9]+$" + +paths: + "/v1/connect/{project_id}/accounts": + parameters: + - name: project_id + in: path + required: true + schema: + type: string + pattern: "^proj_[a-zA-Z0-9]+$" + x-fern-sdk-variable: project_id +``` + +When using the generated SDK, the `project_id` can be provided once during client initialization: + +```python +client = Client(project_id="proj_123") +``` + +And it will automatically be injected into all paths that reference it. + + + The `x-fern-sdk-variables` extension is currently supported in Python (version 4.24.0+) and TypeScript SDKs. + \ No newline at end of file diff --git a/fern/products/openapi-definition/others b/fern/products/openapi-definition/others new file mode 100644 index 000000000..df4371c06 --- /dev/null +++ b/fern/products/openapi-definition/others @@ -0,0 +1,139 @@ +--- +title: "Other OpenAPI Extensions" +description: "Overview of additional OpenAPI extensions supported by Fern" +--- + +Fern supports several OpenAPI extensions that enable additional functionality beyond the standard OpenAPI specification. + +## x-fern-sdk-variables + +The `x-fern-sdk-variables` extension allows you to define variables that will be passed to the SDK client constructor and injected into API paths automatically. + +```yaml +openapi: 3.0.0 +x-fern-sdk-variables: + project_id: + type: string + description: The project ID to use for API requests + pattern: "^proj_[a-zA-Z0-9]+$" +paths: + /v1/projects/{project_id}/resources: + parameters: + - name: project_id + in: path + required: true + schema: + type: string + x-fern-sdk-variable: project_id +``` + +This allows SDK users to provide the variable once in the client constructor rather than passing it to every method: + +```python +client = Client(project_id="proj_123") +# project_id is automatically injected into paths +client.resources.list() +``` + +## x-fern-include-empty-arrays + +The `x-fern-include-empty-arrays` extension can be added to array properties to ensure they are included in the response even when empty: + +```yaml +components: + schemas: + User: + type: object + properties: + groups: + type: array + items: + type: string + x-fern-include-empty-arrays: true +``` + +## x-fern-sdk-group-name + +The `x-fern-sdk-group-name` extension allows you to organize API operations into logical groups in generated SDKs: + +```yaml +paths: + /users: + get: + x-fern-sdk-group-name: users + operationId: listUsers +``` + +## x-fern-sdk-method-name + +The `x-fern-sdk-method-name` extension lets you customize the method name for an operation in generated SDKs: + +```yaml +paths: + /users: + get: + x-fern-sdk-method-name: list + operationId: listUsers +``` + +## x-fern-sdk-return-value + +The `x-fern-sdk-return-value` extension allows you to specify which part of the response should be returned from SDK methods: + +```yaml +paths: + /users: + get: + x-fern-sdk-return-value: data + responses: + 200: + content: + application/json: + schema: + type: object + properties: + data: + type: array + items: + $ref: '#/components/schemas/User' +``` + +## x-fern-ignore + +The `x-fern-ignore` extension allows you to exclude specific schemas, operations or properties from generated SDKs: + +```yaml +paths: + /internal: + get: + x-fern-ignore: true + operationId: internalOperation +``` + +## x-fern-paginate + +The `x-fern-paginate` extension enables pagination support in generated SDKs: + +```yaml +paths: + /users: + get: + x-fern-paginate: + cursor: "$request.after" + next_cursor: "$response.page_info.end_cursor" + results: "$response.data" +``` + +## x-fern-docs-disable-excerpt + +The `x-fern-docs-disable-excerpt` extension disables excerpt generation for a schema in API documentation: + +```yaml +components: + schemas: + User: + x-fern-docs-disable-excerpt: true + type: object +``` + +For more information on working with OpenAPI extensions in Fern, see our [OpenAPI guide](/learn/openapi-definition/overview). \ No newline at end of file diff --git a/fern/products/sdks/overview/python/configuration.mdx b/fern/products/sdks/overview/python/configuration.mdx index 1c0eb6af7..2f4cea3b9 100644 --- a/fern/products/sdks/overview/python/configuration.mdx +++ b/fern/products/sdks/overview/python/configuration.mdx @@ -21,6 +21,7 @@ groups: ## SDK Configuration Options + Additional exports to include in the package's __init__.py file. @@ -28,6 +29,7 @@ groups: + When true, types won't be exported in the package's __init__.py file. @@ -40,12 +42,15 @@ groups: + Additional development dependencies to include in the generated package. + Optional extras/feature flags for the package. + When true, generates a flatter package structure without nested directories. @@ -53,14 +58,15 @@ groups: - Feature flag that improves imports in the Python SDK by removing nested `resources` directory + Feature flag that improves imports in the Python SDK by removing nested `resources` directory. - Whether or not to include legacy wire tests in the generated SDK + Whether or not to include legacy wire tests in the generated SDK. + When enabled, generates utility functions for working with union types. @@ -72,26 +78,18 @@ groups: - -Specifies the Python package name that users will import your generated client -from. + Specifies the Python package name that users will import your generated client from. -For example, setting `package_name: "my_custom_package"` enables users to use -`my_custom_package import Client` to import your client: + For example, setting `package_name: "my_custom_package"` enables users to use `from my_custom_package import Client` to import your client: -```yaml {7-10} -default-group: local -groups: - local: - generators: - - name: fernapi/fern-python - version: 0.7.1 - config: - package_name: "my_custom_package" -``` + ```yaml + config: + package_name: "my_custom_package" + ``` + Configuration options for Pydantic model generation. @@ -116,8 +114,6 @@ groups: triangle: lambda triangle: do_something_with_triangle(triangle), ) ``` - - When enabled, the python generator will not run Black formatting in the generated code. Black is slow so this can potentially speed up code generation quite a bit. @@ -140,6 +136,7 @@ groups: + Custom pyproject.toml content to include in the generated package. @@ -147,6 +144,7 @@ groups: + When true, skips code formatting of the generated Python code. @@ -154,6 +152,7 @@ groups: + When true, includes the API name in the generated package name. @@ -168,6 +167,20 @@ groups: Whether or not to generate TypedDicts instead of Pydantic Models for file upload request objects. Note that this flag was only introduced due to an oversight in the `use_typeddict_requests` flag implementation; it should be removed in the future. + + Allows defining reusable variables that can be referenced in path parameters and substituted by the SDK. For example: + + ```yaml + x-fern-sdk-variables: + project_id: + type: string + description: "The project ID to use" + pattern: "^proj_[a-zA-Z0-9]+$" + ``` + + When defined in your OpenAPI spec, this will allow the generated SDK to automatically handle path parameter substitution for the variable. + + ### client Configuration for the generated client class and file structure.