Search in sources :

Example 31 with PathParameter

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");
}
Also used : ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) BodyParameter(io.swagger.models.parameters.BodyParameter) ModelImpl(io.swagger.models.ModelImpl) PathParameter(io.swagger.models.parameters.PathParameter) Annotation(java.lang.annotation.Annotation) Test(org.testng.annotations.Test)

Example 32 with PathParameter

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);
}
Also used : Path(io.swagger.models.Path) QueryParameter(io.swagger.models.parameters.QueryParameter) OAuth2Definition(io.swagger.models.auth.OAuth2Definition) Error(io.swagger.models.Error) StringProperty(io.swagger.models.properties.StringProperty) Operation(io.swagger.models.Operation) Info(io.swagger.models.Info) PathParameter(io.swagger.models.parameters.PathParameter) Contact(io.swagger.models.Contact) RefProperty(io.swagger.models.properties.RefProperty) Response(io.swagger.models.Response) Swagger(io.swagger.models.Swagger) LongProperty(io.swagger.models.properties.LongProperty) Model(io.swagger.models.Model) Person(io.swagger.models.Person) SecurityRequirement(io.swagger.models.SecurityRequirement) Test(org.testng.annotations.Test)

Example 33 with PathParameter

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;
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParam(javax.ws.rs.HeaderParam) ArrayList(java.util.ArrayList) PathParameter(io.swagger.models.parameters.PathParameter) FormParameter(io.swagger.models.parameters.FormParameter) Annotation(java.lang.annotation.Annotation) CookieParam(javax.ws.rs.CookieParam) QueryParam(javax.ws.rs.QueryParam) HeaderParameter(io.swagger.models.parameters.HeaderParameter) CookieParameter(io.swagger.models.parameters.CookieParameter) FormParameter(io.swagger.models.parameters.FormParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) CookieParameter(io.swagger.models.parameters.CookieParameter) PathParam(javax.ws.rs.PathParam) HeaderParameter(io.swagger.models.parameters.HeaderParameter) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) FormParam(javax.ws.rs.FormParam)

Example 34 with PathParameter

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));
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Type(java.lang.reflect.Type) JavaType(com.fasterxml.jackson.databind.JavaType) ParameterizedType(java.lang.reflect.ParameterizedType) FormParameter(io.swagger.models.parameters.FormParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) AnnotatedParameter(com.fasterxml.jackson.databind.introspect.AnnotatedParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) PathParameter(io.swagger.models.parameters.PathParameter) FormParameter(io.swagger.models.parameters.FormParameter)

Example 35 with PathParameter

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);
}
Also used : IntegerProperty(io.swagger.models.properties.IntegerProperty) PathParameter(io.swagger.models.parameters.PathParameter) Test(org.testng.annotations.Test)

Aggregations

PathParameter (io.swagger.models.parameters.PathParameter)51 QueryParameter (io.swagger.models.parameters.QueryParameter)35 Parameter (io.swagger.models.parameters.Parameter)32 Test (org.testng.annotations.Test)32 BodyParameter (io.swagger.models.parameters.BodyParameter)26 HeaderParameter (io.swagger.models.parameters.HeaderParameter)16 Swagger (io.swagger.models.Swagger)14 StringProperty (io.swagger.models.properties.StringProperty)12 FormParameter (io.swagger.models.parameters.FormParameter)11 Operation (io.swagger.models.Operation)10 SerializableParameter (io.swagger.models.parameters.SerializableParameter)10 Response (io.swagger.models.Response)8 IntegerProperty (io.swagger.models.properties.IntegerProperty)8 RefProperty (io.swagger.models.properties.RefProperty)8 Path (io.swagger.models.Path)6 ArrayProperty (io.swagger.models.properties.ArrayProperty)6 HashMap (java.util.HashMap)6 ModelImpl (io.swagger.models.ModelImpl)5 RefModel (io.swagger.models.RefModel)5 ArrayList (java.util.ArrayList)5