Java Code Examples for io.swagger.v3.oas.models.Operation#setParameters()

The following examples show how to use io.swagger.v3.oas.models.Operation#setParameters() . 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: OpenAPI3ValidationTest.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
@Test
public void testFormURLEncodedCharParameter() throws Exception {
  Operation op = testSpec.getPaths().get("/formTests/urlencodedchar").getPost();
  if(op.getParameters()==null) op.setParameters(new ArrayList<>());
  OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec, refsCache);
  loadHandlers("/formTests/urlencodedchar", HttpMethod.POST, false, validationHandler, (routingContext) -> {
    RequestParameters params = routingContext.get("parsedParameters");
    routingContext.response().setStatusMessage(params.formParameter("name").getString()).end();
  });

  String name = "test+urlencoded+char";

  MultiMap form = MultiMap.caseInsensitiveMultiMap();
  form.add("name", name);

  testRequestWithForm(HttpMethod.POST, "/formTests/urlencodedchar", FormType.FORM_URLENCODED, form, 200, name);
}
 
Example 2
Source File: OpenAPI3ValidationTest.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
@Test
public void testJsonBodyFailure() throws Exception {
  Operation op = testSpec.getPaths().get("/jsonBodyTest/sampleTest").getPost();
  if(op.getParameters()==null) op.setParameters(new ArrayList<>());
  OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec, refsCache);
  loadHandlers("/jsonBodyTest/sampleTest", HttpMethod.POST, true, validationHandler, (routingContext) -> {
    RequestParameters params = routingContext.get("parsedParameters");
    routingContext
      .response()
      .setStatusCode(200)
      .setStatusMessage("OK")
      .putHeader("Content-Type", "application/json")
      .end(params.body().getJsonObject().encode());
  });

  JsonObject object = new JsonObject();
  object.put("id", "anId");

  List<String> valuesArray = new ArrayList<>();
  for (int i = 0; i < 4; i++)
    valuesArray.add(getSuccessSample(ParameterType.INT).getInteger().toString());
  valuesArray.add(2, getFailureSample(ParameterType.INT));
  object.put("values", valuesArray);

  testRequestWithJSON(HttpMethod.POST, "/jsonBodyTest/sampleTest", object.toBuffer(), 400, errorMessage(ValidationException.ErrorType.JSON_INVALID));
}
 
Example 3
Source File: OpenAPI3ValidationTest.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
@Test
public void testFormArrayParameterFailure() throws Exception {
  Operation op = testSpec.getPaths().get("/formTests/arraytest").getPost();
  if(op.getParameters()==null) op.setParameters(new ArrayList<>());
  OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec, refsCache);
  loadHandlers("/formTests/arraytest", HttpMethod.POST, true, validationHandler, (routingContext) -> routingContext.response().setStatusMessage("ok").end());

  String id = "anId";

  List<String> valuesArray = new ArrayList<>();
  for (int i = 0; i < 4; i++)
    valuesArray.add(getSuccessSample(ParameterType.INT).getInteger().toString());
  valuesArray.add(getFailureSample(ParameterType.INT));
  String values = serializeInCSVStringArray(valuesArray);

  MultiMap form = MultiMap.caseInsensitiveMultiMap();
  form.add("id", id);
  form.add("values", values);

  testRequestWithForm(HttpMethod.POST, "/formTests/arraytest", FormType.FORM_URLENCODED, form, 400, errorMessage
    (ValidationException.ErrorType.NO_MATCH));
}
 
Example 4
Source File: OpenAPI3MultipleFilesValidationTest.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
@Test
public void testFormURLEncodedCharParameter() throws Exception {
    Operation op = testSpec.getPaths().get("/formTests/urlencodedchar")
            .getPost();
    if (op.getParameters() == null)
        op.setParameters(new ArrayList<>());
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(
            op, op.getParameters(), testSpec, refsCache);
    loadHandlers("/formTests/urlencodedchar", HttpMethod.POST, false,
            validationHandler, (routingContext) -> {
                RequestParameters params = routingContext
                        .get("parsedParameters");
                routingContext.response()
                        .setStatusMessage(
                                params.formParameter("name").getString())
                        .end();
            });

    String name = "test+urlencoded+char";

    MultiMap form = MultiMap.caseInsensitiveMultiMap();
    form.add("name", name);

    testRequestWithForm(HttpMethod.POST, "/formTests/urlencodedchar",
            FormType.FORM_URLENCODED, form, 200, name);
}
 
