use of io.swagger.models.parameters.PathParameter in project swagger-core by swagger-api.
the class ParameterProcessorTest method implicitParameterProcessorTest.
@Test(description = "parse implicit parameters from method")
public void implicitParameterProcessorTest() throws NoSuchMethodException {
final ApiImplicitParams params = getClass().getDeclaredMethod("implicitParametrizedMethod").getAnnotation(ApiImplicitParams.class);
final PathParameter param0 = (PathParameter) ParameterProcessor.applyAnnotations(null, new PathParameter(), String.class, Collections.<Annotation>singletonList(params.value()[0]));
assertNotNull(param0);
assertEquals(param0.getIn(), "path");
assertEquals(param0.getName(), "paramName1");
assertEquals(param0.getDescription(), "paramValue1");
assertNull(param0.getEnum());
assertNotNull(param0.getItems());
final BodyParameter param1 = (BodyParameter) ParameterProcessor.applyAnnotations(null, new BodyParameter(), String.class, Collections.<Annotation>singletonList(params.value()[1]));
assertNotNull(param1);
assertEquals(param1.getIn(), "body");
assertEquals(param1.getName(), "body");
assertEquals(param1.getDescription(), "paramValue2");
assertEquals(param1.getAccess(), "test");
final ModelImpl model = (ModelImpl) param1.getSchema();
assertNotNull(model);
assertEquals(model.getDefaultValue(), "10");
}
use of io.swagger.models.parameters.PathParameter in project swagger-core by swagger-api.
the class SecurityDefinitionTest method createModelWithSecurityRequirements.
@Test(description = "it should create a model with security requirements")
public void createModelWithSecurityRequirements() throws IOException {
final Model personModel = ModelConverters.getInstance().read(Person.class).get("Person");
final Model errorModel = ModelConverters.getInstance().read(Error.class).get("Error");
final Info info = new Info().version("1.0.0").title("Swagger Petstore");
final Contact contact = new Contact().name("Swagger API Team").email("foo@bar.baz").url("http://swagger.io");
info.setContact(contact);
final Swagger swagger = new Swagger().info(info).host("petstore.swagger.io").scheme(Scheme.HTTP).consumes("application/json").produces("application/json").model("Person", personModel).model("Error", errorModel);
swagger.securityDefinition("githubAccessCode", new OAuth2Definition().accessCode("http://foo.com/accessCode", "http://foo.com/tokenUrl").scope("user:email", "Grants read access to a user’s email addresses."));
final Operation get = new Operation().produces("application/json").summary("finds pets in the system").description("a longer description").tag("Pet Operations").operationId("get pet by id");
get.parameter(new QueryParameter().name("tags").description("tags to filter by").required(false).property(new StringProperty()));
get.parameter(new PathParameter().name("petId").description("pet to fetch").property(new LongProperty()));
final Response response = new Response().description("pets returned").schema(new RefProperty().asDefault("Person"));
final Response errorResponse = new Response().description("error response").schema(new RefProperty().asDefault("Error"));
get.response(200, response).defaultResponse(errorResponse).security(new SecurityRequirement("internal_oauth2").scope("user:email")).security(new SecurityRequirement("api_key"));
swagger.path("/pets", new Path().get(get));
final String json = ResourceUtils.loadClassResource(getClass(), "ModelWithSecurityRequirements.json");
SerializationMatchers.assertEqualsToJson(swagger, json);
}
use of io.swagger.models.parameters.PathParameter in project swagger-core by swagger-api.
the class DefaultParameterExtension method extractParameters.
@Override
public List<Parameter> extractParameters(List<Annotation> annotations, Type type, Set<Type> typesToSkip, Iterator<SwaggerExtension> chain) {
if (shouldIgnoreType(type, typesToSkip)) {
return new ArrayList<Parameter>();
}
List<Parameter> parameters = new ArrayList<Parameter>();
Parameter parameter = null;
for (Annotation annotation : annotations) {
if (annotation instanceof QueryParam) {
QueryParam param = (QueryParam) annotation;
QueryParameter qp = new QueryParameter().name(param.value());
Property schema = createProperty(type);
if (schema != null) {
qp.setProperty(schema);
}
parameter = qp;
} else if (annotation instanceof PathParam) {
PathParam param = (PathParam) annotation;
PathParameter pp = new PathParameter().name(param.value());
Property schema = createProperty(type);
if (schema != null) {
pp.setProperty(schema);
}
parameter = pp;
} else if (annotation instanceof HeaderParam) {
HeaderParam param = (HeaderParam) annotation;
HeaderParameter hp = new HeaderParameter().name(param.value());
Property schema = createProperty(type);
if (schema != null) {
hp.setProperty(schema);
}
parameter = hp;
} else if (annotation instanceof CookieParam) {
CookieParam param = (CookieParam) annotation;
CookieParameter cp = new CookieParameter().name(param.value());
Property schema = createProperty(type);
if (schema != null) {
cp.setProperty(schema);
}
parameter = cp;
} else if (annotation instanceof FormParam) {
FormParam param = (FormParam) annotation;
FormParameter fp = new FormParameter().name(param.value());
Property schema = createProperty(type);
if (schema != null) {
fp.setProperty(schema);
}
parameter = fp;
} else {
handleAdditionalAnnotation(parameters, annotation, type, typesToSkip);
}
}
if (parameter != null) {
parameters.add(parameter);
}
return parameters;
}
use of io.swagger.models.parameters.PathParameter in project swagger-core by swagger-api.
the class Reader method readImplicitParam.
protected Parameter readImplicitParam(ApiImplicitParam param) {
final Parameter p;
if (param.paramType().equalsIgnoreCase("path")) {
p = new PathParameter();
} else if (param.paramType().equalsIgnoreCase("query")) {
p = new QueryParameter();
} else if (param.paramType().equalsIgnoreCase("form") || param.paramType().equalsIgnoreCase("formData")) {
p = new FormParameter();
} else if (param.paramType().equalsIgnoreCase("body")) {
p = null;
} else if (param.paramType().equalsIgnoreCase("header")) {
p = new HeaderParameter();
} else {
LOGGER.warn("Unknown implicit parameter type: [{}]", param.paramType());
return null;
}
final Type type = param.dataTypeClass() == Void.class ? ReflectionUtils.typeFromString(param.dataType()) : param.dataTypeClass();
return ParameterProcessor.applyAnnotations(swagger, p, (type == null) ? String.class : type, Arrays.<Annotation>asList(param));
}
use of io.swagger.models.parameters.PathParameter in project swagger-core by swagger-api.
the class ParameterSerializationTest method serializeIntegerArrayPathParameter.
@Test(description = "it should serialize a PathParameter with integer array")
public void serializeIntegerArrayPathParameter() {
final PathParameter p = new PathParameter().type(ArrayProperty.TYPE).items(new IntegerProperty()).collectionFormat("multi");
final String json = "{" + " \"in\":\"path\"," + " \"required\":true," + " \"type\":\"array\"," + " \"items\":{" + " \"type\":\"integer\"," + " \"format\":\"int32\"" + " }," + " \"collectionFormat\":\"multi\"" + "}";
SerializationMatchers.assertEqualsToJson(p, json);
}
Aggregations