Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isArray and isIterable should be done after checking customTypeSchema. (5.2.x) #1281

Merged
merged 2 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
projectVersion=.5.2.0
projectVersion=5.2.0
projectGroup=io.micronaut.openapi
micronautDocsVersion=2.0.0
groovyVersion=4.0.15
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
micronaut.openapi.schema.io.micronaut.data.model.Page=io.micronaut.openapi.SwaggerPage
Original file line number Diff line number Diff line change
Expand Up @@ -854,19 +854,19 @@ protected Schema<?> resolveSchema(OpenAPI openAPI, @Nullable Element definingEle

if (type != null) {

String typeName = type.getName();
ClassElement customTypeSchema = getCustomSchema(typeName, typeArgs, context);
if (customTypeSchema != null) {
type = customTypeSchema;
}

if (isArray == null) {
isArray = type.isArray();
}
if (isIterable == null) {
isIterable = type.isIterable();
}

String typeName = type.getName();
ClassElement customTypeSchema = getCustomSchema(typeName, typeArgs, context);
if (customTypeSchema != null) {
type = customTypeSchema;
}

// File upload case
if (isFileUpload(type)) {
isPublisher = isPublisher && !"io.micronaut.http.multipart.PartData".equals(typeName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public static Operation mergeOperations(Operation op1, Operation op2) {
Parameter existedParameter = null;
int i = 0;
for (Parameter p1 : op1.getParameters()) {
if (p1.getName().equals(p2.getName())
if (Objects.equals(p1.getName(), p2.getName())
&& Objects.equals(p1.getIn(), p2.getIn())) {
existedParameter = p1;
break;
Expand Down
9 changes: 9 additions & 0 deletions openapi/src/test/groovy/io/micronaut/openapi/SwaggerPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.micronaut.openapi;

import java.util.List;

public class SwaggerPage<T> {

public List<T> content;
public int num;
}
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,50 @@ class MyBean {}
System.clearProperty(OpenApiConfigProperty.MICRONAUT_CONFIG_FILE_LOCATIONS)
System.clearProperty(Environment.ENVIRONMENTS_PROPERTY)
}

void "test custom OpenAPI schema for iterable class"() {
given:
System.setProperty(OpenApiConfigProperty.MICRONAUT_OPENAPI_CONFIG_FILE, "openapi-custom-schema-for-iterable-class.properties")

when:
buildBeanDefinition('test.MyBean', '''
package test;

import io.micronaut.data.model.Page;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;

@Controller
class OpenApiController {

@Get("{?pageable*}")
public Page<String> processSync() {
return null;
}
}

@jakarta.inject.Singleton
class MyBean {}
''')
then:
Utils.testReference != null

when:
OpenAPI openAPI = Utils.testReference
Schema swaggerPageSchema = openAPI.components.schemas.'SwaggerPage_String_'

then:

swaggerPageSchema
swaggerPageSchema.type == 'object'
swaggerPageSchema.properties.content
swaggerPageSchema.properties.content.type == 'array'
swaggerPageSchema.properties.content.items.type == 'object'
swaggerPageSchema.properties.num
swaggerPageSchema.properties.num.type == 'integer'
swaggerPageSchema.properties.num.format == 'int32'

cleanup:
System.clearProperty(OpenApiConfigProperty.MICRONAUT_CONFIG_FILE_LOCATIONS)
}
}
Loading