Skip to content

issue #2733 second change for only check response entity type #2736

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

Merged
merged 1 commit into from
Sep 29, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.media.StringSchema;
import org.springdoc.core.providers.ObjectMapperProvider;
import org.springframework.http.ResponseEntity;

import static org.springdoc.core.converters.ConverterUtils.isFluxTypeWrapper;
import static org.springdoc.core.converters.ConverterUtils.isResponseTypeToIgnore;
Expand Down Expand Up @@ -65,12 +66,7 @@ public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterato
if (javaType != null) {
Class<?> cls = javaType.getRawClass();
if (isResponseTypeWrapper(cls) && !isFluxTypeWrapper(cls)) {
JavaType innerType = javaType.getBindings().getBoundType(0);
if(javaType.getSuperClass() !=null
&& javaType.getSuperClass().hasGenericTypes()
&& isResponseTypeWrapper(javaType.getSuperClass().getRawClass())
&& !Object.class.equals(javaType.getSuperClass().getBindings().getBoundType(0).getRawClass()))
innerType = javaType.getSuperClass().getBindings().getBoundType(0);
JavaType innerType = findResponseEntity(javaType).containedType(0);
if (innerType == null)
return new StringSchema();
return context.resolve(new AnnotatedType(innerType)
Expand All @@ -83,4 +79,13 @@ else if (isResponseTypeToIgnore(cls))
}
return (chain.hasNext()) ? chain.next().resolve(type, context, chain) : null;
}

private JavaType findResponseEntity(JavaType javaType){
if(ResponseEntity.class.isAssignableFrom(javaType.getRawClass())){
while (ResponseEntity.class != javaType.getRawClass())
javaType = javaType.getSuperClass();
}
return javaType;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@


import test.org.springdoc.api.v30.app227.model.Item;
import test.org.springdoc.api.v30.app227.wrapper.NoGenericWrapper;
import test.org.springdoc.api.v30.app227.wrapper.ResponseEntityWrapper;

import org.springframework.http.HttpStatus;
Expand All @@ -34,4 +35,9 @@ public ResponseEntityWrapper<String> persons() {
return new ResponseEntityWrapper<>(Item.fromPayload("1", "OK", "String"), HttpStatus.OK);
}

@GetMapping("/persons2")
public NoGenericWrapper persons2() {
return new NoGenericWrapper(Item.fromPayload("1", "OK", "String"), HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package test.org.springdoc.api.v30.app227.wrapper;


import org.springframework.http.HttpStatusCode;
import test.org.springdoc.api.v30.app227.model.Item;

public class NoGenericWrapper extends ResponseEntityWrapper<String> {
public NoGenericWrapper(Item<String> body, HttpStatusCode status) {
super(body, status);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@
}
}
}
},
"/persons2": {
"get": {
"tags": [
"hello-controller"
],
"operationId": "persons2",
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/ItemString"
}
}
}
}
}
}
}
},
"components": {
Expand Down