Skip to content

Commit

Permalink
Demonstrate ref in ref example
Browse files Browse the repository at this point in the history
  • Loading branch information
DerkSch committed Feb 23, 2021
1 parent 33fc721 commit 6bd1f85
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
8 changes: 8 additions & 0 deletions openapi3/swagger_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,14 @@ func TestLoadFromRemoteURL(t *testing.T) {
require.Equal(t, "string", swagger.Components.Schemas["TestSchema"].Value.Type)
}

func TestLoadWithReferenceInReference(t *testing.T) {
loader := NewSwaggerLoader()
loader.IsExternalRefsAllowed = true
swagger, err := loader.LoadSwaggerFromFile("testdata/refInRef/openapi.json")
require.NoError(t, err)
require.NotNil(t, swagger)
}

func TestLoadFileWithExternalSchemaRef(t *testing.T) {
loader := NewSwaggerLoader()
loader.IsExternalRefsAllowed = true
Expand Down
7 changes: 7 additions & 0 deletions openapi3/testdata/refInRef/messages/definitions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"definitions": {
"External": {
"type": "string"
}
}
}
11 changes: 11 additions & 0 deletions openapi3/testdata/refInRef/messages/request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"type": "object",
"required": [
"definition_reference"
],
"properties": {
"definition_reference": {
"$ref": "definitions.json#/definitions/External"
}
}
}
9 changes: 9 additions & 0 deletions openapi3/testdata/refInRef/messages/response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uuid"
}
}
}
34 changes: 34 additions & 0 deletions openapi3/testdata/refInRef/openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"openapi": "3.0.3",
"info": {
"title": "Reference in reference example",
"version": "1.0.0"
},
"paths": {
"/api/test/ref/in/ref": {
"post": {
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "messages/request.json"
}
}
}
},
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"schema": {
"$ref": "messages/response.json"
}
}
}
}
}
}
}
}
}

0 comments on commit 6bd1f85

Please sign in to comment.