Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reproduce failing to load JSON refs in non-openapi document #314

Merged
merged 2 commits into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"