Example 5
Source File: AbstractOpenApiResource.java    From springdoc-openapi with Apache License 2.0 6 votes vote down vote up
/**
 * Fill parameters list.
 *
 * @param operation the operation
 * @param queryParams the query params
 * @param methodAttributes the method attributes
 */
private void fillParametersList(Operation operation, Map<String, String> queryParams, MethodAttributes methodAttributes) {
	List<Parameter> parametersList = operation.getParameters();
	if (parametersList == null)
		parametersList = new ArrayList<>();
	Collection<Parameter> headersMap = AbstractRequestBuilder.getHeaders(methodAttributes, new LinkedHashMap<>());
	parametersList.addAll(headersMap);
	if (!CollectionUtils.isEmpty(queryParams)) {
		for (Map.Entry<String, String> entry : queryParams.entrySet()) {
			io.swagger.v3.oas.models.parameters.Parameter parameter = new io.swagger.v3.oas.models.parameters.Parameter();
			parameter.setName(entry.getKey());
			parameter.setSchema(new StringSchema()._default(entry.getValue()));
			parameter.setRequired(true);
			parameter.setIn(ParameterIn.QUERY.toString());
			GenericParameterBuilder.mergeParameter(parametersList, parameter);
		}
		operation.setParameters(parametersList);
	}
}
 
Example 6
Source File: OperationsTransformer.java    From spring-openapi with MIT License 5 votes vote down vote up
private void mapPost(PostMapping postMapping, Method method, Map<String, PathItem> operationsMap, String controllerClassName, String baseControllerPath) {
	Operation operation = new Operation();
	operation.setOperationId(getOperationId(postMapping.name(), method, HttpMethod.POST));
	operation.setSummary(StringUtils.isBlank(postMapping.name()) ? postMapping.name() : method.getName());
	operation.setTags(singletonList(classNameToTag(controllerClassName)));

	operation.setRequestBody(createRequestBody(method, getFirstFromArray(postMapping.consumes())));
	operation.setResponses(createApiResponses(method, getFirstFromArray(postMapping.produces())));
	operation.setParameters(transformParameters(method));

	String path = ObjectUtils.defaultIfNull(getFirstFromArray(postMapping.value()), getFirstFromArray(postMapping.path()));

	operationInterceptors.forEach(interceptor -> interceptor.intercept(method, operation));
	updateOperationsMap(prepareUrl(baseControllerPath, "/", path), operationsMap, pathItem -> pathItem.setPost(operation));
}
 
Example 7
Source File: OperationsTransformer.java    From spring-openapi with MIT License 5 votes vote down vote up
private void mapPut(PutMapping putMapping, Method method, Map<String, PathItem> operationsMap, String controllerClassName, String baseControllerPath) {
	Operation operation = new Operation();
	operation.setOperationId(getOperationId(putMapping.name(), method, HttpMethod.PUT));
	operation.setSummary(StringUtils.isBlank(putMapping.name()) ? putMapping.name() : method.getName());
	operation.setTags(singletonList(classNameToTag(controllerClassName)));

	operation.setRequestBody(createRequestBody(method, getFirstFromArray(putMapping.consumes())));
	operation.setResponses(createApiResponses(method, getFirstFromArray(putMapping.produces())));
	operation.setParameters(transformParameters(method));

	String path = ObjectUtils.defaultIfNull(getFirstFromArray(putMapping.value()), getFirstFromArray(putMapping.path()));

	operationInterceptors.forEach(interceptor -> interceptor.intercept(method, operation));
	updateOperationsMap(prepareUrl(baseControllerPath, "/", path), operationsMap, pathItem -> pathItem.setPut(operation));
}
 
