Skip to content

Commit

Permalink
Merge pull request #2819 from swagger-api/ticket-2818
Browse files Browse the repository at this point in the history
refs #2818 - fix @parameter type/format resolving
  • Loading branch information
frantuma authored May 23, 2018
2 parents 0829ea9 + 34ad614 commit 31e5df6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,7 @@ public static Type getSchemaType(io.swagger.v3.oas.annotations.media.Schema sche
return String.class;
}
String schemaType = schema.type();
String schemaFormat = schema.format();
Class schemaImplementation = schema.implementation();

if (!schemaImplementation.equals(Void.class)) {
Expand All @@ -967,9 +968,19 @@ public static Type getSchemaType(io.swagger.v3.oas.annotations.media.Schema sche
}
switch (schemaType) {
case "number":
return BigDecimal.class;
if ("float".equals(schemaFormat)) {
return Float.class;
} else if ("double".equals(schemaFormat)) {
return Double.class;
} else {
return BigDecimal.class;
}
case "integer":
return Long.class;
if ("int32".equals(schemaFormat)) {
return Integer.class;
} else {
return Long.class;
}
case "boolean":
return Boolean.class;
case "string":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import io.swagger.v3.jaxrs2.resources.Ticket2793Resource;
import io.swagger.v3.jaxrs2.resources.Ticket2794Resource;
import io.swagger.v3.jaxrs2.resources.Ticket2806Resource;
import io.swagger.v3.jaxrs2.resources.Ticket2818Resource;
import io.swagger.v3.jaxrs2.resources.UserAnnotationResource;
import io.swagger.v3.jaxrs2.resources.extensions.ExtensionsResource;
import io.swagger.v3.jaxrs2.resources.extensions.OperationExtensionsResource;
Expand Down Expand Up @@ -1077,6 +1078,21 @@ public void testTicket2793() {
" type: boolean\n";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}

@Test(description = "test ticket #2818 @Parameter annotation")
public void test2818() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(Ticket2818Resource.class);
Paths paths = openAPI.getPaths();
assertEquals(paths.size(), 1);
PathItem pathItem = paths.get("/bookstore/{id}");
assertNotNull(pathItem);
Operation operation = pathItem.getGet();
assertNotNull(operation);
assertEquals(operation.getParameters().get(0).getSchema().getType(), "integer");
assertEquals(operation.getParameters().get(0).getSchema().getFormat(), "int32");

}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.swagger.v3.jaxrs2.resources;

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.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/bookstore")
public class Ticket2818Resource {

@Produces({ MediaType.APPLICATION_JSON })
@Path("/{id}")
@GET
public Book getBook(
@Parameter(
in = ParameterIn.PATH,
schema = @Schema (
type = "integer",
format = "int32"
)
)
@PathParam("id") int id) {
return new Book();
}


public static class Book {
public String foo;
}
}

0 comments on commit 31e5df6

Please sign in to comment.