Search in sources :

Example 1 with Oas20PathItem

use of io.apicurio.datamodels.openapi.v2.models.Oas20PathItem in project syndesis by syndesisio.

the class CyclicValidationCheckTest method shouldFindTwoStepCyclicReferencesInResponses.

@Test
public void shouldFindTwoStepCyclicReferencesInResponses() {
    final Oas20Document openApiDoc = new Oas20Document();
    final Oas20PathItem pathItem = new Oas20PathItem("/api");
    final Oas20Operation operation = new Oas20Operation("post");
    Oas20Response response = new Oas20Response("200");
    Oas20Schema responseSchema = new Oas20Schema();
    responseSchema.$ref = "#/definitions/A";
    response.schema = responseSchema;
    operation.responses = operation.createResponses();
    operation.responses.addResponse("200", response);
    pathItem.post = operation;
    openApiDoc.paths = openApiDoc.createPaths();
    openApiDoc.paths.addPathItem("/api", pathItem);
    Oas20SchemaDefinition schemaDefinitionA = new Oas20SchemaDefinition("A");
    schemaDefinitionA.type = "object";
    Oas20Schema propertySchemaA = new Oas20Schema();
    propertySchemaA.$ref = "#/definitions/B";
    schemaDefinitionA.properties = new HashMap<>();
    schemaDefinitionA.properties.put("b", propertySchemaA);
    openApiDoc.definitions = openApiDoc.createDefinitions();
    openApiDoc.definitions.addDefinition("A", schemaDefinitionA);
    Oas20SchemaDefinition schemaDefinitionB = new Oas20SchemaDefinition("B");
    schemaDefinitionB.type = "object";
    Oas20Schema propertySchemaB = new Oas20Schema();
    propertySchemaB.$ref = "#/definitions/A";
    schemaDefinitionB.properties = new HashMap<>();
    schemaDefinitionB.properties.put("a", propertySchemaB);
    openApiDoc.definitions.addDefinition("B", schemaDefinitionB);
    assertThat(CyclicValidationCheck.hasCyclicReferences(getSchemaDefinitions(openApiDoc))).isTrue();
}
Also used : Oas20Schema(io.apicurio.datamodels.openapi.v2.models.Oas20Schema) Oas20Document(io.apicurio.datamodels.openapi.v2.models.Oas20Document) Oas20PathItem(io.apicurio.datamodels.openapi.v2.models.Oas20PathItem) Oas20Operation(io.apicurio.datamodels.openapi.v2.models.Oas20Operation) Oas20Response(io.apicurio.datamodels.openapi.v2.models.Oas20Response) Oas20SchemaDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20SchemaDefinition) Test(org.junit.Test)

Example 2 with Oas20PathItem

use of io.apicurio.datamodels.openapi.v2.models.Oas20PathItem in project syndesis by syndesisio.

the class CyclicValidationCheckTest method shouldFindThreeStepCyclicReferencesInParameters.

@Test
public void shouldFindThreeStepCyclicReferencesInParameters() {
    final Oas20Document openApiDoc = new Oas20Document();
    final Oas20PathItem pathItem = new Oas20PathItem("/api");
    final Oas20Operation operation = new Oas20Operation("post");
    final Oas20Parameter parameter = new Oas20Parameter();
    parameter.$ref = "#/definitions/A";
    operation.parameters = new ArrayList<>();
    operation.parameters.add(parameter);
    pathItem.post = operation;
    openApiDoc.paths = openApiDoc.createPaths();
    openApiDoc.paths.addPathItem("/api", pathItem);
    Oas20SchemaDefinition schemaDefinitionA = new Oas20SchemaDefinition("A");
    schemaDefinitionA.type = "object";
    Oas20Schema propertySchemaA = new Oas20Schema();
    propertySchemaA.$ref = "#/definitions/B";
    schemaDefinitionA.properties = new HashMap<>();
    schemaDefinitionA.properties.put("b", propertySchemaA);
    openApiDoc.definitions = openApiDoc.createDefinitions();
    openApiDoc.definitions.addDefinition("A", schemaDefinitionA);
    Oas20SchemaDefinition schemaDefinitionB = new Oas20SchemaDefinition("B");
    schemaDefinitionB.type = "object";
    Oas20Schema propertySchemaB = new Oas20Schema();
    propertySchemaB.$ref = "#/definitions/C";
    schemaDefinitionB.properties = new HashMap<>();
    schemaDefinitionB.properties.put("c", propertySchemaB);
    openApiDoc.definitions.addDefinition("B", schemaDefinitionB);
    Oas20SchemaDefinition schemaDefinitionC = new Oas20SchemaDefinition("C");
    schemaDefinitionC.type = "object";
    Oas20Schema propertySchemaC = new Oas20Schema();
    propertySchemaC.$ref = "#/definitions/A";
    schemaDefinitionC.properties = new HashMap<>();
    schemaDefinitionC.properties.put("a", propertySchemaC);
    openApiDoc.definitions.addDefinition("C", schemaDefinitionC);
    assertThat(CyclicValidationCheck.hasCyclicReferences(getSchemaDefinitions(openApiDoc))).isTrue();
}
Also used : Oas20Schema(io.apicurio.datamodels.openapi.v2.models.Oas20Schema) Oas20Document(io.apicurio.datamodels.openapi.v2.models.Oas20Document) Oas20PathItem(io.apicurio.datamodels.openapi.v2.models.Oas20PathItem) Oas20Operation(io.apicurio.datamodels.openapi.v2.models.Oas20Operation) Oas20SchemaDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20SchemaDefinition) Oas20Parameter(io.apicurio.datamodels.openapi.v2.models.Oas20Parameter) Test(org.junit.Test)

Example 3 with Oas20PathItem

use of io.apicurio.datamodels.openapi.v2.models.Oas20PathItem in project syndesis by syndesisio.

the class CyclicValidationCheckTest method shouldFindMultipleStepCyclicReferencesInParameters.

@Test
public void shouldFindMultipleStepCyclicReferencesInParameters() {
    final Oas20Document openApiDoc = new Oas20Document();
    final Oas20PathItem pathItem = new Oas20PathItem("/api");
    final Oas20Operation operation = new Oas20Operation("post");
    final Oas20Parameter parameter = new Oas20Parameter();
    parameter.$ref = "#/definitions/A";
    operation.parameters = new ArrayList<>();
    operation.parameters.add(parameter);
    pathItem.post = operation;
    openApiDoc.paths = openApiDoc.createPaths();
    openApiDoc.paths.addPathItem("/api", pathItem);
    openApiDoc.definitions = openApiDoc.createDefinitions();
    for (int c = 'A'; c < 'Z'; c++) {
        final String current = String.valueOf((char) c);
        final String next = String.valueOf((char) (c + 1));
        Oas20SchemaDefinition schemaDefinition = new Oas20SchemaDefinition(current);
        schemaDefinition.type = "object";
        Oas20Schema propertySchema = new Oas20Schema();
        propertySchema.$ref = "#/definitions/" + next;
        schemaDefinition.properties = new HashMap<>();
        schemaDefinition.properties.put(next, propertySchema);
        openApiDoc.definitions.addDefinition(current, schemaDefinition);
    }
    Oas20SchemaDefinition schemaDefinition = new Oas20SchemaDefinition("Z");
    schemaDefinition.type = "object";
    Oas20Schema propertySchema = new Oas20Schema();
    propertySchema.$ref = "#/definitions/A";
    schemaDefinition.properties = new HashMap<>();
    schemaDefinition.properties.put("a", propertySchema);
    openApiDoc.definitions.addDefinition("Z", schemaDefinition);
    assertThat(CyclicValidationCheck.hasCyclicReferences(getSchemaDefinitions(openApiDoc))).isTrue();
}
Also used : Oas20Schema(io.apicurio.datamodels.openapi.v2.models.Oas20Schema) Oas20Document(io.apicurio.datamodels.openapi.v2.models.Oas20Document) Oas20PathItem(io.apicurio.datamodels.openapi.v2.models.Oas20PathItem) Oas20Operation(io.apicurio.datamodels.openapi.v2.models.Oas20Operation) Oas20SchemaDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20SchemaDefinition) Oas20Parameter(io.apicurio.datamodels.openapi.v2.models.Oas20Parameter) Test(org.junit.Test)

Example 4 with Oas20PathItem

use of io.apicurio.datamodels.openapi.v2.models.Oas20PathItem in project syndesis by syndesisio.

the class CyclicValidationCheckTest method shouldFindNoCyclicReferencesWhenThereAreNone.

@Test
public void shouldFindNoCyclicReferencesWhenThereAreNone() {
    final Oas20Document openApiDoc = new Oas20Document();
    final Oas20PathItem pathItem = new Oas20PathItem("/api");
    final Oas20Operation operation = new Oas20Operation("post");
    final Oas20Parameter parameter = new Oas20Parameter();
    parameter.$ref = "#/definitions/Request";
    operation.parameters = new ArrayList<>();
    operation.parameters.add(parameter);
    Oas20Response response = new Oas20Response("200");
    Oas20Schema responseSchema = new Oas20Schema();
    responseSchema.$ref = "#/definitions/Response";
    response.schema = responseSchema;
    operation.responses = operation.createResponses();
    operation.responses.addResponse("200", response);
    pathItem.post = operation;
    openApiDoc.paths = openApiDoc.createPaths();
    openApiDoc.paths.addPathItem("/api", pathItem);
    Oas20SchemaDefinition requestSchemaDefinition = new Oas20SchemaDefinition("Request");
    requestSchemaDefinition.type = "object";
    Oas20Schema requestPropertySchema = new Oas20Schema();
    requestPropertySchema.type = "integer";
    requestPropertySchema.format = "int32";
    requestSchemaDefinition.properties = new HashMap<>();
    requestSchemaDefinition.properties.put("reqval", requestPropertySchema);
    openApiDoc.definitions = openApiDoc.createDefinitions();
    openApiDoc.definitions.addDefinition("Request", requestSchemaDefinition);
    Oas20SchemaDefinition responseSchemaDefinition = new Oas20SchemaDefinition("Response");
    responseSchemaDefinition.type = "object";
    Oas20Schema responsePropertySchema = new Oas20Schema();
    responsePropertySchema.type = "integer";
    responsePropertySchema.format = "int32";
    responseSchemaDefinition.properties = new HashMap<>();
    responseSchemaDefinition.properties.put("resval", responsePropertySchema);
    openApiDoc.definitions.addDefinition("Request", responseSchemaDefinition);
    assertThat(CyclicValidationCheck.hasCyclicReferences(getSchemaDefinitions(openApiDoc))).isFalse();
}
Also used : Oas20Schema(io.apicurio.datamodels.openapi.v2.models.Oas20Schema) Oas20Document(io.apicurio.datamodels.openapi.v2.models.Oas20Document) Oas20PathItem(io.apicurio.datamodels.openapi.v2.models.Oas20PathItem) Oas20Operation(io.apicurio.datamodels.openapi.v2.models.Oas20Operation) Oas20Response(io.apicurio.datamodels.openapi.v2.models.Oas20Response) Oas20SchemaDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20SchemaDefinition) Oas20Parameter(io.apicurio.datamodels.openapi.v2.models.Oas20Parameter) Test(org.junit.Test)

Example 5 with Oas20PathItem

use of io.apicurio.datamodels.openapi.v2.models.Oas20PathItem in project syndesis by syndesisio.

the class CyclicValidationCheckTest method shouldFindTwoStepCyclicReferencesInParameters.

@Test
public void shouldFindTwoStepCyclicReferencesInParameters() {
    final Oas20Document openApiDoc = new Oas20Document();
    final Oas20PathItem pathItem = new Oas20PathItem("/api");
    final Oas20Operation operation = new Oas20Operation("post");
    final Oas20Parameter parameter = new Oas20Parameter();
    parameter.$ref = "#/definitions/A";
    operation.parameters = new ArrayList<>();
    operation.parameters.add(parameter);
    pathItem.post = operation;
    openApiDoc.paths = openApiDoc.createPaths();
    openApiDoc.paths.addPathItem("/api", pathItem);
    Oas20SchemaDefinition schemaDefinitionA = new Oas20SchemaDefinition("A");
    schemaDefinitionA.type = "object";
    Oas20Schema propertySchemaA = new Oas20Schema();
    propertySchemaA.$ref = "#/definitions/B";
    schemaDefinitionA.properties = new HashMap<>();
    schemaDefinitionA.properties.put("b", propertySchemaA);
    openApiDoc.definitions = openApiDoc.createDefinitions();
    openApiDoc.definitions.addDefinition("A", schemaDefinitionA);
    Oas20SchemaDefinition schemaDefinitionB = new Oas20SchemaDefinition("B");
    schemaDefinitionB.type = "object";
    Oas20Schema propertySchemaB = new Oas20Schema();
    propertySchemaB.$ref = "#/definitions/A";
    schemaDefinitionB.properties = new HashMap<>();
    schemaDefinitionB.properties.put("a", propertySchemaB);
    openApiDoc.definitions.addDefinition("B", schemaDefinitionB);
    assertThat(CyclicValidationCheck.hasCyclicReferences(getSchemaDefinitions(openApiDoc))).isTrue();
}
Also used : Oas20Schema(io.apicurio.datamodels.openapi.v2.models.Oas20Schema) Oas20Document(io.apicurio.datamodels.openapi.v2.models.Oas20Document) Oas20PathItem(io.apicurio.datamodels.openapi.v2.models.Oas20PathItem) Oas20Operation(io.apicurio.datamodels.openapi.v2.models.Oas20Operation) Oas20SchemaDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20SchemaDefinition) Oas20Parameter(io.apicurio.datamodels.openapi.v2.models.Oas20Parameter) Test(org.junit.Test)

Aggregations

Oas20Document (io.apicurio.datamodels.openapi.v2.models.Oas20Document)18 Oas20PathItem (io.apicurio.datamodels.openapi.v2.models.Oas20PathItem)18 Test (org.junit.Test)17 Oas20Operation (io.apicurio.datamodels.openapi.v2.models.Oas20Operation)15 Oas20Schema (io.apicurio.datamodels.openapi.v2.models.Oas20Schema)12 Oas20Parameter (io.apicurio.datamodels.openapi.v2.models.Oas20Parameter)10 Oas20SchemaDefinition (io.apicurio.datamodels.openapi.v2.models.Oas20SchemaDefinition)9 OpenApiModelInfo (io.syndesis.server.api.generator.openapi.OpenApiModelInfo)8 Oas20Response (io.apicurio.datamodels.openapi.v2.models.Oas20Response)6 Violation (io.syndesis.common.model.Violation)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)1 Connector (io.syndesis.common.model.connection.Connector)1