Example 8
Source File: OpenAPI3ValidationTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testJsonBodyFailureErrorMessage() throws Exception {
  Operation op = testSpec.getPaths().get("/jsonBodyTest/sampleTest").getPost();
  if(op.getParameters()==null) op.setParameters(new ArrayList<>());
  OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec, refsCache);
  loadHandlers("/jsonBodyTest/sampleTest", HttpMethod.POST, true, validationHandler, (routingContext) -> {
    RequestParameters params = routingContext.get("parsedParameters");
    routingContext
      .response()
      .setStatusCode(200)
      .setStatusMessage("OK")
      .putHeader("Content-Type", "application/json")
      .end(params.body().getJsonObject().encode());
  }, routingContext -> {
    ValidationException e = (ValidationException) routingContext.failure();
    routingContext
      .response()
      .setStatusCode(400)
      .setStatusMessage(errorMessage(ValidationException.ErrorType.JSON_INVALID))
      .putHeader("Content-Type", "application/json")
      .end(new JsonObject().put("field", e.parameterName()).toBuffer());
  });

  JsonObject object = new JsonObject();
  object.put("id", "anId");

  List<String> valuesArray = new ArrayList<>();
  for (int i = 0; i < 4; i++)
    valuesArray.add(getSuccessSample(ParameterType.INT).getInteger().toString());
  valuesArray.add(0, getFailureSample(ParameterType.INT));
  object.put("values", valuesArray);

  testRequestWithJSON(HttpMethod.POST, "/jsonBodyTest/sampleTest", object.toBuffer(), 400,
    errorMessage(ValidationException.ErrorType.JSON_INVALID),
    new JsonObject().put("field", "body.values[0]").toBuffer());

  testRequestWithJSON(HttpMethod.POST, "/jsonBodyTest/sampleTest", new JsonArray().toBuffer(), 400,
    errorMessage(ValidationException.ErrorType.JSON_INVALID),
    new JsonObject().put("field", "body").toBuffer());
}
 
Example 9
Source File: OpenAPI3ValidationTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testJsonBody() throws Exception {
  Operation op = testSpec.getPaths().get("/jsonBodyTest/sampleTest").getPost();
  if(op.getParameters()==null) op.setParameters(new ArrayList<>());
  OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec, refsCache);
  loadHandlers("/jsonBodyTest/sampleTest", HttpMethod.POST, false, validationHandler, (routingContext) -> {
    RequestParameters params = routingContext.get("parsedParameters");
    routingContext
      .response()
      .setStatusCode(200)
      .setStatusMessage("OK")
      .putHeader("Content-Type", "application/json")
      .end(params.body().getJsonObject().encode());
  });

  JsonObject object = new JsonObject();
  object.put("id", "anId");

  List<Integer> valuesArray = new ArrayList<>();
  for (int i = 0; i < 4; i++)
    valuesArray.add(getSuccessSample(ParameterType.INT).getInteger());
  object.put("values", valuesArray);

  testRequestWithJSON(HttpMethod.POST, "/jsonBodyTest/sampleTest", object.toBuffer(), 200, "OK", object.toBuffer());
  testRequestWithBufferResponse(HttpMethod.POST,
    "/jsonBodyTest/sampleTest",
    "application/json; charset=utf-8",
    object.toBuffer(), 200, "OK", "application/json", b -> assertEquals(object, b.toJsonObject()));
  testRequestWithBufferResponse(HttpMethod.POST,
    "/jsonBodyTest/sampleTest",
    "application/superapplication+json",
    object.toBuffer(), 200, "OK", "application/json", b -> assertEquals(object, b.toJsonObject()));
}
 
