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

The following examples show how to use io.swagger.v3.oas.models.Operation#setOperationId() . 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: OperationsTransformer.java    From spring-openapi with MIT License 6 votes vote down vote up
private void mapRequestMapping(RequestMapping requestMapping, Method method, Map<String, PathItem> operationsMap, String controllerClassName,
							   String baseControllerPath) {
	Operation operation = new Operation();
	operation.setOperationId(getOperationId(requestMapping.name(), method, getSpringMethod(requestMapping.method())));
	operation.setSummary(StringUtils.isBlank(requestMapping.name()) ? requestMapping.name() : method.getName());
	operation.setTags(singletonList(classNameToTag(controllerClassName)));

	if (isHttpMethodWithRequestBody(requestMapping.method())) {
		operation.setRequestBody(createRequestBody(method, getFirstFromArray(requestMapping.consumes())));
	}
	operation.setParameters(transformParameters(method));
	operation.setResponses(createApiResponses(method, getFirstFromArray(requestMapping.produces())));

	operationInterceptors.forEach(interceptor -> interceptor.intercept(method, operation));

	String path = ObjectUtils.defaultIfNull(getFirstFromArray(requestMapping.value()), getFirstFromArray(requestMapping.path()));
	updateOperationsMap(prepareUrl(baseControllerPath, "/", path), operationsMap,
			pathItem -> setContentBasedOnHttpMethod(pathItem, requestMapping.method(), operation)
	);
}
 
Example 2
Source File: OperationBuilder.java    From springdoc-openapi with Apache License 2.0 6 votes vote down vote up
/**
 * Merge operation operation.
 *
 * @param operation the operation
 * @param operationModel the operation model
 * @return the operation
 */
public Operation mergeOperation(Operation operation, Operation operationModel) {
	if (operationModel.getOperationId().length() < operation.getOperationId().length()) {
		operation.setOperationId(operationModel.getOperationId());
	}

	ApiResponses apiResponses = operation.getResponses();
	for (Entry<String, ApiResponse> apiResponseEntry : operationModel.getResponses().entrySet()) {
		if (apiResponses.containsKey(apiResponseEntry.getKey())) {
			Content existingContent = apiResponses.get(apiResponseEntry.getKey()).getContent();
			Content newContent = apiResponseEntry.getValue().getContent();
			if (newContent != null)
				newContent.forEach((mediaTypeStr, mediaType) -> SpringDocAnnotationsUtils.mergeSchema(existingContent, mediaType.getSchema(), mediaTypeStr));
		}
		else
			apiResponses.addApiResponse(apiResponseEntry.getKey(), apiResponseEntry.getValue());
	}
	return operation;
}
 
Example 3
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 4
Source File: OASMergeUtilTest.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
@Test
public void testMergeOperations() {
  Operation thatOperation = new Operation();

  Operation thisOperation = new Operation();
  thisOperation.setOperationId("new id");
  thisOperation.setSummary("new summary");
  thisOperation.setDescription("new description");

  Map<String, Object> extensions = new HashMap<>();
  extensions.put("new schema", new Schema());
  thisOperation.setExtensions(extensions);

  Assert.assertSame(thisOperation, OASMergeUtil.mergeOperations(thisOperation, null));

  Operation afterMerge = OASMergeUtil.mergeOperations(thatOperation, thisOperation);
  Assert.assertEquals("new id", afterMerge.getOperationId());
  Assert.assertEquals("new summary", afterMerge.getSummary());
  Assert.assertEquals("new description", afterMerge.getDescription());
  Assert.assertSame(extensions, afterMerge.getExtensions());

  thatOperation.setOperationId("existing id");
  thatOperation.setSummary("existing summary");
  thatOperation.setDescription("existing description");

  Map<String, Object> existingExtensions = new HashMap<>();
  extensions.put("existing schema", new Schema());
  thisOperation.setExtensions(extensions);

  afterMerge = OASMergeUtil.mergeOperations(thisOperation, thatOperation);
  Assert.assertEquals("existing id", afterMerge.getOperationId());
  Assert.assertEquals("existing summary", afterMerge.getSummary());
  Assert.assertEquals("existing description", afterMerge.getDescription());
  Assert.assertSame(extensions, afterMerge.getExtensions());
}
 
