Java Code Examples for io.swagger.models.Path#getOperationMap()
The following examples show how to use
io.swagger.models.Path#getOperationMap() .
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: FlaskConnexionCodegen.java From TypeScript-Microservices with MIT License | 5 votes |
@Override public void preprocessSwagger(Swagger swagger) { // need vendor extensions for x-swagger-router-controller Map<String, Path> paths = swagger.getPaths(); if(paths != null) { for(String pathname : paths.keySet()) { Path path = paths.get(pathname); Map<HttpMethod, Operation> operationMap = path.getOperationMap(); 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 = operation.getTags().get(0); } String operationId = operation.getOperationId(); if(operationId == null) { operationId = getOrGenerateOperationId(operation, pathname, method.toString()); } operation.setOperationId(toOperationId(operationId)); if(operation.getVendorExtensions().get("x-swagger-router-controller") == null) { operation.getVendorExtensions().put( "x-swagger-router-controller", controllerPackage + "." + toApiFilename(tag) ); } for (Parameter param: operation.getParameters()) { // sanitize the param name but don't underscore it since it's used for request mapping String name = param.getName(); String paramName = sanitizeName(name); if (!paramName.equals(name)) { LOGGER.warn(name + " cannot be used as parameter name with flask-connexion and was sanitized as " + paramName); } param.setName(paramName); } } } } } }
Example 2
Source File: JavaVertXServerCodegen.java From TypeScript-Microservices with MIT License | 5 votes |
private void manageOperationNames(Path path, String pathname) { String serviceIdTemp; Map<HttpMethod, Operation> operationMap = path.getOperationMap(); if (operationMap != null) { for (Entry<HttpMethod, Operation> entry : operationMap.entrySet()) { serviceIdTemp = computeServiceId(pathname, entry); entry.getValue().setVendorExtension("x-serviceid", serviceIdTemp); entry.getValue().setVendorExtension("x-serviceid-varname", serviceIdTemp.toUpperCase() + "_SERVICE_ID"); } } }
Example 3
Source File: OAS2Parser.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Remove MG related information * * @param swagger Swagger */ private void removePublisherSpecificInfo(Swagger swagger) { Map<String, Object> extensions = swagger.getVendorExtensions(); OASParserUtil.removePublisherSpecificInfo(extensions); for (String pathKey : swagger.getPaths().keySet()) { Path path = swagger.getPath(pathKey); Map<HttpMethod, Operation> operationMap = path.getOperationMap(); for (Map.Entry<HttpMethod, Operation> entry : operationMap.entrySet()) { Operation operation = entry.getValue(); OASParserUtil.removePublisherSpecificInfofromOperation(operation.getVendorExtensions()); } } }
Example 4
Source File: OAS2Parser.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Update OAS operations for Store * * @param swagger Swagger to be updated */ private void updateOperations(Swagger swagger) { for (String pathKey : swagger.getPaths().keySet()) { Path path = swagger.getPath(pathKey); Map<HttpMethod, Operation> operationMap = path.getOperationMap(); for (Map.Entry<HttpMethod, Operation> entry : operationMap.entrySet()) { Operation operation = entry.getValue(); Map<String, Object> extensions = operation.getVendorExtensions(); if (extensions != null) { // remove mediation extension if (extensions.containsKey(APIConstants.SWAGGER_X_MEDIATION_SCRIPT)) { extensions.remove(APIConstants.SWAGGER_X_MEDIATION_SCRIPT); } // set x-scope value to security definition if it not there. if (extensions.containsKey(APIConstants.SWAGGER_X_WSO2_SCOPES)) { String scope = (String) extensions.get(APIConstants.SWAGGER_X_WSO2_SCOPES); List<Map<String, List<String>>> security = operation.getSecurity(); if (security == null) { security = new ArrayList<>(); operation.setSecurity(security); } for (Map<String, List<String>> requirement : security) { if (requirement.get(APIConstants.SWAGGER_APIM_DEFAULT_SECURITY) == null || !requirement .get(APIConstants.SWAGGER_APIM_DEFAULT_SECURITY).contains(scope)) { requirement .put(APIConstants.SWAGGER_APIM_DEFAULT_SECURITY, Collections.singletonList(scope)); } } } } } } }
Example 5
Source File: OAS2Parser.java From carbon-apimgt with Apache License 2.0 | 4 votes |
/** * This method returns URI templates according to the given swagger file * * @param resourceConfigsJSON swaggerJSON * @return URI Templates * @throws APIManagementException */ @Override public Set<URITemplate> getURITemplates(String resourceConfigsJSON) throws APIManagementException { Swagger swagger = getSwagger(resourceConfigsJSON); Set<URITemplate> urlTemplates = new LinkedHashSet<>(); Set<Scope> scopes = getScopes(resourceConfigsJSON); String oauth2SchemeKey = getOAuth2SecuritySchemeKey(swagger); for (String pathString : swagger.getPaths().keySet()) { Path path = swagger.getPath(pathString); Map<HttpMethod, Operation> operationMap = path.getOperationMap(); for (Map.Entry<HttpMethod, Operation> entry : operationMap.entrySet()) { Operation operation = entry.getValue(); URITemplate template = new URITemplate(); template.setHTTPVerb(entry.getKey().name().toUpperCase()); template.setHttpVerbs(entry.getKey().name().toUpperCase()); template.setUriTemplate(pathString); List<String> opScopes = getScopeOfOperations(oauth2SchemeKey, operation); if (!opScopes.isEmpty()) { if (opScopes.size() == 1) { String firstScope = opScopes.get(0); Scope scope = APIUtil.findScopeByKey(scopes, firstScope); if (scope == null) { throw new APIManagementException("Scope '" + firstScope + "' not found."); } template.setScope(scope); template.setScopes(scope); } else { template = OASParserUtil.setScopesToTemplate(template, opScopes, scopes); } } Map<String, Object> extensions = operation.getVendorExtensions(); if (extensions != null) { if (extensions.containsKey(APIConstants.SWAGGER_X_AUTH_TYPE)) { String authType = (String) extensions.get(APIConstants.SWAGGER_X_AUTH_TYPE); template.setAuthType(authType); template.setAuthTypes(authType); } else { template.setAuthType("Any"); template.setAuthTypes("Any"); } if (extensions.containsKey(APIConstants.SWAGGER_X_THROTTLING_TIER)) { String throttlingTier = (String) extensions.get(APIConstants.SWAGGER_X_THROTTLING_TIER); template.setThrottlingTier(throttlingTier); template.setThrottlingTiers(throttlingTier); } if (extensions.containsKey(APIConstants.SWAGGER_X_MEDIATION_SCRIPT)) { String mediationScript = (String) extensions.get(APIConstants.SWAGGER_X_MEDIATION_SCRIPT); template.setMediationScript(mediationScript); template.setMediationScripts(template.getHTTPVerb(), mediationScript); } } urlTemplates.add(template); } } return urlTemplates; }
Example 6
Source File: OAS2Parser.java From carbon-apimgt with Apache License 2.0 | 4 votes |
/** * Update OAS definition for API Publisher * * @param api API * @param oasDefinition * @return OAS definition * @throws APIManagementException throws if an error occurred */ @Override public String getOASDefinitionForPublisher(API api, String oasDefinition) throws APIManagementException { Swagger swagger = getSwagger(oasDefinition); if (api.getAuthorizationHeader() != null) { swagger.setVendorExtension(APIConstants.X_WSO2_AUTH_HEADER, api.getAuthorizationHeader()); } if (api.getApiLevelPolicy() != null) { swagger.setVendorExtension(APIConstants.X_THROTTLING_TIER, api.getApiLevelPolicy()); } swagger.setVendorExtension(APIConstants.X_WSO2_CORS, api.getCorsConfiguration()); Object prodEndpointObj = OASParserUtil.generateOASConfigForEndpoints(api, true); if (prodEndpointObj != null) { swagger.setVendorExtension(APIConstants.X_WSO2_PRODUCTION_ENDPOINTS, prodEndpointObj); } Object sandEndpointObj = OASParserUtil.generateOASConfigForEndpoints(api, false); if (sandEndpointObj != null) { swagger.setVendorExtension(APIConstants.X_WSO2_SANDBOX_ENDPOINTS, sandEndpointObj); } swagger.setVendorExtension(APIConstants.X_WSO2_BASEPATH, api.getContext()); if (api.getTransports() != null) { swagger.setVendorExtension(APIConstants.X_WSO2_TRANSPORTS, api.getTransports().split(",")); } String apiSecurity = api.getApiSecurity(); // set mutual ssl extension if enabled if (apiSecurity != null) { List<String> securityList = Arrays.asList(apiSecurity.split(",")); if (securityList.contains(APIConstants.API_SECURITY_MUTUAL_SSL)) { String mutualSSLOptional = !securityList.contains(APIConstants.API_SECURITY_MUTUAL_SSL_MANDATORY) ? APIConstants.OPTIONAL : APIConstants.MANDATORY; swagger.setVendorExtension(APIConstants.X_WSO2_MUTUAL_SSL, mutualSSLOptional); } } // This app security is should given in resource level, // otherwise the default oauth2 scheme defined at each resouce level will override application securities JsonNode appSecurityExtension = OASParserUtil.getAppSecurity(apiSecurity); for (String pathKey : swagger.getPaths().keySet()) { Path path = swagger.getPath(pathKey); Map<HttpMethod, Operation> operationMap = path.getOperationMap(); for (Map.Entry<HttpMethod, Operation> entry : operationMap.entrySet()) { Operation operation = entry.getValue(); operation.setVendorExtension(APIConstants.X_WSO2_APP_SECURITY, appSecurityExtension); } } swagger.setVendorExtension(APIConstants.X_WSO2_APP_SECURITY, appSecurityExtension); swagger.setVendorExtension(APIConstants.X_WSO2_RESPONSE_CACHE, OASParserUtil.getResponseCacheConfig(api.getResponseCache(), api.getCacheTimeout())); return getSwaggerJsonString(swagger); }
Example 7
Source File: OAS2Parser.java From carbon-apimgt with Apache License 2.0 | 4 votes |
/** * This method returns URI templates according to the given swagger file(Swagger version 2) * * @param swagger Swagger * @return Swagger * @throws APIManagementException */ private Swagger injectOtherResourceScopesToDefaultScheme(Swagger swagger) throws APIManagementException { List<String> schemes = getOtherSchemes(); Map<String, Path> paths = swagger.getPaths(); for (String pathKey : paths.keySet()) { Path pathItem = paths.get(pathKey); Map<HttpMethod, Operation> operationsMap = pathItem.getOperationMap(); for (Map.Entry<HttpMethod, Operation> entry : operationsMap.entrySet()) { HttpMethod httpMethod = entry.getKey(); Operation operation = entry.getValue(); Map<String, List<String>> updatedDefaultSecurityRequirement = new HashMap<>(); List<Map<String, List<String>>> securityRequirements = operation.getSecurity(); if (securityRequirements == null) { securityRequirements = new ArrayList<>(); } if (APIConstants.SUPPORTED_METHODS.contains(httpMethod.name().toLowerCase())) { List<String> opScopesDefault = new ArrayList<>(); List<String> opScopesDefaultInstance = getScopeOfOperations(SWAGGER_SECURITY_SCHEMA_KEY, operation); if (opScopesDefaultInstance != null) { opScopesDefault.addAll(opScopesDefaultInstance); } updatedDefaultSecurityRequirement.put(SWAGGER_SECURITY_SCHEMA_KEY, opScopesDefault); for (Map<String, List<String>> input : securityRequirements) { for (String scheme : schemes) { if (!SWAGGER_SECURITY_SCHEMA_KEY.equals(scheme)) { List<String> opScopesOthers = getScopeOfOperations(scheme, operation); if (opScopesOthers != null) { for (String scope : opScopesOthers) { if (!opScopesDefault.contains(scope)) { opScopesDefault.add(scope); } } } } updatedDefaultSecurityRequirement.put(SWAGGER_SECURITY_SCHEMA_KEY, opScopesDefault); } } securityRequirements.add(updatedDefaultSecurityRequirement); } operation.setSecurity(securityRequirements); entry.setValue(operation); operationsMap.put(httpMethod, operation); } paths.put(pathKey, pathItem); } swagger.setPaths(paths); return swagger; }
Example 8
Source File: ImportController.java From restfiddle with Apache License 2.0 | 4 votes |
private void swaggerToRFConverter(String projectId, String name, MultipartFile file) throws IOException { // MultipartFile file File tempFile = File.createTempFile("RF_SWAGGER_IMPORT", "JSON"); file.transferTo(tempFile); Swagger swagger = new SwaggerParser().read(tempFile.getAbsolutePath()); String host = swagger.getHost(); String basePath = swagger.getBasePath(); Info info = swagger.getInfo(); String title = info.getTitle(); String description = info.getDescription(); NodeDTO folderNode = createFolder(projectId, title); folderNode.setDescription(description); ConversationDTO conversationDTO; Map<String, Path> paths = swagger.getPaths(); Set<String> keySet = paths.keySet(); for (Iterator<String> iterator = keySet.iterator(); iterator.hasNext();) { String pathKey = iterator.next(); Path path = paths.get(pathKey); Map<HttpMethod, Operation> operationMap = path.getOperationMap(); Set<HttpMethod> operationsKeySet = operationMap.keySet(); for (Iterator<HttpMethod> operIterator = operationsKeySet.iterator(); operIterator.hasNext();) { HttpMethod httpMethod = operIterator.next(); Operation operation = operationMap.get(httpMethod); conversationDTO = new ConversationDTO(); RfRequestDTO rfRequestDTO = new RfRequestDTO(); rfRequestDTO.setApiUrl("http://" + host + basePath + pathKey); rfRequestDTO.setMethodType(httpMethod.name()); operation.getParameters(); conversationDTO.setRfRequestDTO(rfRequestDTO); ConversationDTO createdConversation = conversationController.create(conversationDTO); conversationDTO.setId(createdConversation.getId()); String operationId = operation.getOperationId(); String summary = operation.getSummary(); // Request Node NodeDTO childNode = new NodeDTO(); childNode.setName(operationId); childNode.setDescription(summary); childNode.setProjectId(projectId); childNode.setConversationDTO(conversationDTO); NodeDTO createdChildNode = nodeController.create(folderNode.getId(), childNode); System.out.println("created node : " + createdChildNode.getName()); } } }