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));
}
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");
}
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);
}
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;
}
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;
}
Aggregations