Example 5
Source File: ProtoOpenAPI.java    From product-microgateway with Apache License 2.0 5 votes vote down vote up
/**
 * Add openAPI path item to the the openAPI object.
 *
 * @param path            name of the pathItem
 * @param scopes          array of operation scopes
 * @param throttlingTier throttling tier
 */
void addOpenAPIPath(String path, String[] scopes, String throttlingTier) {
    PathItem pathItem = new PathItem();
    Operation operation = new Operation();
    operation.setOperationId(UUID.randomUUID().toString());
    addOauth2SecurityRequirement(operation, scopes);
    if (StringUtils.isNotEmpty(throttlingTier)) {
        operation.addExtension(OpenAPIConstants.THROTTLING_TIER, throttlingTier);
    }
    //needs to add the basic Auth Requirement to the operation level because if scopes are mentioned,
    // there would be oauth2 security requirement in method level.
    if (isBasicAuthEnabled) {
        addBasicAuthSecurityRequirement(operation);
    }
    if (isAPIKeyEnabled) {
        addAPIKeySecurityRequirement(operation);
    }
    //For each path, the only available http method is "post" according to the grpc mapping.
    pathItem.setPost(operation);
    if (openAPI.getPaths() == null) {
        openAPI.setPaths(new Paths());
    }
    //as Responses object is mandatory
    ApiResponse apiResponse = new ApiResponse();
    apiResponse.setDescription(ProtoToOpenAPIConstants.RESPONSE_DESCRIPTION);
    ApiResponses apiResponses = new ApiResponses();
    apiResponses.addApiResponse(ProtoToOpenAPIConstants.SUCCESS_RESPONSE_CODE, apiResponse);
    operation.setResponses(apiResponses);
    //append forward slash to preserve openAPI syntax
    openAPI.getPaths().addPathItem(ProtoToOpenAPIConstants.PATH_SEPARATOR + path, pathItem);
}
 
Example 6
Source File: DataRestOperationBuilder.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
/**
 * Init operation operation.
 *
 * @param handlerMethod the handler method
 * @param domainType the domain type
 * @param requestMethod the request method
 * @return the operation
 */
private Operation initOperation(HandlerMethod handlerMethod, Class<?> domainType, RequestMethod requestMethod) {
	Operation operation = new Operation();
	StringBuilder operationIdBuilder = new StringBuilder();
	operationIdBuilder.append(handlerMethod.getMethod().getName());
	if (domainType != null) {
		operationIdBuilder.append(STRING_SEPARATOR).append(domainType.getSimpleName().toLowerCase())
				.append(STRING_SEPARATOR).append(requestMethod.toString().toLowerCase());
	}
	operation.setOperationId(operationIdBuilder.toString());
	return operation;
}
 
Example 7
Source File: ActuatorOperationCustomizer.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Override
public Operation customize(Operation operation, HandlerMethod handlerMethod) {
	if (operation.getTags() != null && operation.getTags().contains(actuatorProvider.getTag().getName())) {
		operation.setSummary(handlerMethod.toString());
		operation.setOperationId(operation.getOperationId() + "_" + methodCount++);
	}
	return operation;
}
 
Example 8
Source File: AbstractOpenApiResource.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
/**
 * Calculate path.
 *
 * @param routerOperation the router operation
 */
