Other extensions
Fern supports different OpenAPI extensions so that you can generate higher-quality SDKs.
API version
You can define your API version scheme, such as a X-API-Version
header. The supported versions and default value are specified like so:
Global headers
At times, your API will leverage certain headers for every endpoint, or the majority of them, we call these “global headers”. For convenience, generated Fern SDKs expose “global headers” to easily be updated on API calls. Take for example an API key, if we declare the API key as a global header, a user will be able to plug theirs in easily:
To configure global headers, Fern will automatically pull out headers that are used in every request, or the majority of requests, and mark them as global.
In order to label additional headers as global, or to alias the names of global headers, you can leverage the x-fern-global-headers
extension:
yields the following client:
Enum descriptions and names
OpenAPI doesn’t natively support adding descriptions to enum values. To do this in Fern you can use the x-fern-enum
extension.
In the example below, we’ve added some descriptions to enum values. These descriptions will propagate into the generated SDK and docs website.
x-fern-enum
also supports a name
field that allows you to customize the name of the enum in code.
This is particularly useful when you have enums that rely on symbolic characters that would otherwise cause
generated code not to compile.
For example, the following OpenAPI
would generate
Schema names
OpenAPI allows you to define inlined schemas that do not have names.
Fern automatically generates names for all the inlined schemas. For example, in this example,
Fern would generate the name CastItem
for the inlined array item schema.
If you want to override the generated name, you can use the extension x-fern-type-name
.
This would replace CastItem
with Person
and the generated code would read more idiomatically:
Property names
The x-fern-property-name
extension allows you to customize the variable name for object
properties.
For example, if you had a property called _metadata
in your schema but you wanted the
variable to be called data
in your SDK you would do the following:
Server names
The x-fern-server-name
extension is used to name your servers.
In a generated TypeScript SDK, you’d see:
Base path
The x-fern-base-path
extension is used to configure the base path prepended to every endpoint.
In the example below, we have configured the /v1
base path so the full endpoint path is
https://api.example.com/v1/users
.
Ignoring schemas or endpoints
If you want Fern to skip reading any endpoints or schemas, use the x-fern-ignore
extension.
To skip an endpoint, add x-fern-ignore: true
at the operation level.
To skip a schema, add x-fern-ignore: true
at the schema level.
Overlaying extensions
Because of the number of tools that use OpenAPI, it may be more convenient to
“overlay” your fern specific OpenAPI extensions onto your original definition.
In order to do this you can specify your overrides file in generators.yml
.
Below is an example of how someone can overlay the extensions x-fern-sdk-method-name
and
x-fern-sdk-group-name
without polluting their original OpenAPI. The combined result is
shown in the third tab.
Embedding extensions
If instead of overlaying your extensions within an overrides file, as mentioned above. Certain frameworks that generate OpenAPI Specifications make it easy to embed extensions directly from code.
FastAPI
Please view our page on FastAPI for more information on how to extend your OpenAPI Specification within FastAPI.
Request + response examples
While OpenAPI has several fields for examples, there is no easy way to associate a request with a response. This is especially useful when you want to show more than one example in your documentation.
x-fern-examples
is an array of examples. Each element of the array
can contain path-parameters
, query-parameters
, request
and response
examples values that are all associated.
Code samples
If you’d like to specify custom code samples for your example, use code-samples
.
If you’re on the Fern Starter plan or higher for SDKs you won’t have to worry about manually adding code samples! Our generators do that for you.
Availability
The x-fern-availability
extension is used to mark the availability of an endpoint. The availability information propagates into the generated Fern Docs website as visual tags.
The options are:
beta
generally-available
deprecated
The example below marks that the POST /pet
endpoint is deprecated
.
This renders as:
Request new extensions
If there’s an extension you want that doesn’t already exist, file an issue to start a discussion about it.