@@ -65,6 +65,134 @@ func TestConvOpenAPIV2ToV3(t *testing.T) {
65
65
require .JSONEq (t , exampleV3 , string (data ))
66
66
}
67
67
68
+ func TestConvOpenAPIV2ToV3WithAdditionalPropertiesSchemaRef (t * testing.T ) {
69
+ v2 := []byte (`
70
+ {
71
+ "basePath": "/v2",
72
+ "host": "test.example.com",
73
+ "info": {
74
+ "title": "MyAPI",
75
+ "version": "0.1"
76
+ },
77
+ "paths": {
78
+ "/foo": {
79
+ "get": {
80
+ "operationId": "getFoo",
81
+ "produces": [
82
+ "application/json"
83
+ ],
84
+ "responses": {
85
+ "200": {
86
+ "description": "returns all information",
87
+ "schema":{
88
+ "type":"object",
89
+ "additionalProperties":{
90
+ "$ref":"#/definitions/Foo"
91
+ }
92
+ }
93
+ }
94
+ },
95
+ "summary": "get foo"
96
+ }
97
+ }
98
+ },
99
+ "definitions": {
100
+ "Foo": {
101
+ "type": "object",
102
+ "properties": {
103
+ "a": {
104
+ "type": "string"
105
+ }
106
+ }
107
+ }
108
+ },
109
+ "schemes": [
110
+ "http"
111
+ ],
112
+ "swagger": "2.0"
113
+ }
114
+ ` )
115
+
116
+ var doc2 openapi2.T
117
+ err := json .Unmarshal (v2 , & doc2 )
118
+ require .NoError (t , err )
119
+
120
+ doc3 , err := ToV3 (& doc2 )
121
+ require .NoError (t , err )
122
+ err = doc3 .Validate (context .Background ())
123
+ require .NoError (t , err )
124
+
125
+ responseSchema := doc3 .Paths .Value ("/foo" ).Get .Responses .Value ("200" ).Value .Content .Get ("application/json" ).Schema .Value
126
+ require .Equal (t , & openapi3.Types {"object" }, responseSchema .Type )
127
+ require .Equal (t , "#/components/schemas/Foo" , responseSchema .AdditionalProperties .Schema .Ref )
128
+ }
129
+
130
+ func TestConvOpenAPIV2ToV3WithNestedAdditionalPropertiesSchemaRef (t * testing.T ) {
131
+ v2 := []byte (`
132
+ {
133
+ "basePath": "/v2",
134
+ "host": "test.example.com",
135
+ "info": {
136
+ "title": "MyAPI",
137
+ "version": "0.1"
138
+ },
139
+ "paths": {
140
+ "/foo": {
141
+ "get": {
142
+ "operationId": "getFoo",
143
+ "produces": [
144
+ "application/json"
145
+ ],
146
+ "responses": {
147
+ "200": {
148
+ "description": "returns all information",
149
+ "schema":{
150
+ "type":"object",
151
+ "additionalProperties":{
152
+ "type":"object",
153
+ "additionalProperties":{
154
+ "$ref":"#/definitions/Foo"
155
+ }
156
+ }
157
+ }
158
+ }
159
+ },
160
+ "summary": "get foo"
161
+ }
162
+ }
163
+ },
164
+ "definitions": {
165
+ "Foo": {
166
+ "type": "object",
167
+ "properties": {
168
+ "a": {
169
+ "type": "string"
170
+ }
171
+ }
172
+ }
173
+ },
174
+ "schemes": [
175
+ "http"
176
+ ],
177
+ "swagger": "2.0"
178
+ }
179
+ ` )
180
+
181
+ var doc2 openapi2.T
182
+ err := json .Unmarshal (v2 , & doc2 )
183
+ require .NoError (t , err )
184
+
185
+ doc3 , err := ToV3 (& doc2 )
186
+ require .NoError (t , err )
187
+ err = doc3 .Validate (context .Background ())
188
+ require .NoError (t , err )
189
+
190
+ responseSchema := doc3 .Paths .Value ("/foo" ).Get .Responses .Value ("200" ).Value .Content .Get ("application/json" ).Schema .Value
191
+ require .Equal (t , & openapi3.Types {"object" }, responseSchema .Type )
192
+ require .Equal (t , & openapi3.Types {"object" }, responseSchema .AdditionalProperties .Schema .Value .Type )
193
+ require .Equal (t , "#/components/schemas/Foo" , responseSchema .AdditionalProperties .Schema .Value .AdditionalProperties .Schema .Ref )
194
+ }
195
+
68
196
const exampleV2 = `
69
197
{
70
198
"basePath": "/v2",
0 commit comments