Skip to content

Set containingClass at MethodParameter #1491

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 2 commits into from
Feb 5, 2022
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 @@ -174,7 +174,7 @@ private static Stream<MethodParameter> fromSimpleClass(Class<?> paramClass, Fiel
.filter(d -> d.getName().equals(field.getName()))
.map(PropertyDescriptor::getReadMethod)
.filter(Objects::nonNull)
.map(method -> new MethodParameter(method, -1))
.map(method -> new MethodParameter(method, -1).withContainingClass(paramClass))
.map(param -> new DelegatingMethodParameter(param, fieldNamePrefix + field.getName(), finalFieldAnnotations, true, isNotRequired));
}
catch (IntrospectionException e) {
Expand Down Expand Up @@ -246,4 +246,4 @@ static void removeSimpleTypes(Class<?>... classes) {
SIMPLE_TYPES.removeAll(Arrays.asList(classes));
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package test.org.springdoc.api.app181;

import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;

public class AbstractParameterObject<T> {

int primitiveBaseField;

T genericField;

public int getPrimitiveBaseField() {
return primitiveBaseField;
}

public void setPrimitiveBaseField(int primitiveBaseField) {
this.primitiveBaseField = primitiveBaseField;
}

public T getGenericField() {
return genericField;
}

public void setGenericField(T genericField) {
this.genericField = genericField;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package test.org.springdoc.api.app181;

public class ConcreteParameterObject extends AbstractParameterObject<String> {

int primitiveConcreteField;

public int getPrimitiveConcreteField() {
return primitiveConcreteField;
}

public void setPrimitiveConcreteField(int primitiveConcreteField) {
this.primitiveConcreteField = primitiveConcreteField;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
*
* * Copyright 2019-2020 the original author or authors.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * https://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*/

package test.org.springdoc.api.app181;

import org.springdoc.api.annotations.ParameterObject;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

@GetMapping( "/test1")
public ResponseEntity<String> sayHello( @ParameterObject final ConcreteParameterObject test) {
System.out.println("Field B = " + test);
return new ResponseEntity<String>("{\"Say\": \"Hello\"}", HttpStatus.OK);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
*
* * Copyright 2019-2020 the original author or authors.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * https://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*/

package test.org.springdoc.api.app181;


import test.org.springdoc.api.AbstractSpringDocTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* Tests Spring meta-annotations as method parameters
*/
public class SpringDocApp181Test extends AbstractSpringDocTest {

@SpringBootApplication
static class SpringDocTestApp {}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"openapi": "3.0.1",
"info": {
"title": "OpenAPI definition",
"version": "v0"
},
"servers": [
{
"url": "http://localhost",
"description": "Generated server url"
}
],
"paths": {
"/test1": {
"get": {
"tags": [
"hello-controller"
],
"operationId": "sayHello",
"parameters": [
{
"name": "primitiveConcreteField",
"in": "query",
"required": false,
"schema": {
"type": "integer",
"format": "int32"
}
},
{
"name": "primitiveBaseField",
"in": "query",
"required": false,
"schema": {
"type": "integer",
"format": "int32"
}
},
{
"name": "genericField",
"in": "query",
"required": false,
"schema": {
"type": "string"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"type": "object" is returned without this PR.

}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"type": "string"
}
}
}
}
}
}
}
},
"components": {}
}