protected void calculatePath(RouterOperation routerOperation) {
	String operationPath = routerOperation.getPath();
	io.swagger.v3.oas.annotations.Operation apiOperation = routerOperation.getOperation();
	String[] methodConsumes = routerOperation.getConsumes();
	String[] methodProduces = routerOperation.getProduces();
	String[] headers = routerOperation.getHeaders();
	Map<String, String> queryParams = routerOperation.getQueryParams();

	OpenAPI openAPI = openAPIBuilder.getCalculatedOpenAPI();
	Paths paths = openAPI.getPaths();
	Map<HttpMethod, Operation> operationMap = null;
	if (paths.containsKey(operationPath)) {
		PathItem pathItem = paths.get(operationPath);
		operationMap = pathItem.readOperationsMap();
	}
	for (RequestMethod requestMethod : routerOperation.getMethods()) {
		Operation existingOperation = getExistingOperation(operationMap, requestMethod);
		MethodAttributes methodAttributes = new MethodAttributes(springDocConfigProperties.getDefaultConsumesMediaType(), springDocConfigProperties.getDefaultProducesMediaType(), methodConsumes, methodProduces, headers);
		methodAttributes.setMethodOverloaded(existingOperation != null);
		Operation operation = getOperation(routerOperation, existingOperation);
		if (apiOperation != null)
			openAPI = operationParser.parse(apiOperation, operation, openAPI, methodAttributes);

		String operationId = operationParser.getOperationId(operation.getOperationId(), openAPI);
		operation.setOperationId(operationId);

		fillParametersList(operation, queryParams, methodAttributes);
		if (!CollectionUtils.isEmpty(operation.getParameters()))
			operation.getParameters().forEach(parameter -> {
						if (parameter.getSchema() == null)
							parameter.setSchema(new StringSchema());
						if (parameter.getIn() == null)
							parameter.setIn(ParameterIn.QUERY.toString());
					}
			);
		PathItem pathItemObject = buildPathItem(requestMethod, operation, operationPath, paths);
		paths.addPathItem(operationPath, pathItemObject);
	}
}
 
Example 9
Source File: OperationsTransformer.java    From spring-openapi with MIT License 5 votes vote down vote up
private void handleOperation(Operation operation, Map<String, Integer> operationIdCount) {
	if (operation == null) {
		return;
	}
	String operationId = operation.getOperationId();
	if (operationIdCount.containsKey(operationId)) {
		Integer newValue = operationIdCount.get(operationId) + 1;
		operation.setOperationId(operationId + "_" + newValue);
		operationIdCount.put(operationId, newValue);
		return;
	}
	operationIdCount.put(operationId, 0);
}
 
Example 10
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 11
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 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: 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 14
Source File: OperationBuilder.java    From springdoc-openapi with Apache License 2.0 4 votes vote down vote up
/**
 * Parse open api.
 *
 * @param apiOperation the api operation
 * @param operation the operation
 * @param openAPI the open api
 * @param methodAttributes the method attributes
 * @return the open api
 */
public OpenAPI parse(io.swagger.v3.oas.annotations.Operation apiOperation,
		Operation operation, OpenAPI openAPI, MethodAttributes methodAttributes) {
	Components components = openAPI.getComponents();
	if (StringUtils.isNotBlank(apiOperation.summary()))
		operation.setSummary(propertyResolverUtils.resolve(apiOperation.summary()));

	if (StringUtils.isNotBlank(apiOperation.description()))
		operation.setDescription(propertyResolverUtils.resolve(apiOperation.description()));

	if (StringUtils.isNotBlank(apiOperation.operationId()))
		operation.setOperationId(getOperationId(apiOperation.operationId(), openAPI));

	if (apiOperation.deprecated())
		operation.setDeprecated(apiOperation.deprecated());

	buildTags(apiOperation, operation);

	if (operation.getExternalDocs() == null)  // if not set in root annotation
		AnnotationsUtils.getExternalDocumentation(apiOperation.externalDocs())
				.ifPresent(operation::setExternalDocs);

	// servers
	AnnotationsUtils.getServers(apiOperation.servers())
			.ifPresent(servers -> servers.forEach(operation::addServersItem));

	// build parameters
	for (io.swagger.v3.oas.annotations.Parameter parameterDoc : apiOperation.parameters()) {
		Parameter parameter = parameterBuilder.buildParameterFromDoc(parameterDoc, components,
				methodAttributes.getJsonViewAnnotation());
		operation.addParametersItem(parameter);
	}

	// RequestBody in Operation
	requestBodyBuilder.buildRequestBodyFromDoc(apiOperation.requestBody(), operation.getRequestBody(), methodAttributes, components).ifPresent(operation::setRequestBody);

	// build response
	buildResponse(components, apiOperation, operation, methodAttributes);

	// security
	securityParser.buildSecurityRequirement(apiOperation.security(), operation);

	// Extensions in Operation
	buildExtensions(apiOperation, operation);
	return openAPI;
}
 
