Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Fenoll <[email protected]>
  • Loading branch information
fenollp committed Mar 2, 2021
1 parent 4c01aae commit 14747be
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
22 changes: 22 additions & 0 deletions openapi3/swagger_loader_outside_refs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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)

props := doc.Paths["/service"].Get.Responses["200"].Value.Content["application/json"].Schema.Value.Items.Value.Properties
require.NotNil(t, props)
require.Equal(t, "string", props["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 14747be

Please sign in to comment.