question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support beans as parameter in @GetMapping / components empty

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11

github_iconTop GitHub Comments

5reactions
anzapcommented, Aug 25, 2019

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: image

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
0reactions
membersoundcommented, Nov 7, 2019

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Springboot @GetMapping method injection with object as ...
Bean is an object managed by the Spring context. Objects of these classes do not need to be created - Spring is responsible...
Read more >
CORS support in Spring Framework
Spring Framework 4.2 GA provides first class support for CORS ... it is recommended to just declare a WebMvcConfigurer bean as following:
Read more >
Validation with Spring Boot - the Complete Guide - Reflectoring
A tutorial consolidating the most important features you'll need to integrate Bean Validation into your Spring Boot application.
Read more >
Using Custom Data Binders in Spring MVC - Baeldung
Binding Individual Objects to Request Parameters ... @Component public class StringToLocalDateTimeConverter implements Converter<String, ...
Read more >
F.A.Q - Springdoc-openapi
To enable the support of multiple OpenAPI definitions, a bean of type ... You can define common parameters under parameters in the global...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found