Example 15
Source File: NodeJSExpressServerCodegen.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@Override
    public void preprocessOpenAPI(OpenAPI openAPI) {
        URL url = URLPathUtils.getServerURL(openAPI, serverVariableOverrides());
        String host = URLPathUtils.getProtocolAndHost(url);
        String port = URLPathUtils.getPort(url, defaultServerPort);
        String basePath = url.getPath();

        if (additionalProperties.containsKey(SERVER_PORT)) {
            port = additionalProperties.get(SERVER_PORT).toString();
        }
        this.additionalProperties.put(SERVER_PORT, port);

        if (openAPI.getInfo() != null) {
            Info info = openAPI.getInfo();
            if (info.getTitle() != null) {
                // when info.title is defined, use it for projectName
                // used in package.json
                projectName = info.getTitle()
                        .replaceAll("[^a-zA-Z0-9]", "-")
                        .replaceAll("^[-]*", "")
                        .replaceAll("[-]*$", "")
                        .replaceAll("[-]{2,}", "-")
                        .toLowerCase(Locale.ROOT);
                this.additionalProperties.put("projectName", projectName);
            }
        }

        // need vendor extensions
        Paths paths = openAPI.getPaths();
        if (paths != null) {
            for (String pathname : paths.keySet()) {
                PathItem path = paths.get(pathname);
                Map<HttpMethod, Operation> operationMap = path.readOperationsMap();
                if (operationMap != null) {
                    for (HttpMethod method : operationMap.keySet()) {
                        Operation operation = operationMap.get(method);
                        String tag = "default";
                        if (operation.getTags() != null && operation.getTags().size() > 0) {
                            tag = toApiName(operation.getTags().get(0));
                        }
                        if (operation.getOperationId() == null) {
                            operation.setOperationId(getOrGenerateOperationId(operation, pathname, method.toString()));
                        }
                        // add x-openapi-router-controller
//                        if (operation.getExtensions() == null ||
//                                operation.getExtensions().get("x-openapi-router-controller") == null) {
//                            operation.addExtension("x-openapi-router-controller", sanitizeTag(tag) + "Controller");
//                        }
//                        // add x-openapi-router-service
//                        if (operation.getExtensions() == null ||
//                                operation.getExtensions().get("x-openapi-router-service") == null) {
//                            operation.addExtension("x-openapi-router-service", sanitizeTag(tag) + "Service");
//                        }
                        if (operation.getExtensions() == null ||
                                operation.getExtensions().get("x-eov-operation-handler") == null) {
                            operation.addExtension("x-eov-operation-handler", "controllers/" + sanitizeTag(tag) + "Controller");
                        }
                    }
                }
            }
        }

    }
 
