9
9
import io .swagger .v3 .oas .models .media .MediaType ;
10
10
import io .swagger .v3 .oas .models .media .ObjectSchema ;
11
11
import io .swagger .v3 .oas .models .media .Schema ;
12
+ import io .swagger .v3 .oas .models .media .StringSchema ;
12
13
import io .swagger .v3 .oas .models .media .XML ;
13
14
import io .swagger .v3 .oas .models .parameters .Parameter ;
14
15
import io .swagger .v3 .oas .models .parameters .RequestBody ;
@@ -82,14 +83,13 @@ public void flatten(OpenAPI openAPI) {
82
83
if (inner .getProperties () != null && inner .getProperties ().size () > 0 ) {
83
84
flattenProperties (inner .getProperties (), pathname );
84
85
String modelName = resolveModelName (inner .getTitle (), "body" );
85
- Schema innerModel = createModelFromProperty (inner , modelName );
86
- String existing = matchGenerated (innerModel );
86
+ String existing = matchGenerated (inner );
87
87
if (existing != null ) {
88
88
am .setItems (new Schema ().$ref (existing ));
89
89
} else {
90
90
am .setItems (new Schema ().$ref (modelName ));
91
- addGenerated (modelName , innerModel );
92
- openAPI .getComponents ().addSchemas (modelName , innerModel );
91
+ addGenerated (modelName , inner );
92
+ openAPI .getComponents ().addSchemas (modelName , inner );
93
93
}
94
94
}
95
95
}
@@ -114,22 +114,25 @@ public void flatten(OpenAPI openAPI) {
114
114
openAPI .getComponents ().addSchemas (modelName , model );
115
115
}
116
116
}
117
- } else if (model instanceof ArraySchema ) {
117
+ }else if (model instanceof ComposedSchema ) {
118
+ String modelName = resolveModelName (model .getTitle (), parameter .getName ());
119
+ parameter .setSchema (new Schema ().$ref (modelName ));
120
+ addGenerated (modelName , model );
121
+ openAPI .getComponents ().addSchemas (modelName , model );
122
+ }else if (model instanceof ArraySchema ) {
118
123
ArraySchema am = (ArraySchema ) model ;
119
124
Schema inner = am .getItems ();
120
-
121
125
if (isObjectSchema (inner )) {
122
126
if (inner .getProperties () != null && inner .getProperties ().size () > 0 ) {
123
127
flattenProperties (inner .getProperties (), pathname );
124
128
String modelName = resolveModelName (inner .getTitle (), parameter .getName ());
125
- Schema innerModel = createModelFromProperty (inner , modelName );
126
- String existing = matchGenerated (innerModel );
129
+ String existing = matchGenerated (inner );
127
130
if (existing != null ) {
128
131
am .setItems (new Schema ().$ref (existing ));
129
132
} else {
130
133
am .setItems (new Schema ().$ref (modelName ));
131
- addGenerated (modelName , innerModel );
132
- openAPI .getComponents ().addSchemas (modelName , innerModel );
134
+ addGenerated (modelName , am );
135
+ openAPI .getComponents ().addSchemas (modelName , am );
133
136
}
134
137
}
135
138
}
@@ -151,17 +154,27 @@ public void flatten(OpenAPI openAPI) {
151
154
if (isObjectSchema (mediaSchema )) {
152
155
if (mediaSchema .getProperties () != null && mediaSchema .getProperties ().size () > 0 ) {
153
156
String modelName = resolveModelName (mediaSchema .getTitle (), "inline_response_" + key );
154
- Schema model = createModelFromProperty (mediaSchema , modelName );
155
- String existing = matchGenerated (model );
157
+ String existing = matchGenerated (mediaSchema );
156
158
if (existing != null ) {
157
159
media .setSchema (this .makeRefProperty (existing , mediaSchema ));
158
160
} else {
159
161
media .setSchema (this .makeRefProperty (modelName , mediaSchema ));
160
- addGenerated (modelName , model );
161
- openAPI .getComponents ().addSchemas (modelName , model );
162
+ addGenerated (modelName , mediaSchema );
163
+ openAPI .getComponents ().addSchemas (modelName , mediaSchema );
162
164
}
163
165
}
164
- } else if (mediaSchema instanceof ArraySchema ) {
166
+ } else if (mediaSchema instanceof ComposedSchema ){
167
+ String modelName = resolveModelName (mediaSchema .getTitle (), "inline_response_" + key );
168
+ String existing = matchGenerated (mediaSchema );
169
+ if (existing != null ) {
170
+ media .setSchema (this .makeRefProperty (existing , mediaSchema ));
171
+ } else {
172
+ media .setSchema (this .makeRefProperty (modelName , mediaSchema ));
173
+ addGenerated (modelName , mediaSchema );
174
+ openAPI .getComponents ().addSchemas (modelName , mediaSchema );
175
+ }
176
+
177
+ }else if (mediaSchema instanceof ArraySchema ) {
165
178
ArraySchema ap = (ArraySchema ) mediaSchema ;
166
179
Schema inner = ap .getItems ();
167
180
@@ -170,14 +183,13 @@ public void flatten(OpenAPI openAPI) {
170
183
flattenProperties (inner .getProperties (), pathname );
171
184
String modelName = resolveModelName (inner .getTitle (),
172
185
"inline_response_" + key );
173
- Schema innerModel = createModelFromProperty (inner , modelName );
174
- String existing = matchGenerated (innerModel );
186
+ String existing = matchGenerated (inner );
175
187
if (existing != null ) {
176
188
ap .setItems (this .makeRefProperty (existing , inner ));
177
189
} else {
178
190
ap .setItems (this .makeRefProperty (modelName , inner ));
179
- addGenerated (modelName , innerModel );
180
- openAPI .getComponents ().addSchemas (modelName , innerModel );
191
+ addGenerated (modelName , inner );
192
+ openAPI .getComponents ().addSchemas (modelName , inner );
181
193
}
182
194
}
183
195
}
@@ -189,14 +201,13 @@ public void flatten(OpenAPI openAPI) {
189
201
flattenProperties (innerProperty .getProperties (), pathname );
190
202
String modelName = resolveModelName (innerProperty .getTitle (),
191
203
"inline_response_" + key );
192
- Schema innerModel = createModelFromProperty (innerProperty , modelName );
193
- String existing = matchGenerated (innerModel );
204
+ String existing = matchGenerated (innerProperty );
194
205
if (existing != null ) {
195
206
mediaSchema .setAdditionalProperties (new Schema ().$ref (existing ));
196
207
} else {
197
208
mediaSchema .setAdditionalProperties (new Schema ().$ref (modelName ));
198
- addGenerated (modelName , innerModel );
199
- openAPI .getComponents ().addSchemas (modelName , innerModel );
209
+ addGenerated (modelName , innerProperty );
210
+ openAPI .getComponents ().addSchemas (modelName , innerProperty );
200
211
}
201
212
}
202
213
}
@@ -226,11 +237,10 @@ public void flatten(OpenAPI openAPI) {
226
237
if (isObjectSchema (inner )) {
227
238
if (inner .getProperties () != null && inner .getProperties ().size () > 0 ) {
228
239
String innerModelName = resolveModelName (inner .getTitle (), modelName + "_inner" );
229
- Schema innerModel = createModelFromProperty (inner , innerModelName );
230
- String existing = matchGenerated (innerModel );
240
+ String existing = matchGenerated (inner );
231
241
if (existing == null ) {
232
- openAPI .getComponents ().addSchemas (innerModelName , innerModel );
233
- addGenerated (innerModelName , innerModel );
242
+ openAPI .getComponents ().addSchemas (innerModelName , inner );
243
+ addGenerated (innerModelName , inner );
234
244
m .setItems (new Schema ().$ref (innerModelName ));
235
245
} else {
236
246
m .setItems (new Schema ().$ref (existing ));
0 commit comments