Search in sources :

Example 1 with RefParameter

use of io.swagger.models.parameters.RefParameter in project swagger-core by swagger-api.

the class SwaggerSerializerTest method writeSpecWithParameterReferences.

@Test(description = "it should write a spec with parameter references")
public void writeSpecWithParameterReferences() throws IOException {
    final Model personModel = ModelConverters.getInstance().read(Person.class).get("Person");
    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").securityDefinition("api-key", new ApiKeyAuthDefinition("key", In.HEADER)).scheme(Scheme.HTTP).consumes("application/json").produces("application/json").model("Person", personModel);
    final QueryParameter parameter = new QueryParameter().name("id").description("a common get parameter").property(new LongProperty());
    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").parameter(new RefParameter("foo"));
    swagger.parameter("foo", parameter).path("/pets", new Path().get(get));
    final String swaggerJson = Json.mapper().writeValueAsString(swagger);
    final Swagger rebuilt = Json.mapper().readValue(swaggerJson, Swagger.class);
    assertEquals(Json.pretty(swagger), Json.pretty(rebuilt));
}
Also used : Path(io.swagger.models.Path) ApiKeyAuthDefinition(io.swagger.models.auth.ApiKeyAuthDefinition) QueryParameter(io.swagger.models.parameters.QueryParameter) RefParameter(io.swagger.models.parameters.RefParameter) Swagger(io.swagger.models.Swagger) LongProperty(io.swagger.models.properties.LongProperty) Model(io.swagger.models.Model) RefModel(io.swagger.models.RefModel) Operation(io.swagger.models.Operation) Info(io.swagger.models.Info) Person(io.swagger.models.Person) Contact(io.swagger.models.Contact) Test(org.testng.annotations.Test)

Example 2 with RefParameter

use of io.swagger.models.parameters.RefParameter in project swagger-parser by swagger-api.

the class SwaggerResolverTest method testOperationBodyParameterRemoteRefs.

// (description = "resolve operation body parameter remote refs")
@org.junit.Test
public void testOperationBodyParameterRemoteRefs() {
    final ModelImpl schema = new ModelImpl();
    final Swagger swagger = new Swagger();
    swagger.path("/fun", new Path().get(new Operation().parameter(new RefParameter("#/parameters/SampleParameter"))));
    swagger.path("/times", new Path().get(new Operation().parameter(new RefParameter("#/parameters/SampleParameter"))));
    swagger.parameter("SampleParameter", new BodyParameter().name("skip").schema(schema));
    final Swagger resolved = new SwaggerResolver(swagger, null).resolve();
    final List<Parameter> params = swagger.getPaths().get("/fun").getGet().getParameters();
    assertEquals(params.size(), 1);
    final BodyParameter param = (BodyParameter) params.get(0);
    assertEquals(param.getName(), "skip");
}
Also used : RefParameter(io.swagger.models.parameters.RefParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) RefParameter(io.swagger.models.parameters.RefParameter) BodyParameter(io.swagger.models.parameters.BodyParameter)

Example 3 with RefParameter

use of io.swagger.models.parameters.RefParameter in project swagger-parser by swagger-api.

the class SwaggerResolverTest method testSharedSwaggerParametersTest.

@Test(description = "resolve top-level parameters")
public void testSharedSwaggerParametersTest() {
    final Swagger swagger = new Swagger();
    swagger.path("/fun", new Path().get(new Operation().parameter(new RefParameter("username")).response(200, new Response().description("ok!"))));
    swagger.parameter("username", new QueryParameter().name("username").property(new StringProperty()));
    final Swagger resolved = new SwaggerResolver(swagger, null).resolve();
    assertTrue(resolved.getParameters().size() == 1);
    assertTrue(resolved.getPaths().get("/fun").getGet().getParameters().size() == 1);
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) RefParameter(io.swagger.models.parameters.RefParameter) Test(org.testng.annotations.Test)

Example 4 with RefParameter

use of io.swagger.models.parameters.RefParameter in project swagger-parser by swagger-api.

the class SwaggerConverter method isRefABodyParam.

private boolean isRefABodyParam(io.swagger.models.parameters.Parameter param) {
    if (param instanceof RefParameter) {
        RefParameter refParameter = (RefParameter) param;
        String simpleRef = refParameter.getSimpleRef();
        io.swagger.models.parameters.Parameter parameter = globalV2Parameters.get(simpleRef);
        return "body".equals(parameter.getIn());
    }
    return false;
}
Also used : RefParameter(io.swagger.models.parameters.RefParameter)

Example 5 with RefParameter

use of io.swagger.models.parameters.RefParameter in project swagger-parser by swagger-api.

the class SwaggerConverter method isRefAFormParam.

private boolean isRefAFormParam(io.swagger.models.parameters.Parameter param) {
    if (param instanceof RefParameter) {
        RefParameter refParameter = (RefParameter) param;
        String simpleRef = refParameter.getSimpleRef();
        io.swagger.models.parameters.Parameter parameter = globalV2Parameters.get(simpleRef);
        return "formData".equals(parameter.getIn());
    }
    return false;
}
Also used : RefParameter(io.swagger.models.parameters.RefParameter)

Aggregations

RefParameter (io.swagger.models.parameters.RefParameter)11 BodyParameter (io.swagger.models.parameters.BodyParameter)5 Test (org.testng.annotations.Test)5 QueryParameter (io.swagger.models.parameters.QueryParameter)4 Parameter (io.swagger.models.parameters.Parameter)3 Model (io.swagger.models.Model)2 AbstractSerializableParameter (io.swagger.models.parameters.AbstractSerializableParameter)2 PathParameter (io.swagger.models.parameters.PathParameter)2 SerializableParameter (io.swagger.models.parameters.SerializableParameter)2 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)2 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)2 FileSchema (io.swagger.v3.oas.models.media.FileSchema)2 Schema (io.swagger.v3.oas.models.media.Schema)2 ArrayList (java.util.ArrayList)2 Contact (io.swagger.models.Contact)1 Info (io.swagger.models.Info)1 Operation (io.swagger.models.Operation)1 Path (io.swagger.models.Path)1 Person (io.swagger.models.Person)1 RefModel (io.swagger.models.RefModel)1