It would be great if beans are supported in GET endpoints.
@RestController
public class MyController {
@GetMapping
public Object persons(@Valid PersonDto person) {
}
}
class PersonDto {
@NotBlank private String name;
@NotNull private Integer age;
}
In this case, the following error is printed:
Resolver error at paths./my/persons.get.parameters.0.schema.$ref
Could not resolve reference: Could not resolve pointer: /components/schemas/PersonDto does not exist in document
Tested with 1.1.6, without any issues. For new issues please add the expected result as well in OpenAPI 3, format.
A sample code is available on github: https://github.com/springdoc/springdoc-openapi-demos/tree/master/springdoc-openapi-test-app1
Class: ItemController
Method:
@GetMapping("/items/demo")
public List<ItemDTO> showItemsForObject(final ItemLightDTO itemDTO) {
return new ArrayList<ItemDTO>();
}
Find attached a complete example, which is not working:
@SpringBootApplication
public class AppTest {
public static void main(String[] args) {
SpringApplication.run(AppTest.class, args);
}
}
@RestController
public class PersonServlet {
@GetMapping(value = "/persons")
public String persons(final PersonDto dto) {
return "OK";
}
}
public class PersonDto implements Serializable {
private String name;
private String age;
public PersonDto() {
}
public PersonDto(String names, String age) {
super();
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.springtest</groupId>
<artifactId>validation</artifactId>
<version>1.0.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.1.7</version>
</dependency>
</dependencies>
</project>
Result in swagger-ui:
Errors
Resolver error at paths./persons.get.parameters.0.schema.$ref
Could not resolve reference: Could not resolve pointer: /components/schemas/PersonDto does not exist in document
Openapi format:
{
"openapi":"3.0.1",
"info":{
"title":"OpenAPI definition",
"version":"v0"
},
"paths":{
"/persons":{
"get":{
"operationId":"persons",
"parameters":[
{
"name":"dto",
"in":"query",
"required":true,
"schema":{
"$ref":"#/components/schemas/PersonDto"
}
}
],
"responses":{
"200 OK":{
"description":"default response",
"content":{
"*/*":{
"schema":{
"type":"string"
}
}
}
}
}
}
}
},
"components":{
}
}
This is also not working for me. Tried to annotate the parameter in the example provided by @membersound above like this:
@RestController
public class PersonServlet {
@GetMapping(value = "/persons")
public String persons(@Parameter(explode = Explode.TRUE, in = ParameterIn.QUERY, content = @Content(schema = @Schema(implementation = PersonDto.class))) final PersonDto dto) {
return "OK";
}
}
but this had no effect.
Tested using version 1.1.24
Hi,
Issue confirmed and fixed.
Please test with v1.1.26 of springdoc-openapi and give us your feedback.
Tested this with v1.1.26. Even though OpenAPI 3.0 yaml export seems ok
/persons:
get:
operationId: persons
parameters:
- name: dto
in: query
required: true
schema:
$ref: '#/components/schemas/PersonDto'
responses:
'200':
description: default response
content:
'*/*':
schema:
type: string
...
components:
schemas:
PersonDto:
type: object
properties:
name:
type: string
age:
type: string
i'm still not sure if this the correct output here as swagger-ui does not seem to recognise this.
I would expect that in swagger-ui Parameters are expanded to include the fields in PersonDto, but this is not the case.
Screenshot of swagger-ui:

I tested this with springfox and OpenAPI 2 and the expansion of bean to it's properties when used in a GET request, seems to work fine.
To make it more clear i would expect the outcome in this case to be:
/persons:
get:
operationId: persons
parameters:
- name: name
in: query
schema:
type: string
- name: age
in: query
schema:
type: string
responses:
'200':
description: default response
content:
'*/*':
schema:
type: string
@springdoc any chance you can take a look at the UI part? should we rather open a new issue?
+1 for the great support around this project, I'm really excited that finally we can take adventage of swagger on webflux projects as well
Could you please reopen this? Test failed with springdoc-1.1.33 and spring-boot-2.1.7!
The parameter bean is shown as required Object, but the objects parameters are not expanded and not shown.
I am running into the exact same issue with latest v1.2.0 release. Java beans are very commonly used in GET requests, in which cases, the properties of the bean rather than the bean itself should be listed as parameters. Please consider adding support of this.
@lzhoucs could you maybe create another issue for this to draw attention to that problem? I don't know if anyone is watching this as it is closed...
Hi Guys,
The support of Bean as parameters is already available;
You can have a look at SpringDocApp22Test for a sample.
For the behaviour of swagger-ui where the Request Parameter is shown as an object: There is a related enhancement on swagger-ui that we follow. This isn't yet resolved:
For any other issue, please provide the sample code to reproduce it, the actual and the expected result using OpenAPI description (yaml / json)
So you're actually saying that as of now, it's still not possible to show the fields of a bean as input in swagger-ui?
Most helpful comment
Tested this with v1.1.26. Even though OpenAPI 3.0 yaml export seems ok
i'm still not sure if this the correct output here as swagger-ui does not seem to recognise this.
I would expect that in swagger-ui Parameters are expanded to include the fields in PersonDto, but this is not the case.
Screenshot of swagger-ui:

I tested this with springfox and OpenAPI 2 and the expansion of bean to it's properties when used in a GET request, seems to work fine.
To make it more clear i would expect the outcome in this case to be: