Java Code Examples for io.swagger.v3.oas.models.Operation#getDescription()
The following examples show how to use
io.swagger.v3.oas.models.Operation#getDescription() .
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: ResourceInterfaceGenerator.java From spring-openapi with MIT License | 5 votes |
private MethodSpec createMethod(OperationData operationData) { Operation operation = operationData.getOperation(); MethodSpec.Builder methodSpecBuilder = MethodSpec.methodBuilder(getMethodName(operation)) .addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT); if (operation.getDescription() != null) { methodSpecBuilder.addJavadoc(operation.getDescription()); } if (operation.getParameters() != null) { operation.getParameters() .forEach(parameter -> methodSpecBuilder.addParameter( parseProperties(formatParameterName(parameter.getName()), parameter.getSchema()).build() )); } if (operation.getRequestBody() != null && operation.getRequestBody().getContent() != null) { LinkedHashMap<String, MediaType> mediaTypes = operation.getRequestBody().getContent(); methodSpecBuilder.addParameter(parseProperties("requestBody", mediaTypes.entrySet().iterator().next().getValue().getSchema()).build()); } if (operation.getResponses() == null || CollectionUtils.isEmpty(operation.getResponses().entrySet())) { methodSpecBuilder.returns(TypeName.VOID); } else { ApiResponse apiResponse = operation.getResponses().entrySet().stream() .filter(responseEntry -> StringUtils.startsWith(responseEntry.getKey(), "2")) // HTTP 20x .findFirst() .map(Map.Entry::getValue) .orElse(null); if (apiResponse != null && apiResponse.getContent() != null && !apiResponse.getContent().isEmpty()) { MediaType mediaType = apiResponse.getContent().entrySet().iterator().next().getValue(); if (mediaType.getSchema() != null) { methodSpecBuilder.returns(determineTypeName(mediaType.getSchema())); return methodSpecBuilder.build(); } } methodSpecBuilder.returns(TypeName.VOID); } return methodSpecBuilder.build(); }
Example 2
Source File: BallerinaOperation.java From product-microgateway with Apache License 2.0 | 4 votes |
@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 3
Source File: OASMergeUtil.java From crnk-framework with Apache License 2.0 | 4 votes |
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; }