Hi! I'm trying to split my OpenAPI spec across multiple files, and I'm not entirely sure whether what I'm doing should or shouldn't be supported.
Here's my testcase:
# main.yaml
openapi: "3.0.0"
info:
title: "test file"
version: "n/a"
paths:
/testpath:
$ref: "testpath.yaml#/paths/~1testpath"
# testpath.yaml
paths:
/testpath:
get:
responses:
"200":
$ref: "#/components/responses/testpath_200_response"
components:
responses:
testpath_200_response:
description: a custom response
content:
application/json:
schema:
type: string
main.yaml is the root of the spec. The definition of the /testpath path is in testpath.yaml, and it refers to a named response in that same file.
Here's a small test driver that parses the spec and prints it out in JSON:
package main
import (
"fmt"
"github.com/getkin/kin-openapi/openapi3"
)
func main() {
sl := openapi3.NewSwaggerLoader()
sl.IsExternalRefsAllowed = true
s, err := sl.LoadSwaggerFromFile("main.yaml")
if err != nil {
panic(err)
}
bs, err := s.MarshalJSON()
if err != nil {
panic(err)
}
fmt.Printf("%s\n", bs)
}
When I run it, I get the following:
$ go run main.go | jq
{
"components": {},
"info": {
"title": "test file",
"version": "n/a"
},
"openapi": "3.0.0",
"paths": {
"/testpath": {
"get": {
"responses": {
"200": {
"$ref": "#/components/responses/testpath_200_response"
}
}
}
}
}
}
The reference to testpath_200_response does not have testpath.yaml at the front, so it seems to be referring to a component in the same document, but components is empty in this doc. I think the path where the reference originated is getting lost along the way.
The language in the OpenAPI spec is fairly dense, so I'm not 100% sure whether I'm doing this right. That being said, swagger-cli validate main.yaml says that it's valid, and using Swagger UI on main.yaml follows the reference to the response type.
Thanks for reading this far, and thanks for all the work you've done on this project. 😃
Hi! I'm trying to split my OpenAPI spec across multiple files, and I'm not entirely sure whether what I'm doing should or shouldn't be supported.
Here's my testcase:
main.yamlis the root of the spec. The definition of the/testpathpath is intestpath.yaml, and it refers to a named response in that same file.Here's a small test driver that parses the spec and prints it out in JSON:
When I run it, I get the following:
The reference to
testpath_200_responsedoes not havetestpath.yamlat the front, so it seems to be referring to a component in the same document, butcomponentsis empty in this doc. I think the path where the reference originated is getting lost along the way.The language in the OpenAPI spec is fairly dense, so I'm not 100% sure whether I'm doing this right. That being said,
swagger-cli validate main.yamlsays that it's valid, and using Swagger UI onmain.yamlfollows the reference to the response type.Thanks for reading this far, and thanks for all the work you've done on this project. 😃