|
| 1 | +--- |
| 2 | +title: Other OpenAPI Extensions |
| 3 | +description: Additional extensions supported by Fern when generating SDKs from OpenAPI definitions |
| 4 | +--- |
| 5 | + |
| 6 | +# Additional OpenAPI Extensions |
| 7 | + |
| 8 | +## SDK Variables |
| 9 | + |
| 10 | +The `x-fern-sdk-variables` extension allows you to define variables that will be available in the generated SDKs. These variables can be referenced in path parameters and used consistently across your API. |
| 11 | + |
| 12 | +```yaml |
| 13 | +openapi: 3.0.0 |
| 14 | +x-fern-sdk-variables: |
| 15 | + project_id: |
| 16 | + type: string |
| 17 | + description: The ID of the project |
| 18 | + pattern: "^proj_[a-zA-Z0-9]+$" |
| 19 | +``` |
| 20 | +
|
| 21 | +Any path parameter marked with `x-fern-sdk-variable` will be treated as an SDK variable: |
| 22 | + |
| 23 | +```yaml |
| 24 | +paths: |
| 25 | + /v1/projects/{project_id}/widgets: |
| 26 | + parameters: |
| 27 | + - name: project_id |
| 28 | + in: path |
| 29 | + required: true |
| 30 | + schema: |
| 31 | + type: string |
| 32 | + x-fern-sdk-variable: project_id |
| 33 | +``` |
| 34 | + |
| 35 | +The generated SDK will include this variable in the client constructor rather than requiring it for each method call. |
| 36 | + |
| 37 | +## Operation Extensions |
| 38 | + |
| 39 | +### x-fern-sdk-group-name |
| 40 | + |
| 41 | +Groups operations into logical SDK services/namespaces: |
| 42 | + |
| 43 | +```yaml |
| 44 | +/users: |
| 45 | + get: |
| 46 | + x-fern-sdk-group-name: users |
| 47 | +``` |
| 48 | + |
| 49 | +### x-fern-sdk-method-name |
| 50 | + |
| 51 | +Customizes the generated method name: |
| 52 | + |
| 53 | +```yaml |
| 54 | +/users: |
| 55 | + get: |
| 56 | + x-fern-sdk-method-name: list |
| 57 | +``` |
| 58 | + |
| 59 | +### x-fern-sdk-return-value |
| 60 | + |
| 61 | +Specifies which part of the response should be returned: |
| 62 | + |
| 63 | +```yaml |
| 64 | +/users/{id}: |
| 65 | + get: |
| 66 | + x-fern-sdk-return-value: data |
| 67 | +``` |
| 68 | + |
| 69 | +### x-fern-pagination |
| 70 | + |
| 71 | +Configures pagination behavior: |
| 72 | + |
| 73 | +```yaml |
| 74 | +/users: |
| 75 | + get: |
| 76 | + x-fern-pagination: |
| 77 | + cursor: "$request.after" |
| 78 | + next_cursor: "$response.page_info.end_cursor" |
| 79 | + results: "$response.data" |
| 80 | +``` |
| 81 | + |
| 82 | +### x-fern-ignore |
| 83 | + |
| 84 | +Excludes an operation from SDK generation: |
| 85 | + |
| 86 | +```yaml |
| 87 | +/internal/metrics: |
| 88 | + get: |
| 89 | + x-fern-ignore: true |
| 90 | +``` |
| 91 | + |
| 92 | +For additional OpenAPI customization options, refer to the [OpenAPI Configuration](/learn/api-definition/configuration) documentation. |
0 commit comments