Example 10
Source File: OpenAPI3MultipleFilesValidationTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testFormArrayParameter() throws Exception {
    Operation op = testSpec.getPaths().get("/formTests/arraytest")
            .getPost();
    if (op.getParameters() == null)
        op.setParameters(new ArrayList<>());
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(
            op, op.getParameters(), testSpec, refsCache);
    loadHandlers("/formTests/arraytest", HttpMethod.POST, false,
            validationHandler, (routingContext) -> {
                RequestParameters params = routingContext
                        .get("parsedParameters");
                List<String> result = new ArrayList<>();
                for (RequestParameter r : params.formParameter("values")
                        .getArray())
                    result.add(r.getInteger().toString());
                routingContext.response()
                        .setStatusMessage(
                                params.formParameter("id").getString()
                                        + serializeInCSVStringArray(result))
                        .end();
            });

    String id = "anId";

    List<String> valuesArray = new ArrayList<>();
    for (int i = 0; i < 4; i++)
        valuesArray.add(getSuccessSample(ParameterType.INT).getInteger()
                .toString());
    String values = serializeInCSVStringArray(valuesArray);

    MultiMap form = MultiMap.caseInsensitiveMultiMap();
    form.add("id", id);
    form.add("values", values);

    testRequestWithForm(HttpMethod.POST, "/formTests/arraytest",
            FormType.FORM_URLENCODED, form, 200, id + values);
}
 
Example 11
Source File: OpenAPI3MultipleFilesValidationTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testFormArrayParameterFailure() throws Exception {
    Operation op = testSpec.getPaths().get("/formTests/arraytest")
            .getPost();
    if (op.getParameters() == null)
        op.setParameters(new ArrayList<>());
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(
            op, op.getParameters(), testSpec, refsCache);
    loadHandlers("/formTests/arraytest", HttpMethod.POST, true,
            validationHandler, (routingContext) -> routingContext.response()
                    .setStatusMessage("ok").end());

    String id = "anId";

    List<String> valuesArray = new ArrayList<>();
    for (int i = 0; i < 4; i++)
        valuesArray.add(getSuccessSample(ParameterType.INT).getInteger()
                .toString());
    valuesArray.add(getFailureSample(ParameterType.INT));
    String values = serializeInCSVStringArray(valuesArray);

    MultiMap form = MultiMap.caseInsensitiveMultiMap();
    form.add("id", id);
    form.add("values", values);

    testRequestWithForm(HttpMethod.POST, "/formTests/arraytest",
            FormType.FORM_URLENCODED, form, 400,
            errorMessage(ValidationException.ErrorType.NO_MATCH));
}
 
Example 12
Source File: OperationsTransformer.java    From spring-openapi with MIT License 5 votes vote down vote up
private void mapPatch(PatchMapping patchMapping, Method method, Map<String, PathItem> operationsMap, String controllerClassName, String baseControllerPath) {
	Operation operation = new Operation();
	operation.setOperationId(getOperationId(patchMapping.name(), method, HttpMethod.PATCH));
	operation.setSummary(StringUtils.isBlank(patchMapping.name()) ? patchMapping.name() : method.getName());
	operation.setTags(singletonList(classNameToTag(controllerClassName)));

	operation.setRequestBody(createRequestBody(method, getFirstFromArray(patchMapping.consumes())));
	operation.setResponses(createApiResponses(method, getFirstFromArray(patchMapping.produces())));
	operation.setParameters(transformParameters(method));

	String path = ObjectUtils.defaultIfNull(getFirstFromArray(patchMapping.value()), getFirstFromArray(patchMapping.path()));

	operationInterceptors.forEach(interceptor -> interceptor.intercept(method, operation));
	updateOperationsMap(prepareUrl(baseControllerPath, "/", path), operationsMap, pathItem -> pathItem.setPatch(operation));
}
 
