Search in sources :

Example 6 with RefParameter

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

the class FileReferenceTests method testIssue421.

@Test
public void testIssue421() {
    SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("./src/test/resources/nested-file-references/issue-421.yaml", null, true);
    assertNotNull(result.getSwagger());
    Swagger swagger = result.getSwagger();
    assertNotNull(swagger.getPath("/pet/{petId}"));
    assertNotNull(swagger.getPath("/pet/{petId}").getGet());
    assertNotNull(swagger.getPath("/pet/{petId}").getGet().getParameters());
    assertTrue(swagger.getPath("/pet/{petId}").getGet().getParameters().size() == 1);
    assertTrue(swagger.getPath("/pet/{petId}").getGet().getParameters().get(0).getName().equals("petId"));
    assertTrue(swagger.getDefinitions().get("Pet") instanceof ModelImpl);
    assertTrue(swagger.getDefinitions().get("Pet").getProperties().size() == 6);
    assertNotNull(swagger.getPath("/pet/{petId}").getPost());
    assertNotNull(swagger.getPath("/pet/{petId}").getPost().getParameters());
    assertTrue(swagger.getPath("/pet/{petId}").getPost().getParameters().size() == 3);
    assertTrue(swagger.getPath("/pet/{petId}").getPost().getParameters().get(1) instanceof RefParameter);
    assertTrue(((RefParameter) swagger.getPath("/pet/{petId}").getPost().getParameters().get(1)).getRefFormat() == RefFormat.INTERNAL);
    assertTrue(((RefParameter) swagger.getPath("/pet/{petId}").getPost().getParameters().get(1)).getSimpleRef().equals("name"));
    assertNotNull(swagger.getPath("/store/order"));
    assertNotNull(swagger.getPath("/store/order").getPost());
    assertNotNull(swagger.getPath("/store/order").getPost().getParameters());
    assertTrue(swagger.getPath("/store/order").getPost().getParameters().size() == 1);
    assertTrue(swagger.getPath("/store/order").getPost().getParameters().get(0) instanceof BodyParameter);
    assertNotNull(((BodyParameter) swagger.getPath("/store/order").getPost().getParameters().get(0)).getSchema());
    assertTrue(((BodyParameter) swagger.getPath("/store/order").getPost().getParameters().get(0)).getSchema() instanceof RefModel);
    assertTrue(((RefModel) ((BodyParameter) swagger.getPath("/store/order").getPost().getParameters().get(0)).getSchema()).getSimpleRef().equals("Order"));
    assertTrue(swagger.getDefinitions().get("Order") instanceof ModelImpl);
    assertTrue(swagger.getDefinitions().get("Order").getProperties().size() == 6);
}
Also used : RefParameter(io.swagger.models.parameters.RefParameter) SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) BodyParameter(io.swagger.models.parameters.BodyParameter) Test(org.testng.annotations.Test)

Example 7 with RefParameter

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

the class SwaggerResolverTest method testOperationParameterRemoteRefs.

@Test(description = "resolve operation parameter remote refs")
public void testOperationParameterRemoteRefs() {
    final Swagger swagger = new Swagger();
    swagger.path("/fun", new Path().get(new Operation().parameter(new RefParameter("#/parameters/SampleParameter"))));
    swagger.parameter("SampleParameter", new QueryParameter().name("skip").property(new IntegerProperty()));
    final Swagger resolved = new SwaggerResolver(swagger, null).resolve();
    final List<Parameter> params = swagger.getPaths().get("/fun").getGet().getParameters();
    assertEquals(params.size(), 1);
    final QueryParameter param = (QueryParameter) params.get(0);
    assertEquals(param.getName(), "skip");
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) 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) Test(org.testng.annotations.Test)

Aggregations

RefParameter (io.swagger.models.parameters.RefParameter)7 Test (org.testng.annotations.Test)5 BodyParameter (io.swagger.models.parameters.BodyParameter)4 QueryParameter (io.swagger.models.parameters.QueryParameter)4 Parameter (io.swagger.models.parameters.Parameter)3 Model (io.swagger.models.Model)2 PathParameter (io.swagger.models.parameters.PathParameter)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 Swagger (io.swagger.models.Swagger)1 ApiKeyAuthDefinition (io.swagger.models.auth.ApiKeyAuthDefinition)1 LongProperty (io.swagger.models.properties.LongProperty)1 SwaggerDeserializationResult (io.swagger.parser.util.SwaggerDeserializationResult)1 ArrayList (java.util.ArrayList)1