Java Code Examples for io.swagger.v3.oas.models.PathItem#getParameters()

The following examples show how to use io.swagger.v3.oas.models.PathItem#getParameters() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CallbackProcessor.java    From swagger-parser with Apache License 2.0 6 votes vote down vote up
public void processCallback(Callback callback) {
    if (callback.get$ref() != null){
        processReferenceCallback(callback);
    }
    //Resolver PathItem
    for(String name : callback.keySet()){
        PathItem pathItem = callback.get(name);
        final Map<PathItem.HttpMethod, Operation> operationMap = pathItem.readOperationsMap();

        for (PathItem.HttpMethod httpMethod : operationMap.keySet()) {
            Operation operation = operationMap.get(httpMethod);
            operationProcessor.processOperation(operation);
        }

        List<Parameter> parameters = pathItem.getParameters();
        if (parameters != null) {
            for (Parameter parameter: parameters){
                parameterProcessor.processParameter(parameter);
            }
        }
    }
}
 
Example 2
Source File: PathsProcessor.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
private void addParametersToEachOperation(PathItem pathItem) {
    if (settings.addParametersToEachOperation()) {
        List<Parameter> parameters = pathItem.getParameters();

        if (parameters != null) {
            // add parameters to each operation
            List<Operation> operations = pathItem.readOperations();
            if (operations != null) {
                for (Operation operation : operations) {
                    List<Parameter> parametersToAdd = new ArrayList<>();
                    List<Parameter> existingParameters = operation.getParameters();
                    if (existingParameters == null) {
                        existingParameters = new ArrayList<>();
                        operation.setParameters(existingParameters);
                    }
                    for (Parameter parameterToAdd : parameters) {
                        boolean matched = false;
                        for (Parameter existingParameter : existingParameters) {
                            if (parameterToAdd.getIn() != null && parameterToAdd.getIn().equals(existingParameter.getIn()) &&
                                    parameterToAdd.getName().equals(existingParameter.getName())) {
                                matched = true;
                            }
                        }
                        if (!matched) {
                            parametersToAdd.add(parameterToAdd);
                        }
                    }
                    if (parametersToAdd.size() > 0) {
                        operation.getParameters().addAll(0, parametersToAdd);
                    }
                }
            }
        }
        // remove the shared parameters
        pathItem.setParameters(null);
    }
}
 
Example 3
Source File: OpenAPI3RouterFactoryImpl.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
private OperationValue(HttpMethod method, String path, Operation operationModel, PathItem pathModel) {
  this.method = method;
  this.path = path;
  this.pathModel = pathModel;
  this.operationModel = operationModel;
  this.tags = operationModel.getTags();
  // Merge parameters
  List<Parameter> opParams = operationModel.getParameters()==null ? new ArrayList<>() : operationModel.getParameters();
  List<Parameter> parentParams = pathModel.getParameters() == null ? new ArrayList<>() : pathModel.getParameters();
  this.parameters = OpenApi3Utils.mergeParameters(opParams, parentParams);
  this.userHandlers = new ArrayList<>();
  this.userFailureHandlers = new ArrayList<>();
}
 
Example 4
Source File: PathItemParametersValidator.java    From servicecomb-toolkit with Apache License 2.0 4 votes vote down vote up
@Override
protected List<Parameter> getListProperty(PathItem oasObject) {
  return oasObject.getParameters();
}
 
Example 5
Source File: PathItemParametersDiffValidator.java    From servicecomb-toolkit with Apache License 2.0 4 votes vote down vote up
@Override
protected List<Parameter> getListProperty(PathItem oasObject) {
  return oasObject.getParameters();
}
 
Example 6
Source File: OpenAPIV3ParserTest.java    From swagger-parser with Apache License 2.0 4 votes vote down vote up
private OpenAPI doRelativeFileTest(String location) {
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult readResult = parser.readLocation(location, null, options);

    if (readResult.getMessages().size() > 0) {
        Json.prettyPrint(readResult.getMessages());
    }
    final OpenAPI openAPI = readResult.getOpenAPI();
    final PathItem path = openAPI.getPaths().get("/health");
    assertEquals(path.getClass(), PathItem.class); //we successfully converted the RefPath to a Path

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

    final Map<String, ApiResponse> responsesMap = operation.getResponses();

    assertResponse(openAPI, responsesMap, "200","application/json", "Health information from the server", "#/components/schemas/health");
    assertResponse(openAPI, responsesMap, "400","*/*", "Your request was not valid", "#/components/schemas/error");
    assertResponse(openAPI, responsesMap, "500","*/*", "An unexpected error occur during processing", "#/components/schemas/error");

    final Map<String, Schema> definitions = openAPI.getComponents().getSchemas();
    final Schema refInDefinitions = definitions.get("refInDefinitions");
    assertEquals(refInDefinitions.getDescription(), "The example model");
    expectedPropertiesInModel(refInDefinitions, "foo", "bar");

    final ArraySchema arrayModel = (ArraySchema) definitions.get("arrayModel");
    final Schema arrayModelItems = arrayModel.getItems();
    assertEquals(arrayModelItems.get$ref(), "#/components/schemas/foo");

    final Schema fooModel = definitions.get("foo");
    assertEquals(fooModel.getDescription(), "Just another model");
    expectedPropertiesInModel(fooModel, "hello", "world");

    final ComposedSchema composedCat = (ComposedSchema) definitions.get("composedCat");
    final Schema child =  composedCat.getAllOf().get(2);
    expectedPropertiesInModel(child, "huntingSkill", "prop2", "reflexes", "reflexMap");
    final ArraySchema reflexes = (ArraySchema) child.getProperties().get("reflexes");
    final Schema reflexItems = reflexes.getItems();
    assertEquals(reflexItems.get$ref(), "#/components/schemas/reflex");
    assertTrue(definitions.containsKey(reflexItems.get$ref().substring(reflexItems.get$ref().lastIndexOf("/")+1)));

    final Schema reflexMap = (Schema) child.getProperties().get("reflexMap");
    final Schema reflexMapAdditionalProperties = (Schema) reflexMap.getAdditionalProperties();
    assertEquals(reflexMapAdditionalProperties.get$ref(), "#/components/schemas/reflex");

    assertEquals(composedCat.getAllOf().size(), 3);
    assertEquals(composedCat.getAllOf().get(0).get$ref(), "#/components/schemas/pet");
    assertEquals(composedCat.getAllOf().get(1).get$ref(), "#/components/schemas/foo_2");

    return openAPI;
}