Skip to content
This repository was archived by the owner on Mar 16, 2025. It is now read-only.

Commit 65b36bb

Browse files
committed
fixed missing pojos, #67
1 parent 0874eec commit 65b36bb

File tree

3 files changed

+80
-3
lines changed

3 files changed

+80
-3
lines changed

src/main/kotlin/io/openapiprocessor/core/converter/ApiConverter.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class ApiConverter(
134134
resolver)
135135

136136
if (contentType.startsWith(MULTIPART)) {
137-
ep.parameters.addAll (createMultipartParameter(info, mediaType.encodings))
137+
ep.parameters.addAll (createMultipartParameter(info, mediaType.encodings, dataTypes))
138138
} else {
139139
ep.requestBodies.add (createRequestBody (contentType, info, requestBody.getRequired(), dataTypes))
140140
}
@@ -243,12 +243,14 @@ class ApiConverter(
243243
return framework.createRequestBody(contentType, required, changedType)
244244
}
245245

246-
private fun createMultipartParameter(info: SchemaInfo, encodings: Map<String, Encoding>): Collection<ModelParameter> {
247-
val dataType = convertDataType(info, DataTypes())
246+
private fun createMultipartParameter(info: SchemaInfo, encodings: Map<String, Encoding>,
247+
dataTypes: DataTypes): Collection<ModelParameter> {
248+
val dataType = convertDataType(info, dataTypes)
248249
if (dataType !is ObjectDataType) {
249250
throw MultipartResponseBodyException(info.getPath())
250251
}
251252

253+
dataTypes.del(dataType)
252254
val parameters = mutableListOf<ModelParameter>()
253255
dataType.forEach { property, propertyDataType ->
254256
val mpp = MultipartParameter(property, encodings[property]?.contentType)

src/main/kotlin/io/openapiprocessor/core/model/DataTypes.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ class DataTypes {
8181
dataTypeInfos[name] = DataTypeInfo(dataType)
8282
}
8383

84+
/**
85+
* remove a data type.
86+
*
87+
* @param dataType the source data type
88+
*/
89+
fun del(dataType: DataType) {
90+
dataTypeInfos.remove (dataType.getName())
91+
}
92+
8493
/**
8594
* find data type by name.
8695
*

src/test/groovy/com/github/hauner/openapi/core/converter/ApiConverterRequestBodySpec.groovy

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,70 @@ paths:
266266
json.dataType.imports == ['pkg.model.MultipartPostRequestBodyJson'] as Set
267267
}
268268

269+
void "add refs request body multipart/* objects" () {
270+
def openApi = parse (
271+
"""\
272+
openapi: 3.0.2
273+
info:
274+
title: params-request-body-multipart
275+
version: 1.0.0
276+
277+
paths:
278+
/multipart:
279+
post:
280+
requestBody:
281+
required: true
282+
content:
283+
multipart/form-data:
284+
schema:
285+
type: object
286+
properties:
287+
file:
288+
type: string
289+
format: binary
290+
json:
291+
type: object
292+
properties:
293+
foo:
294+
\$ref: '#/components/schemas/Foo'
295+
bar:
296+
type: string
297+
encoding:
298+
file:
299+
contentType: application/octet-stream
300+
json:
301+
contentType: application/json
302+
responses:
303+
'204':
304+
description: empty
305+
306+
components:
307+
schemas:
308+
Foo:
309+
type: object
310+
properties:
311+
foo:
312+
type: string
313+
""", ParserType.OPENAPI4J
314+
)
315+
316+
def options = new ApiOptions(packageName: 'pkg', typeMappings: [
317+
new EndpointTypeMapping('/multipart', null, [
318+
new TypeMapping (
319+
'string',
320+
'binary',
321+
'multipart.Multipart')
322+
])
323+
])
324+
325+
when:
326+
def api = new ApiConverter (options, new FrameworkBase())
327+
.convert (openApi)
328+
329+
then:
330+
def dts = api.dataTypes
331+
dts.find ("Foo")
332+
dts.find ("MultipartPostRequestBodyJson")
333+
dts.find ("MultipartPostRequestBody") == null
334+
}
269335
}

0 commit comments

Comments
 (0)