模式名称

以 Markdown 格式查看

OpenAPI 允许您定义没有名称的内联模式。

openapi.yml 中的内联类型
1components:
2 schemas:
3 Movie:
4 type: object
5 properties:
6 name:
7 type: string
8 cast:
9 type: array
10 items:
11 type: object
12 properties:
13 firstName:
14 type: string
15 lastName:
16 type: string
17 age:
18 type: integer

Fern 会自动为所有内联模式生成名称。例如,在这个示例中, Fern 会为内联数组项模式生成名称 CastItem

自动生成的名称
1export interface Movie {
2 name?: string;
3 cast?: CastItem[];
4}
5
6export interface CastItem {
7 firstName?: string;
8 lastName?: string;
9 age?: integer;
10}

如果您想覆盖生成的名称,可以使用扩展 x-fern-type-name

openapi.yml
1components:
2 schemas:
3 Movie:
4 type: object
5 properties:
6 name:
7 type: string
8 cast:
9 type: array
10 items:
11 type: object
12 x-fern-type-name: Person
13 properties:
14 firstName:
15 type: string
16 lastName:
17 type: string
18 age:
19 type: integer

这将用 Person 替换 CastItem,生成的代码将读起来更加自然:

覆盖的名称
1export interface Movie {
2 name?: string;
3 cast?: Person[];
4}
5
6export interface Person {
7 firstName?: string;
8 lastName?: string;
9 age?: integer;
10}