Skip to content

Commit 45155fd

Browse files
authored
Merge pull request #1281 from altro3/JaneWardSandy/master
isArray and isIterable should be done after checking customTypeSchema. (5.2.x)
2 parents e1cf6cc + fb71535 commit 45155fd

File tree

6 files changed

+64
-8
lines changed

6 files changed

+64
-8
lines changed

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
projectVersion=.5.2.0
1+
projectVersion=5.2.0
22
projectGroup=io.micronaut.openapi
33
micronautDocsVersion=2.0.0
44
groovyVersion=4.0.15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
micronaut.openapi.schema.io.micronaut.data.model.Page=io.micronaut.openapi.SwaggerPage

openapi/src/main/java/io/micronaut/openapi/visitor/AbstractOpenApiVisitor.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -854,19 +854,19 @@ protected Schema<?> resolveSchema(OpenAPI openAPI, @Nullable Element definingEle
854854

855855
if (type != null) {
856856

857+
String typeName = type.getName();
858+
ClassElement customTypeSchema = getCustomSchema(typeName, typeArgs, context);
859+
if (customTypeSchema != null) {
860+
type = customTypeSchema;
861+
}
862+
857863
if (isArray == null) {
858864
isArray = type.isArray();
859865
}
860866
if (isIterable == null) {
861867
isIterable = type.isIterable();
862868
}
863869

864-
String typeName = type.getName();
865-
ClassElement customTypeSchema = getCustomSchema(typeName, typeArgs, context);
866-
if (customTypeSchema != null) {
867-
type = customTypeSchema;
868-
}
869-
870870
// File upload case
871871
if (isFileUpload(type)) {
872872
isPublisher = isPublisher && !"io.micronaut.http.multipart.PartData".equals(typeName);

openapi/src/main/java/io/micronaut/openapi/visitor/SchemaUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ public static Operation mergeOperations(Operation op1, Operation op2) {
326326
Parameter existedParameter = null;
327327
int i = 0;
328328
for (Parameter p1 : op1.getParameters()) {
329-
if (p1.getName().equals(p2.getName())
329+
if (Objects.equals(p1.getName(), p2.getName())
330330
&& Objects.equals(p1.getIn(), p2.getIn())) {
331331
existedParameter = p1;
332332
break;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.micronaut.openapi;
2+
3+
import java.util.List;
4+
5+
public class SwaggerPage<T> {
6+
7+
public List<T> content;
8+
public int num;
9+
}

openapi/src/test/groovy/io/micronaut/openapi/visitor/OpenapiCustomSchemaSpec.groovy

+46
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,50 @@ class MyBean {}
282282
System.clearProperty(OpenApiConfigProperty.MICRONAUT_CONFIG_FILE_LOCATIONS)
283283
System.clearProperty(Environment.ENVIRONMENTS_PROPERTY)
284284
}
285+
286+
void "test custom OpenAPI schema for iterable class"() {
287+
given:
288+
System.setProperty(OpenApiConfigProperty.MICRONAUT_OPENAPI_CONFIG_FILE, "openapi-custom-schema-for-iterable-class.properties")
289+
290+
when:
291+
buildBeanDefinition('test.MyBean', '''
292+
package test;
293+
294+
import io.micronaut.data.model.Page;
295+
import io.micronaut.http.annotation.Controller;
296+
import io.micronaut.http.annotation.Get;
297+
298+
@Controller
299+
class OpenApiController {
300+
301+
@Get("{?pageable*}")
302+
public Page<String> processSync() {
303+
return null;
304+
}
305+
}
306+
307+
@jakarta.inject.Singleton
308+
class MyBean {}
309+
''')
310+
then:
311+
Utils.testReference != null
312+
313+
when:
314+
OpenAPI openAPI = Utils.testReference
315+
Schema swaggerPageSchema = openAPI.components.schemas.'SwaggerPage_String_'
316+
317+
then:
318+
319+
swaggerPageSchema
320+
swaggerPageSchema.type == 'object'
321+
swaggerPageSchema.properties.content
322+
swaggerPageSchema.properties.content.type == 'array'
323+
swaggerPageSchema.properties.content.items.type == 'object'
324+
swaggerPageSchema.properties.num
325+
swaggerPageSchema.properties.num.type == 'integer'
326+
swaggerPageSchema.properties.num.format == 'int32'
327+
328+
cleanup:
329+
System.clearProperty(OpenApiConfigProperty.MICRONAUT_CONFIG_FILE_LOCATIONS)
330+
}
285331
}

0 commit comments

Comments
 (0)