Example 13
Source File: OpenAPI3MultipleFilesValidationTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testJsonBody() throws Exception {
    Operation op = testSpec.getPaths().get("/jsonBodyTest/sampleTest")
            .getPost();
    if (op.getParameters() == null)
        op.setParameters(new ArrayList<>());
    OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(
            op, op.getParameters(), testSpec, refsCache);
    loadHandlers("/jsonBodyTest/sampleTest", HttpMethod.POST, false,
            validationHandler, (routingContext) -> {
                RequestParameters params = routingContext
                        .get("parsedParameters");
                routingContext.response().setStatusCode(200)
                        .setStatusMessage("OK")
                        .putHeader("Content-Type", "application/json")
                        .end(params.body().getJsonObject().encode());
            });

    JsonObject object = new JsonObject();
    object.put("id", "anId");

    List<Integer> valuesArray = new ArrayList<>();
    for (int i = 0; i < 4; i++)
        valuesArray.add(getSuccessSample(ParameterType.INT).getInteger());
    object.put("values", valuesArray);

    testRequestWithJSON(HttpMethod.POST, "/jsonBodyTest/sampleTest",
            object.toBuffer(), 200, "OK", object.toBuffer());
    testRequestWithBufferResponse(HttpMethod.POST,
            "/jsonBodyTest/sampleTest", "application/json; charset=utf-8",
            object.toBuffer(), 200, "OK", "application/json",
            b -> assertEquals(object, b.toJsonObject()));
    testRequestWithBufferResponse(HttpMethod.POST,
            "/jsonBodyTest/sampleTest", "application/superapplication+json",
            object.toBuffer(), 200, "OK", "application/json",
            b -> assertEquals(object, b.toJsonObject()));
}
 
Example 14
Source File: OperationsTransformer.java    From spring-openapi with MIT License 5 votes vote down vote up
private void mapGet(GetMapping getMapping, Method method, Map<String, PathItem> operationsMap, String controllerClassName, String baseControllerPath) {
	Operation operation = new Operation();
	operation.setOperationId(getOperationId(getMapping.name(), method, HttpMethod.GET));
	operation.setSummary(StringUtils.isBlank(getMapping.name()) ? getMapping.name() : method.getName());
	operation.setTags(singletonList(classNameToTag(controllerClassName)));

	operation.setParameters(transformParameters(method));
	operation.setResponses(createApiResponses(method, getFirstFromArray(getMapping.produces())));

	String path = ObjectUtils.defaultIfNull(getFirstFromArray(getMapping.value()), getFirstFromArray(getMapping.path()));

	operationInterceptors.forEach(interceptor -> interceptor.intercept(method, operation));
	updateOperationsMap(prepareUrl(baseControllerPath, "/", path), operationsMap, pathItem -> pathItem.setGet(operation));
}
 
Example 15
Source File: OperationsTransformer.java    From spring-openapi with MIT License 5 votes vote down vote up
private void mapDelete(DeleteMapping deleteMapping, Method method, Map<String, PathItem> operationsMap, String controllerClassName,
					   String baseControllerPath) {
	Operation operation = new Operation();
	operation.setOperationId(getOperationId(deleteMapping.name(), method, HttpMethod.DELETE));
	operation.setSummary(StringUtils.isBlank(deleteMapping.name()) ? deleteMapping.name() : method.getName());
	operation.setTags(singletonList(classNameToTag(controllerClassName)));

	operation.setParameters(transformParameters(method));
	operation.setResponses(createApiResponses(method, getFirstFromArray(deleteMapping.produces())));
	String path = ObjectUtils.defaultIfNull(getFirstFromArray(deleteMapping.value()), getFirstFromArray(deleteMapping.path()));

	operationInterceptors.forEach(interceptor -> interceptor.intercept(method, operation));
	updateOperationsMap(prepareUrl(baseControllerPath, "/", path), operationsMap, pathItem -> pathItem.setDelete(operation));
}
 
