Skip to content

support spring RequestMapping String[] params() #1726

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

Closed
sdandroid opened this issue Jun 28, 2022 · 6 comments
Closed

support spring RequestMapping String[] params() #1726

sdandroid opened this issue Jun 28, 2022 · 6 comments
Labels
question Further information is requested

Comments

@sdandroid
Copy link

  @Operation(summary = "test")
  @GetMapping(value = "/api/test", params = "action=test")
  @ResponseBody
  public void test(String code) {
	
  }
  @Operation(summary = "test1")
  @GetMapping(value = "/api/test", params = "action=test1")
  @ResponseBody
  public void test1(String code) {
	
  }

/api/test?action=test  ==>  call  test function
/api/test?action=test1 ==> call  test1 function
/api/test  ==>    cannot call any function

spring doc

	/**
	 * The parameters of the mapped request, narrowing the primary mapping.
	 * <p>Same format for any environment: a sequence of "myParam=myValue" style
	 * expressions, with a request only mapped if each such parameter is found
	 * to have the given value. Expressions can be negated by using the "!=" operator,
	 * as in "myParam!=myValue". "myParam" style expressions are also supported,
	 * with such parameters having to be present in the request (allowed to have
	 * any value). Finally, "!myParam" style expressions indicate that the
	 * specified parameter is <i>not</i> supposed to be present in the request.
	 * <p><b>Supported at the type level as well as at the method level!</b>
	 * When used at the type level, all method-level mappings inherit this
	 * parameter restriction.
	 */
	String[] params() default {};

Now the method cannot be called on the swagger ui without generating the parameters of the param.

@bianjp
Copy link

bianjp commented Jun 28, 2022

OpenAPI identifies API endpoint by path and method, and it does not support query string: https://stackoverflow.com/a/40500680/3128576

So this is not possible until OpenAPI specification supports it.

@sdandroid
Copy link
Author

Can convert path to this?

/api/test?action=test
/api/test?action=test1

Springfox does this, and then sets the query to enum and requires it.

@bianjp
Copy link

bianjp commented Jun 28, 2022

Can convert path to this?

/api/test?action=test
/api/test?action=test1

Springfox does this, and then sets the query to enum and requires it.

Well, this is not specification compliant and I doubt it's should be implemented.

@csgtree
Copy link

csgtree commented Jun 29, 2022

We have such requirement as well during migrating api doc from SpringFox. It will be great to support this case (maybe by offering kind of customization) as there could be large number of legacy APIs using this style (like AWS S3 restful APIs) .

@junoyoon
Copy link

junoyoon commented Jul 5, 2022

This can be fixed by #1706
This PR allows user to rewrite path to include path by extending RouterOperationCustomizer.

@bnasslahsen
Copy link
Collaborator

Agree with @bianjp answer

@bnasslahsen bnasslahsen added the question Further information is requested label Jul 30, 2022
@springdoc springdoc locked as too heated and limited conversation to collaborators Jul 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants