Search in sources :

Example 16 with RefProperty

use of io.swagger.models.properties.RefProperty in project swagger-parser by swagger-api.

the class FileReferenceTests method testIssue316.

@Test
public void testIssue316() {
    SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("./src/test/resources/nested-file-references/issue-316.yaml", null, true);
    assertNotNull(result.getSwagger());
    Swagger swagger = result.getSwagger();
    assertNotNull(swagger.getPath("/events"));
    Path path = swagger.getPath("/events");
    assertNotNull(path.getGet());
    Operation get = path.getGet();
    assertEquals(get.getOperationId(), "getEvents");
    assertTrue(swagger.getDefinitions().size() == 3);
    assertTrue(swagger.getDefinitions().get("Foobar").getProperties().size() == 1);
    assertTrue(swagger.getDefinitions().get("StatusResponse").getProperties().size() == 1);
    assertTrue(swagger.getDefinitions().get("Paging2").getProperties().size() == 2);
    Model model = swagger.getDefinitions().get("Paging2");
    Property property = model.getProperties().get("foobar");
    assertTrue(property instanceof RefProperty);
    RefProperty ref = (RefProperty) property;
    assertEquals(ref.get$ref(), "#/definitions/Foobar");
}
Also used : SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) ArrayProperty(io.swagger.models.properties.ArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

Example 17 with RefProperty

use of io.swagger.models.properties.RefProperty in project swagger-parser by swagger-api.

the class FileReferenceTests method testRelativeRefIssue421.

@Test
public void testRelativeRefIssue421() {
    SwaggerDeserializationResult result = new SwaggerParser().readWithInfo("./src/test/resources/main.yaml", null, true);
    assertNotNull(result.getSwagger());
    Swagger swagger = result.getSwagger();
    assertNotNull(swagger);
    assertNotNull(swagger.getPath("pets"));
    assertNotNull(swagger.getPath("pets").getGet());
    assertNotNull(swagger.getPath("pets").getGet().getResponses());
    assertNotNull(swagger.getPath("pets").getGet().getResponses().get("200"));
    assertNotNull(swagger.getPath("pets").getGet().getResponses().get("200").getSchema());
    assertTrue(swagger.getPath("pets").getGet().getResponses().get("200").getSchema() instanceof RefProperty);
    assertEquals(((RefProperty) swagger.getPath("pets").getGet().getResponses().get("200").getSchema()).get$ref(), "#/definitions/Pet");
    assertTrue(swagger.getDefinitions().get("Pet") instanceof ModelImpl);
    assertTrue(swagger.getDefinitions().get("Pet").getProperties().size() == 2);
}
Also used : SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

Example 18 with RefProperty

use of io.swagger.models.properties.RefProperty in project swagger-parser by swagger-api.

the class NetworkReferenceTests method testIssue411.

@Test
public void testIssue411() throws Exception {
    final List<AuthorizationValue> auths = new ArrayList<>();
    AuthorizationValue auth = new AuthorizationValue("Authorization", "OMG_SO_SEKR3T", "header");
    auths.add(auth);
    new Expectations() {

        {
            remoteUrl.urlToString("http://remote1/resources/swagger.json", auths);
            result = issue_411_server;
            remoteUrl.urlToString("http://remote2/resources/foo", auths);
            result = issue_411_components;
        }
    };
    SwaggerParser parser = new SwaggerParser();
    SwaggerDeserializationResult result = parser.readWithInfo("http://remote1/resources/swagger.json", auths, true);
    Json.prettyPrint(result);
    Swagger swagger = result.getSwagger();
    assertNotNull(swagger.getPath("/health"));
    Path health = swagger.getPath("/health");
    assertTrue(health.getGet().getParameters().size() == 0);
    Object responseRef = health.getGet().getResponses().get("200").getSchema();
    assertTrue(responseRef instanceof RefProperty);
    RefProperty refProperty = (RefProperty) responseRef;
    assertEquals(refProperty.get$ref(), "#/definitions/Success");
    assertNotNull(swagger.getDefinitions().get("Success"));
    Parameter param = swagger.getPath("/stuff").getGet().getParameters().get(0);
    assertEquals(param.getIn(), "query");
    assertEquals(param.getName(), "skip");
    Response response = swagger.getPath("/stuff").getGet().getResponses().get("200");
    assertNotNull(response);
    assertTrue(response.getSchema() instanceof StringProperty);
    Response error = swagger.getPath("/stuff").getGet().getResponses().get("400");
    assertNotNull(error);
    Property errorProp = error.getSchema();
    assertNotNull(errorProp);
    assertTrue(errorProp instanceof RefProperty);
    RefProperty errorProperty = (RefProperty) errorProp;
    assertEquals(errorProperty.get$ref(), "#/definitions/Error");
    assertTrue(swagger.getDefinitions().get("Error") instanceof ModelImpl);
}
Also used : Expectations(mockit.Expectations) Path(io.swagger.models.Path) SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) ArrayList(java.util.ArrayList) StringProperty(io.swagger.models.properties.StringProperty) RefProperty(io.swagger.models.properties.RefProperty) Response(io.swagger.models.Response) AuthorizationValue(io.swagger.models.auth.AuthorizationValue) Swagger(io.swagger.models.Swagger) Parameter(io.swagger.models.parameters.Parameter) ModelImpl(io.swagger.models.ModelImpl) StringProperty(io.swagger.models.properties.StringProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 19 with RefProperty

use of io.swagger.models.properties.RefProperty in project swagger-parser by swagger-api.

the class SwaggerParserTest method testIssue286.

@Test
public void testIssue286() {
    SwaggerParser parser = new SwaggerParser();
    Swagger swagger = parser.read("issue_286.yaml");
    Property response = swagger.getPath("/").getGet().getResponses().get("200").getSchema();
    assertTrue(response instanceof RefProperty);
    assertEquals(((RefProperty) response).getSimpleRef(), "issue_286_PetList");
    assertNotNull(swagger.getDefinitions().get("issue_286_Allergy"));
}
Also used : Swagger(io.swagger.models.Swagger) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) MapProperty(io.swagger.models.properties.MapProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

Example 20 with RefProperty

use of io.swagger.models.properties.RefProperty in project swagger-parser by swagger-api.

the class SwaggerParserTest method doRelativeFileTest.

private Swagger doRelativeFileTest(String location) {
    SwaggerParser parser = new SwaggerParser();
    SwaggerDeserializationResult readResult = parser.readWithInfo(location, null, true);
    if (readResult.getMessages().size() > 0) {
        Json.prettyPrint(readResult.getMessages());
    }
    final Swagger swagger = readResult.getSwagger();
    final Path path = swagger.getPath("/health");
    // we successfully converted the RefPath to a Path
    assertEquals(path.getClass(), Path.class);
    final List<Parameter> parameters = path.getParameters();
    assertParamDetails(parameters, 0, QueryParameter.class, "param1", "query");
    assertParamDetails(parameters, 1, HeaderParameter.class, "param2", "header");
    final Operation operation = path.getGet();
    final List<Parameter> operationParams = operation.getParameters();
    assertParamDetails(operationParams, 0, PathParameter.class, "param3", "path");
    assertParamDetails(operationParams, 1, HeaderParameter.class, "param4", "header");
    assertParamDetails(operationParams, 2, BodyParameter.class, "body", "body");
    final BodyParameter bodyParameter = (BodyParameter) operationParams.get(2);
    assertEquals(((RefModel) bodyParameter.getSchema()).get$ref(), "#/definitions/health");
    final Map<String, Response> responsesMap = operation.getResponses();
    assertResponse(swagger, responsesMap, "200", "Health information from the server", "#/definitions/health");
    assertResponse(swagger, responsesMap, "400", "Your request was not valid", "#/definitions/error");
    assertResponse(swagger, responsesMap, "500", "An unexpected error occur during processing", "#/definitions/error");
    final Map<String, Model> definitions = swagger.getDefinitions();
    final ModelImpl refInDefinitions = (ModelImpl) definitions.get("refInDefinitions");
    assertEquals(refInDefinitions.getDescription(), "The example model");
    expectedPropertiesInModel(refInDefinitions, "foo", "bar");
    final ArrayModel arrayModel = (ArrayModel) definitions.get("arrayModel");
    final RefProperty arrayModelItems = (RefProperty) arrayModel.getItems();
    assertEquals(arrayModelItems.get$ref(), "#/definitions/foo");
    final ModelImpl fooModel = (ModelImpl) definitions.get("foo");
    assertEquals(fooModel.getDescription(), "Just another model");
    expectedPropertiesInModel(fooModel, "hello", "world");
    final ComposedModel composedCat = (ComposedModel) definitions.get("composedCat");
    final ModelImpl child = (ModelImpl) composedCat.getChild();
    expectedPropertiesInModel(child, "huntingSkill", "prop2", "reflexes", "reflexMap");
    final ArrayProperty reflexes = (ArrayProperty) child.getProperties().get("reflexes");
    final RefProperty reflexItems = (RefProperty) reflexes.getItems();
    assertEquals(reflexItems.get$ref(), "#/definitions/reflex");
    assertTrue(definitions.containsKey(reflexItems.getSimpleRef()));
    final MapProperty reflexMap = (MapProperty) child.getProperties().get("reflexMap");
    final RefProperty reflexMapAdditionalProperties = (RefProperty) reflexMap.getAdditionalProperties();
    assertEquals(reflexMapAdditionalProperties.get$ref(), "#/definitions/reflex");
    assertEquals(composedCat.getInterfaces().size(), 2);
    assertEquals(composedCat.getInterfaces().get(0).get$ref(), "#/definitions/pet");
    assertEquals(composedCat.getInterfaces().get(1).get$ref(), "#/definitions/foo_2");
    return swagger;
}
Also used : Path(io.swagger.models.Path) ArrayProperty(io.swagger.models.properties.ArrayProperty) ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) ComposedModel(io.swagger.models.ComposedModel) MapProperty(io.swagger.models.properties.MapProperty) Operation(io.swagger.models.Operation) BodyParameter(io.swagger.models.parameters.BodyParameter) RefProperty(io.swagger.models.properties.RefProperty) Response(io.swagger.models.Response) Swagger(io.swagger.models.Swagger) Model(io.swagger.models.Model) RefModel(io.swagger.models.RefModel) ComposedModel(io.swagger.models.ComposedModel) ArrayModel(io.swagger.models.ArrayModel) SerializableParameter(io.swagger.models.parameters.SerializableParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) FormParameter(io.swagger.models.parameters.FormParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) ModelImpl(io.swagger.models.ModelImpl) ArrayModel(io.swagger.models.ArrayModel)

Aggregations

RefProperty (io.swagger.models.properties.RefProperty)74 Property (io.swagger.models.properties.Property)50 ArrayProperty (io.swagger.models.properties.ArrayProperty)46 StringProperty (io.swagger.models.properties.StringProperty)35 Test (org.testng.annotations.Test)35 Model (io.swagger.models.Model)23 MapProperty (io.swagger.models.properties.MapProperty)20 ModelImpl (io.swagger.models.ModelImpl)18 Response (io.swagger.models.Response)18 IntegerProperty (io.swagger.models.properties.IntegerProperty)18 Operation (io.swagger.models.Operation)17 RefModel (io.swagger.models.RefModel)17 LongProperty (io.swagger.models.properties.LongProperty)14 Path (io.swagger.models.Path)12 Swagger (io.swagger.models.Swagger)12 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)12 ArrayModel (io.swagger.models.ArrayModel)11 BodyParameter (io.swagger.models.parameters.BodyParameter)11 Map (java.util.Map)11