Example 16
Source File: OASMergeUtil.java    From crnk-framework with Apache License 2.0 4 votes vote down vote up
public static Operation mergeOperations(Operation thisOperation, Operation thatOperation) {
  if (thatOperation == null) {
    return thisOperation;
  }

  if (thatOperation.getTags() != null) {
    thisOperation.setTags(
        mergeTags(thisOperation.getTags(), thatOperation.getTags())
    );
  }
  if (thatOperation.getExternalDocs() != null) {
    thisOperation.setExternalDocs(
      mergeExternalDocumentation(thisOperation.getExternalDocs(), thatOperation.getExternalDocs())
    );
  }
  if (thatOperation.getParameters() != null) {
    thisOperation.setParameters(
        mergeParameters(thisOperation.getParameters(), thatOperation.getParameters())
    );
  }
  if (thatOperation.getRequestBody() != null) {
    thisOperation.setRequestBody(thatOperation.getRequestBody());
  }
  if (thatOperation.getResponses() != null) {
    thisOperation.setResponses(thatOperation.getResponses());
  }
  if (thatOperation.getCallbacks() != null) {
    thisOperation.setCallbacks(thatOperation.getCallbacks());
  }
  if (thatOperation.getDeprecated() != null) {
    thisOperation.setDeprecated(thatOperation.getDeprecated());
  }
  if (thatOperation.getSecurity() != null) {
    thisOperation.setSecurity(thatOperation.getSecurity());
  }
  if (thatOperation.getServers() != null) {
    thisOperation.setServers(thatOperation.getServers());
  }
  if (thatOperation.getExtensions() != null) {
    thisOperation.setExtensions(thatOperation.getExtensions());
  }
  if (thatOperation.getOperationId() != null) {
    thisOperation.setOperationId(thatOperation.getOperationId());
  }
  if (thatOperation.getSummary() != null) {
    thisOperation.setSummary(thatOperation.getSummary());
  }
  if (thatOperation.getDescription() != null) {
    thisOperation.setDescription(thatOperation.getDescription());
  }
  if (thatOperation.getExtensions() != null) {
    thisOperation.setExtensions(thatOperation.getExtensions());
  }
  return thisOperation;
}
 
Example 17
Source File: OpenAPIDeserializer.java    From swagger-parser with Apache License 2.0 4 votes vote down vote up
public Operation getOperation(ObjectNode obj, String location, ParseResult result) {
    if (obj == null) {
        return null;
    }
    Operation operation = new Operation();

    ArrayNode array = getArray("tags", obj, false, location, result);
    List<String> tags = getTagsStrings(array, String.format("%s.%s", location, "tags"), result);
    if (tags != null) {
        operation.setTags(tags);
    }
    String value = getString("summary", obj, false, location, result);
    if (StringUtils.isNotBlank(value)) {
        operation.setSummary(value);
    }

    value = getString("description", obj, false, location, result);
    if (StringUtils.isNotBlank(value)) {
        operation.setDescription(value);
    }

    ObjectNode externalDocs = getObject("externalDocs", obj, false, location, result);
    ExternalDocumentation docs = getExternalDocs(externalDocs, String.format("%s.%s", location, "externalDocs"), result);
    if(docs != null) {
        operation.setExternalDocs(docs);
    }
    value = getString("operationId", obj, false, location, result, operationIDs);
    if (StringUtils.isNotBlank(value)) {
        operation.operationId(value);
    }

    ArrayNode parameters = getArray("parameters", obj, false, location, result);
    if (parameters != null){
        operation.setParameters(getParameterList(parameters, String.format("%s.%s", location, "parameters"), result));
    }

    final ObjectNode requestObjectNode = getObject("requestBody", obj, false, location, result);
    if (requestObjectNode != null){
        operation.setRequestBody(getRequestBody(requestObjectNode, String.format("%s.%s", location, "requestBody"), result));
    }

    ObjectNode responsesNode = getObject("responses", obj, true, location, result);
    ApiResponses responses = getResponses(responsesNode, String.format("%s.%s", location, "responses"), result, false);
    if(responses != null) {
        operation.setResponses(responses);
    }

    ObjectNode callbacksNode = getObject("callbacks", obj, false, location, result);
    Map<String,Callback> callbacks = getCallbacks(callbacksNode, String.format("%s.%s", location, "callbacks"), result, false);
    if(callbacks != null){
        operation.setCallbacks(callbacks);
    }

    Boolean deprecated = getBoolean("deprecated", obj, false, location, result);
    if (deprecated != null) {
        operation.setDeprecated(deprecated);
    }

    array = getArray("servers", obj, false, location, result);
    if (array != null && array.size() > 0) {
        operation.setServers(getServersList(array, String.format("%s.%s", location, "servers"), result));
    }


    array = getArray("security", obj, false, location, result);
    if (array != null) {
        operation.setSecurity(getSecurityRequirementsList(array, String.format("%s.%s", location, "security"), result));
    }


    Map <String,Object> extensions = getExtensions(obj);
    if(extensions != null && extensions.size() > 0) {
        operation.setExtensions(extensions);
    }

    Set<String> keys = getKeys(obj);
    for(String key : keys) {
        if(!OPERATION_KEYS.contains(key) && !key.startsWith("x-")) {
            result.extra(location, key, obj.get(key));
        }
    }


    return operation;
}
 