Example 16
Source File: BallerinaOperation.java    From product-microgateway with Apache License 2.0 4 votes vote down vote up
@Override
public BallerinaOperation buildContext(Operation operation, ExtendedAPI api) throws BallerinaServiceGenException,
        CLICompileTimeException {
    if (operation == null) {
        return getDefaultValue();
    }

    // OperationId with spaces with special characters will cause errors in ballerina code.
    // Replacing it with uuid so that we can identify there was a ' ' when doing bal -> swagger
    operation.setOperationId(UUID.randomUUID().toString().replaceAll("-", ""));
    this.operationId = operation.getOperationId();
    this.tags = operation.getTags();
    this.summary = operation.getSummary();
    this.description = operation.getDescription();
    this.externalDocs = operation.getExternalDocs();
    this.parameters = new ArrayList<>();
    //to provide resource level security in dev-first approach
    ApplicationSecurity appSecurity = OpenAPICodegenUtils.populateApplicationSecurity(api.getName(),
            api.getVersion(), operation.getExtensions(), api.getMutualSSL());
    this.authProviders = OpenAPICodegenUtils.getMgwResourceSecurity(operation, appSecurity);
    this.apiKeys = OpenAPICodegenUtils.generateAPIKeysFromSecurity(operation.getSecurity(),
            this.authProviders.contains(OpenAPIConstants.APISecurity.apikey.name()));
    ApplicationSecurity apiAppSecurity = api.getApplicationSecurity();
    if (appSecurity != null && appSecurity.isOptional() != null) {
        // if app security is made optional at resource
        this.applicationSecurityOptional = appSecurity.isOptional();
    } else if (apiAppSecurity != null && apiAppSecurity.isOptional() != null) {
        // if app security made optional at API level
        this.applicationSecurityOptional = apiAppSecurity.isOptional();
    }
    //to set resource level scopes in dev-first approach
    this.scope = OpenAPICodegenUtils.getMgwResourceScope(operation);
    //set resource level endpoint configuration
    setEpConfigDTO(operation);
    Map<String, Object> exts = operation.getExtensions();

    if (exts != null) {
        // set interceptor details
        Object reqExt = exts.get(OpenAPIConstants.REQUEST_INTERCEPTOR);
        Object resExt = exts.get(OpenAPIConstants.RESPONSE_INTERCEPTOR);
        if (reqExt != null) {
            reqInterceptorContext = new BallerinaInterceptor(reqExt.toString());
            requestInterceptor = reqInterceptorContext.getInvokeStatement();
            isJavaRequestInterceptor = BallerinaInterceptor.Type.JAVA == reqInterceptorContext.getType();
        }
        if (resExt != null) {
            resInterceptorContext = new BallerinaInterceptor(resExt.toString());
            responseInterceptor = resInterceptorContext.getInvokeStatement();
            isJavaResponseInterceptor = BallerinaInterceptor.Type.JAVA == resInterceptorContext.getType();
        }


        Optional<Object> scopes = Optional.ofNullable(exts.get(X_SCOPE));
        scopes.ifPresent(value -> this.scope = "\"" + value.toString() + "\"");
        Optional<Object> authType = Optional.ofNullable(exts.get(X_AUTH_TYPE));
        authType.ifPresent(value -> {
            if (AUTH_TYPE_NONE.equals(value)) {
                this.isSecured = false;
            }
        });
        Optional<Object> resourceTier = Optional.ofNullable(exts.get(X_THROTTLING_TIER));
        resourceTier.ifPresent(value -> this.resourceTier = value.toString());
        //set dev-first resource level throttle policy
        if (this.resourceTier == null) {
            Optional<Object> extResourceTier = Optional.ofNullable(exts.get(OpenAPIConstants.THROTTLING_TIER));
            extResourceTier.ifPresent(value -> this.resourceTier = value.toString());
        }
        if (api.getApiLevelPolicy() != null && this.resourceTier != null) {
            //if api level policy exists then we are neglecting the resource level policies
            String message = "[WARN] : Resource level policy: " + this.resourceTier
                    + " will be neglected due to the presence of API level policy: " + api.getApiLevelPolicy()
                    + " for the API : " + api.getName() + "\n";
            CmdUtils.appendMessagesToConsole(message);
            this.resourceTier = null;
        }
        Optional<Object> extDisableSecurity = Optional.ofNullable(exts.get(OpenAPIConstants.DISABLE_SECURITY));
        extDisableSecurity.ifPresent(value -> {
            try {
                this.isSecured = !(Boolean) value;
                this.isSecuredAssignedFromOperation = true;
            } catch (ClassCastException e) {
                throw new CLIRuntimeException("The property '" + OpenAPIConstants.DISABLE_SECURITY +
                        "' should be a boolean value. But provided '" + value.toString() + "'.");
            }
        });
    }

    if (operation.getParameters() != null) {
        for (Parameter parameter : operation.getParameters()) {
            this.parameters.add(new BallerinaParameter().buildContext(parameter, api));
        }
    }

    return this;
}
 
Example 17
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;
}