Skip to content
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
81 changes: 81 additions & 0 deletions openapi2conv/issue1016_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package openapi2conv

import (
"context"
"encoding/json"
"testing"

"github.com/getkin/kin-openapi/openapi2"
"github.com/stretchr/testify/require"
)

func TestIssue1016(t *testing.T) {
v2 := []byte(`
{
"basePath": "/v2",
"host": "test.example.com",
"info": {
"title": "MyAPI",
"version": "0.1",
"x-info": "info extension"
},
"paths": {
"/foo": {
"get": {
"operationId": "getFoo",
"responses": {
"200": {
"description": "returns all information",
"schema": {
"$ref": "#/definitions/PetDirectory"
}
},
"default": {
"description": "OK"
}
},
"summary": "get foo"
}
}
},
"schemes": [
"http"
],
"swagger": "2.0",
"definitions": {
"Pet": {
"type": "object",
"required": ["petType"],
"properties": {
"petType": {
"type": "string"
},
"name": {
"type": "string"
},
"age": {
"type": "integer"
}
}
},
"PetDirectory":{
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/Pet"
}
}
}
}
`)

var doc2 openapi2.T
err := json.Unmarshal(v2, &doc2)
require.NoError(t, err)

doc3, err := v2v3YAML(v2)
require.NoError(t, err)

err = doc3.Validate(context.Background())
require.NoError(t, err)
require.Equal(t, "#/components/schemas/Pet", doc3.Components.Schemas["PetDirectory"].Value.AdditionalProperties.Schema.Ref)
}
4 changes: 4 additions & 0 deletions openapi2conv/openapi2_conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,10 @@ func ToV3SchemaRef(schema *openapi2.SchemaRef) *openapi3.SchemaRef {
AdditionalProperties: schema.Value.AdditionalProperties,
}

if schema.Value.AdditionalProperties.Schema != nil {
v3Schema.AdditionalProperties.Schema.Ref = ToV3Ref(schema.Value.AdditionalProperties.Schema.Ref)
}

if schema.Value.Discriminator != "" {
v3Schema.Discriminator = &openapi3.Discriminator{
PropertyName: schema.Value.Discriminator,
Expand Down
Loading