Example 18
Source File: OperationProcessorTest.java    From swagger-parser with Apache License 2.0 4 votes vote down vote up
@Test
public void testProcessOperation(@Injectable final List<Parameter> inputParameterList,
                                 @Injectable final List<Parameter> outputParameterList,
                                 @Injectable final ApiResponse incomingResponse,
                                 @Injectable final ApiResponse resolvedResponse) throws Exception {

    Operation operation = new Operation();
    operation.setParameters(inputParameterList);

    final String ref = "http://my.company.com/path/to/file.json#/foo/bar";
    ApiResponse refResponse = new ApiResponse().$ref(ref);

    operation.responses(new ApiResponses().addApiResponse("200", refResponse));
    operation.getResponses().addApiResponse("400", incomingResponse);


    new Expectations() {{
        new ParameterProcessor(cache, openAPI);
        times = 1;
        result = parameterProcessor;

        new ResponseProcessor(cache, openAPI);
        times = 1;
        result = responseProcessor;

        parameterProcessor.processParameters(inputParameterList);
        times = 1;
        result = outputParameterList;

        responseProcessor.processResponse(refResponse);
        times = 1;

        RefUtils.computeRefFormat(ref);
        times = 1;

        cache.loadRef(ref, RefFormat.URL, ApiResponse.class);
        times = 1;
        result = resolvedResponse;

        RefUtils.computeRefFormat(ref);
        times = 1;

        incomingResponse.get$ref();
        times = 1;

        responseProcessor.processResponse(incomingResponse);
        times = 1;
        responseProcessor.processResponse(resolvedResponse);
        times = 1;

    }};



    new OperationProcessor(cache, openAPI).processOperation(operation);


    new FullVerifications() {{}};

    assertEquals(operation.getResponses().get("200"), resolvedResponse);
    assertEquals(operation.getParameters(), outputParameterList);
}
 
Example 19
Source File: AbstractRequestBuilder.java    From springdoc-openapi with Apache License 2.0 3 votes vote down vote up
/**
 * Sets params.
 *
 * @param operation the operation
 * @param operationParameters the operation parameters
 * @param requestBodyInfo the request body info
 */
private void setParams(Operation operation, List<Parameter> operationParameters, RequestBodyInfo requestBodyInfo) {
	if (!CollectionUtils.isEmpty(operationParameters))
		operation.setParameters(operationParameters);
	if (requestBodyInfo.getRequestBody() != null)
		operation.setRequestBody(requestBodyInfo.getRequestBody());
}
 
Example 20
Source File: InlineModelResolverTest.java    From swagger-parser with Apache License 2.0 3 votes vote down vote up
@Test
public void resolveInlineParameter() throws Exception {
    OpenAPI openAPI = new OpenAPI();


    ObjectSchema objectSchema = new ObjectSchema();
    objectSchema.addProperties("street", new StringSchema());

    Schema schema = new Schema();
    schema.addProperties("address", objectSchema);
    schema.addProperties("name", new StringSchema());

    Parameter parameter = new Parameter();
    parameter.setName("name");
    parameter.setSchema(schema);

    List parameters = new ArrayList();
    parameters.add(parameter);


    Operation operation = new Operation();
    operation.setParameters(parameters);

    PathItem pathItem = new PathItem();
    pathItem.setGet(operation);
    openAPI.path("/hello",pathItem);

    new InlineModelResolver().flatten(openAPI);

    Operation getOperation = openAPI.getPaths().get("/hello").getGet();
    Parameter param = getOperation.getParameters().get(0);
    assertTrue(param.getSchema().get$ref() != null);



    Schema bodySchema = openAPI.getComponents().getSchemas().get("name");
    assertTrue(bodySchema instanceof Schema);

    assertNotNull(bodySchema.getProperties().get("address"));
}