File tree Expand file tree Collapse file tree 2 files changed +85
-0
lines changed Expand file tree Collapse file tree 2 files changed +85
-0
lines changed Original file line number Diff line number Diff line change
1
+ package openapi2conv
2
+
3
+ import (
4
+ "context"
5
+ "encoding/json"
6
+ "testing"
7
+
8
+ "github.com/getkin/kin-openapi/openapi2"
9
+ "github.com/stretchr/testify/require"
10
+ )
11
+
12
+ func TestIssue1016 (t * testing.T ) {
13
+ v2 := []byte (`
14
+ {
15
+ "basePath": "/v2",
16
+ "host": "test.example.com",
17
+ "info": {
18
+ "title": "MyAPI",
19
+ "version": "0.1",
20
+ "x-info": "info extension"
21
+ },
22
+ "paths": {
23
+ "/foo": {
24
+ "get": {
25
+ "operationId": "getFoo",
26
+ "responses": {
27
+ "200": {
28
+ "description": "returns all information",
29
+ "schema": {
30
+ "$ref": "#/definitions/PetDirectory"
31
+ }
32
+ },
33
+ "default": {
34
+ "description": "OK"
35
+ }
36
+ },
37
+ "summary": "get foo"
38
+ }
39
+ }
40
+ },
41
+ "schemes": [
42
+ "http"
43
+ ],
44
+ "swagger": "2.0",
45
+ "definitions": {
46
+ "Pet": {
47
+ "type": "object",
48
+ "required": ["petType"],
49
+ "properties": {
50
+ "petType": {
51
+ "type": "string"
52
+ },
53
+ "name": {
54
+ "type": "string"
55
+ },
56
+ "age": {
57
+ "type": "integer"
58
+ }
59
+ }
60
+ },
61
+ "PetDirectory":{
62
+ "type": "object",
63
+ "additionalProperties": {
64
+ "$ref": "#/definitions/Pet"
65
+ }
66
+ }
67
+ }
68
+ }
69
+ ` )
70
+
71
+ var doc2 openapi2.T
72
+ err := json .Unmarshal (v2 , & doc2 )
73
+ require .NoError (t , err )
74
+
75
+ doc3 , err := v2v3YAML (v2 )
76
+ require .NoError (t , err )
77
+
78
+ err = doc3 .Validate (context .Background ())
79
+ require .NoError (t , err )
80
+ require .Equal (t , "#/components/schemas/Pet" , doc3 .Components .Schemas ["PetDirectory" ].Value .AdditionalProperties .Schema .Ref )
81
+ }
Original file line number Diff line number Diff line change @@ -516,6 +516,10 @@ func ToV3SchemaRef(schema *openapi2.SchemaRef) *openapi3.SchemaRef {
516
516
AdditionalProperties : schema .Value .AdditionalProperties ,
517
517
}
518
518
519
+ if schema .Value .AdditionalProperties .Schema != nil {
520
+ v3Schema .AdditionalProperties .Schema .Ref = ToV3Ref (schema .Value .AdditionalProperties .Schema .Ref )
521
+ }
522
+
519
523
if schema .Value .Discriminator != "" {
520
524
v3Schema .Discriminator = & openapi3.Discriminator {
521
525
PropertyName : schema .Value .Discriminator ,
You can’t perform that action at this time.
0 commit comments