Skip to content

Commit

Permalink
Issue 130 - Parameter with no annotation should be defaulted to Query…
Browse files Browse the repository at this point in the history
…Value

not PathVariable
  • Loading branch information
Christophe Roudet committed Feb 7, 2020
1 parent ef84c63 commit c5b49d0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ public void visitMethod(MethodElement element, VisitorContext context) {
newParameter.setIn(ParameterIn.QUERY.toString());
newParameter.setName(queryVar);
} else if (! permitsRequestBody && hasNoBindingAnnotationOrType(parameter)) {
// default to PathVariable - https://github.com/micronaut-projects/micronaut-openapi/issues/130
// default to QueryValue - https://github.com/micronaut-projects/micronaut-openapi/issues/130
newParameter = new Parameter();
newParameter.setIn(ParameterIn.PATH.toString());
newParameter.setIn(ParameterIn.QUERY.toString());
newParameter.setName(parameterName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ class MyBean {}
buildBeanDefinition('test.MyBean', '''
package test;
import javax.annotation.Nullable;
import java.security.Principal;
import io.micronaut.http.annotation.*;
import io.micronaut.http.*;
Expand Down Expand Up @@ -383,7 +384,10 @@ interface Test {
public String test4(HttpRequest req);
@Get("/test5")
public String test5(HttpRequest req, Principal principal, String name, Greeting greeting);
public String test5(HttpRequest req, Principal principal, String name, String greeting);
@Get("/test6{?bar}")
public String test6(@Nullable String bar, String name);
}
class Greeting {
Expand All @@ -404,7 +408,7 @@ class MyBean {}
pathItem.get.operationId == 'test1'
pathItem.get.parameters.size() == 1
pathItem.get.parameters[0].name == 'name'
pathItem.get.parameters[0].in == 'path'
pathItem.get.parameters[0].in == 'query'

when:
pathItem = openAPI.paths.get("/test2")
Expand Down Expand Up @@ -434,10 +438,20 @@ class MyBean {}
pathItem.get.operationId == 'test5'
pathItem.get.parameters.size() == 2
pathItem.get.parameters[0].name == 'name'
pathItem.get.parameters[0].in == 'path'
pathItem.get.parameters[0].in == 'query'
pathItem.get.parameters[1].name == 'greeting'
pathItem.get.parameters[1].in == 'path'
pathItem.get.parameters[1].schema.$ref == '#/components/schemas/Greeting'
pathItem.get.parameters[1].in == 'query'

when:
pathItem = openAPI.paths.get("/test6")

then:
pathItem.get.operationId == 'test6'
pathItem.get.parameters.size() == 2
pathItem.get.parameters[0].name == 'bar'
pathItem.get.parameters[0].in == 'query'
pathItem.get.parameters[1].name == 'name'
pathItem.get.parameters[1].in == 'query'
}
}

Expand Down

0 comments on commit c5b49d0

Please sign in to comment.