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

Support nested parameter objects #605

Merged
merged 3 commits into from
Apr 25, 2020
Merged

Conversation

zarebski-m
Copy link
Contributor

@zarebski-m zarebski-m commented Apr 23, 2020

Partially fixes #590

This is partial fix because it does not deal with collections, arrays, and maps. Actually I don't really know how to approach collections just yet.

Support for collections in parameter objects can be added iteratively at later time.

I'd like to also start a discussion about what constitutes a simple type – i.e. a type that is not “exploded” by its nested fields. Obviously all primitives, numbers, strings, optionals, and enums are simple types. For now as simple types are treated also arrays, iterables, and maps.

I think that e.g. java.time classes as well as java.util.Date et al. also deserve status of simple types, but I'd like to know your opinion. In any case, simple types can be adjusted with SpringDocUtils builder. Nothing stops a user from adding or removing simple types as they please.

@bnasslahsen
Copy link
Contributor

Thank you @zarebski-m for your great contribution.
As you mentionned, this is a first step. Support for collections in parameter objects can be added at later time.

For the simpleTypes, i have added the swagger primitiveTypes which integrates dates as well.

@annassi-code
Copy link

please can you give us an example. how your fix works please please ?

Controller

@RestController
public class MealPartiesAdminController {
@GetMapping(value = "/parties/{id}")
public MealParty getMealParty(@PathVariable("id") long mealPartyId, MealPartiesQuery query){
return this.mealPartyAdminService.getMealParty(mealPartyId, query);
}
}

Model

public class MealPartiesQuery {
private String name;
private int membersCount;
}

Both name and membersCount are now endpoint query parameters. However, the generated swagger information only shows the query as an object. I've also added @ModelAttribute to query parameter in the controller but it still shows it as an object.
Am I missing something or there is no support for this currently?

i use openapi 1.5.7 last version

@bnasslahsen
Copy link
Contributor

bnasslahsen commented Apr 22, 2021

simply add @ParameterObject on your parameter MealPartiesQuery in the method getMealParty.
You can read the project documentation
Or see project test for more sample codes. This is just a sample of many.

Note that use GitHub issues to track bugs and enhancements.
If you have a general usage question please ask on Stack Overflow.
The springdoc-openapi team and the broader community monitor the springdoc tag.

@springdoc springdoc locked as too heated and limited conversation to collaborators Apr 22, 2021
@bnasslahsen bnasslahsen added the enhancement New feature or request label Jan 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@ParameterObject support nested parameter objects
3 participants