Skip to navigation

Schema names

View as Markdown

OpenAPI allows you to define inlined schemas that do not have names.

Inline type in openapi.yml
components:
schemas:
Movie:
type: object
properties:
name:
type: string
cast:
type: array
items:
type: object
properties:
firstName:
type: string
lastName:
type: string
age:
type: integer

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.

Auto-generated name
export interface Movie {
name?: string;
cast?: CastItem[];
}
export interface CastItem {
firstName?: string;
lastName?: string;
age?: integer;
}

If you want to override the generated name, you can use the extension x-fern-type-name.

openapi.yml
components:
schemas:
Movie:
type: object
properties:
name:
type: string
cast:
type: array
items:
type: object
x-fern-type-name: Person
properties:
firstName:
type: string
lastName:
type: string
age:
type: integer

This would replace CastItem with Person and the generated code would read more idiomatically:

Overridden name
export interface Movie {
name?: string;
cast?: Person[];
}
export interface Person {
firstName?: string;
lastName?: string;
age?: integer;
}