Skip to content

Commit

Permalink
reproduce failing to load JSON refs in non-openapi document (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
fenollp authored Apr 23, 2021
1 parent 751a395 commit 61b5dd9
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
20 changes: 20 additions & 0 deletions openapi3/swagger_loader_outside_refs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package openapi3

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestLoadOutsideRefs(t *testing.T) {
loader := NewSwaggerLoader()
loader.IsExternalRefsAllowed = true
doc, err := loader.LoadSwaggerFromFile("testdata/303bis/service.yaml")
require.NoError(t, err)
require.NotNil(t, doc)

err = doc.Validate(loader.Context)
require.NoError(t, err)

require.Equal(t, "string", doc.Paths["/service"].Get.Responses["200"].Value.Content["application/json"].Schema.Value.Items.Value.AllOf[0].Value.Properties["created_at"].Value.Type)
}
16 changes: 16 additions & 0 deletions openapi3/testdata/303bis/common/properties.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
timestamp:
type: string
description: Date and time in ISO 8601 format.
example: "2020-04-09T18:14:30Z"
readOnly: true
nullable: true

timestamps:
type: object
properties:
created_at:
$ref: "#/timestamp"
deleted_at:
$ref: "#/timestamp"
updated_at:
$ref: "#/timestamp"
28 changes: 28 additions & 0 deletions openapi3/testdata/303bis/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
openapi: 3.0.0
info:
title: 'some service spec'
version: 1.2.3

paths:
/service:
get:
tags:
- services/service
summary: List services
description: List services.
operationId: list-services
responses:
"200":
description: OK
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/model_service"

components:
schemas:
model_service:
allOf:
- $ref: "common/properties.yaml#/timestamps"

0 comments on commit 61b5dd9

Please sign in to comment.