openapi: 3.0.0
info:title: split test
version: 1.0.0
paths:/pets:get:summary: List all pets
operationId: listPets
tags:- pets
parameters:-name: limit
in: query
description: How many items to return at one time (max 100)
required:falseschema:type: integer
format: int32
responses:'200':description: A paged array of pets
content:application/json:schema:type:"array"items:type: object
required:- id
- name
properties:id:type: integer
format: int64
name:type: string
tag:type: string
/pets/{petId}:get:summary: Info for a specific pet
operationId: showPetById
tags:- pets
parameters:-name: petId
in: path
required:truedescription: The id of the pet to retrieve
schema:type: string
responses:'200':description: Expected response to a valid request
content:application/json:schema:type: object
required:- id
- name
properties:id:type: integer
format: int64
name:type: string
tag:type: string
type: object
required:- id
- name
properties:id:type: integer
format: int64
name:type: string
tag:type: string
あとはこれを ref で参照します
vim openapi.yaml
openapi: 3.0.0
info:title: split test
version: 1.0.0
paths:/pets:get:summary: List all pets
operationId: listPets
tags:- pets
parameters:-name: limit
in: query
description: How many items to return at one time (max 100)
required:falseschema:type: integer
format: int32
responses:'200':description: A paged array of pets
content:application/json:schema:type:"array"items:$ref:"./schemas/pet.yaml"
/pets/{petId}:get:summary: Info for a specific pet
operationId: showPetById
tags:- pets
parameters:-name: petId
in: path
required:truedescription: The id of the pet to retrieve
schema:type: string
responses:'200':description: Expected response to a valid request
content:application/json:schema:$ref:"./schemas/pet.yaml"
name: petId
in: path
required:truedescription: The id of the pet to retrieve
schema:type: string
vim parameters/limit.yaml
name: limit
in: query
description: How many items to return at one time (max 100)
required:falseschema:type: integer
format: int32
あとはそれぞれのファイルをメインのファイルから参照するように変更します
vim openapi.yaml
openapi: 3.0.0
info:title: split test
version: 1.0.0
paths:/pets:get:summary: List all pets
operationId: listPets
tags:- pets
parameters:-$ref:"./parameters/limit.yaml"responses:'200':description: A paged array of pets
content:application/json:schema:type:"array"items:$ref:"./schemas/pet.yaml"
/pets/{petId}:get:summary: Info for a specific pet
operationId: showPetById
tags:- pets
parameters:-$ref:"./parameters/petId.yaml"responses:'200':description: Expected response to a valid request
content:application/json:schema:$ref:"./schemas/pet.yaml"components:parameters:$ref:"./parameters/_index.yaml"