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

Redunant(wrong) direction appended to @PageableDefault #2152

Closed
onacit opened this issue Mar 21, 2023 · 7 comments
Closed

Redunant(wrong) direction appended to @PageableDefault #2152

onacit opened this issue Mar 21, 2023 · 7 comments
Labels
enhancement New feature or request

Comments

@onacit
Copy link

onacit commented Mar 21, 2023

Describe the bug

With following code,

    public PagedModel<Some> read(
            @PageableDefault(sort = {
                    "some,desc",
                    "other,desc",
                    "another.that,desc"
            })
            @ParameterObject final Pageable pageable) {
}

Swagger UI renders a redundant direction,

Screenshot 2023-03-21 at 5 57 34 PM

@bnasslahsen bnasslahsen added the invalid This doesn't seem right label Mar 21, 2023
@bnasslahsen
Copy link
Contributor

@onacit,

springdoc-openapi will reflect your code description in the annotations.
Do no mix sort and direction definitions. Use the appropriate attributes for each:

  • sort: for the sort attributes
  • direction: for the expected direction

Here is an example:

@PageableDefault(sort = {
					"some",
					"other",
					"another.that"
			}, direction = Direction.DESC)

@onacit
Copy link
Author

onacit commented Mar 21, 2023

@bnasslahsen Thanks. The way you described is exactly what I don't want to do.

What if I want to do following?

    public PagedModel<Some> read(
            @PageableDefault(sort = {
                    "some,desc",
                    "other,asc",
                    "another.that,desc"
            })
            @ParameterObject final Pageable pageable) {
}

Thanks, again.

@bnasslahsen
Copy link
Contributor

@onacit,

If you want that syntax, you can propose a PR!

@onacit
Copy link
Author

onacit commented Mar 21, 2023

@bnasslahsen Thank you, sir.

I'm not intending any PR-required syntax.

The following URIs are already valid.

/some?sort=some%2Cdesc&sort=other%2Cdesc&sort=another.that$2Cdesc
/some?sort=some&sort=other%2C&sort=another.that$2Cdesc

The problem is that the UI doesn't detect the ,desc part of each sort parameters, and appends ,ASC.

Thanks.

/some?sort=some%2Cdesc%2CASC&sort=other%2Cdesc%2CASC&sort=another.that$2Cdesc%2CASC

@onacit
Copy link
Author

onacit commented Mar 21, 2023

Apologies, if I'm understood in a very wrong way.

?sort ?direction effective ?sort swagger-ui
some some,asc
some asc some,asc
some desc some,desc
some.asc asc some,asc
some,asc desc some,asc
some.desc some,desc some,desc,ASC
some.desc asc some,desc
some.desc desc some,desc

@onacit
Copy link
Author

onacit commented Mar 23, 2023

@bnasslahsen Would you please take a look at the PR? Thanks.

@bnasslahsen bnasslahsen added enhancement New feature or request and removed invalid This doesn't seem right labels Mar 26, 2023
bnasslahsen added a commit that referenced this issue Mar 26, 2023
[#2152] Detect directions in default sort values
@onacit
Copy link
Author

onacit commented Apr 2, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants