Search in sources :

Example 21 with Parameter

use of com.reprezen.kaizen.oasparser.model3.Parameter in project ets-ogcapi-edr10 by opengeospatial.

the class OpenApiUtils method collectTemplateReplacements.

private static List<Map<String, String>> collectTemplateReplacements(PathItemAndServer pathItemAndServer, UriTemplate uriTemplate) {
    List<Map<String, String>> templateReplacements = new ArrayList<>();
    Collection<Parameter> parameters = pathItemAndServer.operationObject.getParameters();
    for (String templateVariable : uriTemplate.getTemplateVariables()) {
        for (Parameter parameter : parameters) {
            if (templateVariable.equals(parameter.getName())) {
                Schema schema = parameter.getSchema();
                if (schema.hasEnums()) {
                    addEnumTemplateValues(templateReplacements, templateVariable, schema);
                } else if (schema.getDefault() != null) {
                    addDefaultTemplateValue(templateReplacements, templateVariable, schema);
                } else {
                // TODO: What should be done if the parameter does not have a default value and
                // no
                // enumerated set of valid values?
                }
            }
        }
    }
    return templateReplacements;
}
Also used : Schema(com.reprezen.kaizen.oasparser.model3.Schema) ArrayList(java.util.ArrayList) Parameter(com.reprezen.kaizen.oasparser.model3.Parameter) HashMap(java.util.HashMap) Map(java.util.Map)

Example 22 with Parameter

use of com.reprezen.kaizen.oasparser.model3.Parameter in project ets-ogcapi-edr10 by opengeospatial.

the class CollectionsTime method coordsParameterDefinition.

/**
 * <pre>
 * Abstract Test 38: Validate that the coords query parameters are constructed correctly. (position)
 * Abstract Test 54: Validate that the coords query parameters are constructed correctly. (area)
 * Abstract Test 70: Validate that the coords query parameters are constructed correctly. (cube)
 * Abstract Test 92: Validate that the coords query parameters are constructed correctly. (trajectory)
 * Abstract Test 116: Validate that the coords query parameters are constructed correctly. (corridor)
 * </pre>
 *
 * @param testPoint the testPoint under test, never <code>null</code>
 * @param model api definition, never <code>null</code>
 */
public void coordsParameterDefinition(TestPoint testPoint, OpenApi3 model) {
    Parameter coords = null;
    String paramName = "coords";
    boolean hasCoordsParameter = false;
    for (Path path : model.getPaths().values()) {
        if (path.getPathString().endsWith(testPoint.getPath())) {
            for (Operation op : path.getOperations().values()) {
                for (Parameter param : op.getParameters()) {
                    if (hasName(param)) {
                        if (param.getName().equals(paramName)) {
                            coords = param;
                        }
                    }
                }
            }
        }
    }
    if (!testPoint.getPath().endsWith("/locations")) {
        assertNotNull(coords, "Required " + paramName + " parameter for collections with path '" + testPoint.getPath() + "'  in OpenAPI document is missing");
        if (coords != null) {
            String msg = "Expected property '%s' with value '%s' but was '%s'";
            assertEquals(coords.getName(), paramName, String.format(msg, "name", paramName, coords.getName()));
            assertEquals(coords.getIn(), "query", String.format(msg, "in", "query", coords.getIn()));
            assertTrue(isRequired(coords), String.format(msg, "required", "true", coords.getRequired()));
            // assertEquals( coords.getStyle(), "form", String.format( msg, "style","form",
            // coords.getStyle() ) ); //TODO SHOULD BE Enabled
            assertFalse(isExplode(coords), String.format(msg, "explode", "false", coords.getExplode()));
            Schema schema = coords.getSchema();
            assertEquals(schema.getType(), "string", String.format(msg, "schema -> type", "string", schema.getType()));
        }
    }
}
Also used : Path(com.reprezen.kaizen.oasparser.model3.Path) Schema(com.reprezen.kaizen.oasparser.model3.Schema) Parameter(com.reprezen.kaizen.oasparser.model3.Parameter) Operation(com.reprezen.kaizen.oasparser.model3.Operation)

Example 23 with Parameter

use of com.reprezen.kaizen.oasparser.model3.Parameter in project ets-ogcapi-edr10 by opengeospatial.

the class CollectionsTime method withinUnitsParameterDefinition.

/**
 * <pre>
 * Requirement A.23: /req/edr/within-units-definition Parameter withinUnits
 * definition
 * </pre>
 * NOTE: Not referenced by ATS
 *
 * @param testPoint the testPoint under test, never <code>null</code>
 * @param model api definition, never <code>null</code>
 */
