Chloe1990
5 months agoNew Member
How to retrieve the content in $ref
My team composed the api spec documentation in a layered structure to prevent the long page.
For example, in global.yaml, we have
openapi: "3.0.3"
info:
tags:
components:
paths:
/api/v1/abc:
$ref: "./controller/abc.yaml#/GetAbc"
in abc.yam, we have
GetAbc:
get:
parameters:
-name: "searchParam"
in : "query"
schema:
example:
$ref: "../xyz.yaml#/Example1"
and the real example of the request is stored in xyz.yaml/Example1
We want to parse from the root node to prevent some paths are not consistent in the yaml files.
The solution we have currently is the follwing
- use File to parse the yaml file,
- Use JsonNode to retrieve the first layer node:
- JsonNode node = rootSpecNode
.at("/paths")
.get("/api/v1/abc)
.get("$ref"); - String secondLayerPath = rootPath +......+ node.toString().replace(...)
Does openApi provide an easier way to parse the api spec yaml file especially for $ref rather than using the above way?