Skip to content

Commit

Permalink
Merge pull request #3032 from swagger-api/ticket-3029
Browse files Browse the repository at this point in the history
ref #3029 - fix ref parameter resolving
  • Loading branch information
frantuma authored Nov 26, 2018
2 parents 51bfc35 + e876fc0 commit 6fc8ca9
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public ResolvedParameter extractParameters(List<Annotation> annotations,
if (parameter == null) {
parameter = new Parameter();
}
if (StringUtils.isNotBlank(((io.swagger.v3.oas.annotations.Parameter) annotation).ref())) {
parameter.$ref(((io.swagger.v3.oas.annotations.Parameter) annotation).ref());
}
} else {
List<Parameter> formParameters = new ArrayList<>();
List<Parameter> parameters = new ArrayList<>();
Expand All @@ -107,7 +110,7 @@ public ResolvedParameter extractParameters(List<Annotation> annotations,
List<Parameter> parameters = new ArrayList<>();
ResolvedParameter extractParametersResult = new ResolvedParameter();

if (parameter != null && StringUtils.isNotBlank(parameter.getIn())) {
if (parameter != null && (StringUtils.isNotBlank(parameter.getIn()) || StringUtils.isNotBlank(parameter.get$ref()))) {
parameters.add(parameter);
} else if (includeRequestBody) {
Parameter unknownParameter = ParameterProcessor.applyAnnotations(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.swagger.v3.jaxrs2.resources.RefExamplesResource;
import io.swagger.v3.jaxrs2.resources.RefHeaderResource;
import io.swagger.v3.jaxrs2.resources.RefLinksResource;
import io.swagger.v3.jaxrs2.resources.RefParameter3029Resource;
import io.swagger.v3.jaxrs2.resources.RefParameterResource;
import io.swagger.v3.jaxrs2.resources.RefRequestBodyResource;
import io.swagger.v3.jaxrs2.resources.RefResponsesResource;
Expand Down Expand Up @@ -1914,4 +1915,59 @@ public void testTicket3015() {
PrimitiveType.customExcludedClasses().remove(URI.class.getName());
}


@Test(description = "Parameter with ref")
public void testTicket3029() {
Components components = new Components();
components.addParameters("id", new Parameter()
.description("Id Description")
.schema(new IntegerSchema())
.in(ParameterIn.QUERY.toString())
.example(1)
.required(true));
OpenAPI oas = new OpenAPI()
.info(new Info().description("info"))
.components(components);

Reader reader = new Reader(oas);
OpenAPI openAPI = reader.read(RefParameter3029Resource.class);

String yaml = "openapi: 3.0.1\n" +
"info:\n" +
" description: info\n" +
"paths:\n" +
" /2:\n" +
" get:\n" +
" summary: Simple get operation\n" +
" operationId: sendPayload2\n" +
" parameters:\n" +
" - $ref: '#/components/parameters/id'\n" +
" responses:\n" +
" default:\n" +
" description: default response\n" +
" content:\n" +
" '*/*': {}\n" +
" /1:\n" +
" get:\n" +
" summary: Simple get operation\n" +
" operationId: sendPayload1\n" +
" parameters:\n" +
" - $ref: '#/components/parameters/id'\n" +
" responses:\n" +
" default:\n" +
" description: default response\n" +
" content:\n" +
" '*/*': {}\n" +
"components:\n" +
" parameters:\n" +
" id:\n" +
" in: query\n" +
" description: Id Description\n" +
" required: true\n" +
" schema:\n" +
" type: integer\n" +
" format: int32\n" +
" example: 1\n";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.swagger.v3.jaxrs2.resources;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;

public class RefParameter3029Resource {

@GET
@Path("/1")
@Operation(
summary = "Simple get operation",
operationId = "sendPayload1",
parameters = @Parameter(ref = "id"))
public void sendPayload1() {
}

@GET
@Path("/2")
@Operation(
summary = "Simple get operation",
operationId = "sendPayload2")
@Parameter(ref = "id")
public void sendPayload2() {
}

}

0 comments on commit 6fc8ca9

Please sign in to comment.