public void withinUnitsParameterDefinition(TestPoint testPoint, OpenApi3 model) {
    Parameter withinUnits = null;
    String paramName = "within-units";
    for (Path path : model.getPaths().values()) {
        if (testPoint.getPath().equals(path.getPathString())) {
            for (Operation op : path.getOperations().values()) {
                for (Parameter param : op.getParameters()) {
                    if (hasName(param)) {
                        if (param.getName().equals(paramName)) {
                            withinUnits = param;
                        }
                    }
                }
            }
        }
    }
    if (withinUnits != null) {
        String msg = "Expected property '%s' with value '%s' but was '%s'";
        assertEquals(withinUnits.getName(), paramName, String.format(msg, "name", paramName, withinUnits.getName()));
        assertEquals(withinUnits.getIn(), "query", String.format(msg, "in", "query", withinUnits.getIn()));
        assertFalse(isRequired(withinUnits), String.format(msg, "required", "false", withinUnits.getRequired()));
        assertEquals(withinUnits.getStyle(), "form", String.format(msg, "style", "form", withinUnits.getStyle()));
        assertFalse(isExplode(withinUnits), String.format(msg, "explode", "false", withinUnits.getExplode()));
    }
}
Also used : Path(com.reprezen.kaizen.oasparser.model3.Path) Parameter(com.reprezen.kaizen.oasparser.model3.Parameter) Operation(com.reprezen.kaizen.oasparser.model3.Operation)

Example 24 with Parameter

use of com.reprezen.kaizen.oasparser.model3.Parameter in project ets-ogcapi-edr10 by opengeospatial.

the class OpenApiUtils method isParameterSupportedForCollection.

public static boolean isParameterSupportedForCollection(OpenApi3 apiModel, String collectionName, String queryParam) {
    String requestedPath = createCollectionPath(collectionName);
    List<Path> paths = identifyTestPoints(apiModel, requestedPath, new PathMatcher());
    for (Path path : paths) {
        Collection<Parameter> parameters = path.getGet().getParameters();
        for (Parameter parameter : parameters) {
            if (queryParam.equalsIgnoreCase(parameter.getName())) {
                return true;
            }
        }
    }
    return false;
}
Also used : Path(com.reprezen.kaizen.oasparser.model3.Path) Parameter(com.reprezen.kaizen.oasparser.model3.Parameter)

Example 25 with Parameter

use of com.reprezen.kaizen.oasparser.model3.Parameter in project ets-ogcapi-edr10 by opengeospatial.

the class OpenApiUtils method isFreeFormParameterSupportedForCollection.

public static boolean isFreeFormParameterSupportedForCollection(OpenApi3 apiModel, String collectionName) {
    String requestedPath = createCollectionPath(collectionName);
    List<Path> paths = identifyTestPoints(apiModel, requestedPath, new PathMatcher());
    for (Path path : paths) {
        Collection<Parameter> parameters = path.getGet().getParameters();
        for (Parameter parameter : parameters) {
            if (parameter.getSchema() != null && parameter.getSchema().isAdditionalProperties()) {
                return true;
            }
        }
    }
    return false;
}
Also used : Path(com.reprezen.kaizen.oasparser.model3.Path) Parameter(com.reprezen.kaizen.oasparser.model3.Parameter)

Aggregations

Parameter (com.reprezen.kaizen.oasparser.model3.Parameter)26 Path (com.reprezen.kaizen.oasparser.model3.Path)17 Operation (com.reprezen.kaizen.oasparser.model3.Operation)13 Schema (com.reprezen.kaizen.oasparser.model3.Schema)7 Parameter (org.osate.aadl2.Parameter)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 DataAccess (org.osate.aadl2.DataAccess)4 FeatureGroup (org.osate.aadl2.FeatureGroup)3 Test (org.testng.annotations.Test)3 Map (java.util.Map)2 Parameter (org.eclipse.jst.server.tomcat.core.internal.xml.server32.Parameter)2 TestPoint (org.opengis.cite.ogcapifeatures10.openapi3.TestPoint)2 AbstractFeature (org.osate.aadl2.AbstractFeature)2 ClassifierValue (org.osate.aadl2.ClassifierValue)2 DataSubcomponent (org.osate.aadl2.DataSubcomponent)2 Port (org.osate.aadl2.Port)2 SubprogramSubcomponent (org.osate.aadl2.SubprogramSubcomponent)2 CobiGenRuntimeException (com.devonfw.cobigen.api.exception.CobiGenRuntimeException)1 ParameterDef (com.devonfw.cobigen.openapiplugin.model.ParameterDef)1