Source:
private boolean isValidEndpointDefinition(URL definitionURL, InputStream definitionFileInputStream, String definitionType) { String definitionContent = null; try { if (definitionURL != null) { definitionContent = IOUtils.toString(definitionURL.openStream()); } else if (definitionFileInputStream != null) { definitionContent = IOUtils.toString(definitionFileInputStream); definitionFileInputStream.reset(); } } catch (IOException e) { log.error("Error in reading endpoint definition content", e); return false; } if (StringUtils.isEmpty(definitionContent)) { log.error("No endpoint definition content found"); return false; } boolean isValid = false; if (RegistryEntryDTO.DefinitionTypeEnum.OAS.toString().equals(definitionType)) { try { APIDefinitionValidationResponse response = OASParserUtil.validateAPIDefinition(definitionContent,false); isValid = response.isValid(); } catch (APIManagementException | ClassCastException e) { log.error("Unable to parse the OpenAPI endpoint definition", e); } } else if (RegistryEntryDTO.DefinitionTypeEnum.WSDL1.toString().equals(definitionType) || RegistryEntryDTO.DefinitionTypeEnum.WSDL2.toString().equals(definitionType)) { try { if (definitionURL != null) { isValid = APIMWSDLReader.validateWSDLUrl(definitionURL).isValid(); } else { isValid = APIMWSDLReader.validateWSDLFile(definitionFileInputStream).isValid(); definitionFileInputStream.reset(); } } catch (APIManagementException e) { log.error("Unable to parse the WSDL endpoint definition", e); } catch (IOException e) { log.error("Error in reading endpoint definition file content", e); } } else if (RegistryEntryDTO.DefinitionTypeEnum.GQL_SDL.toString().equals(definitionType)) { try { SchemaParser schemaParser = new SchemaParser(); TypeDefinitionRegistry typeRegistry = schemaParser.parse(definitionContent); GraphQLSchema graphQLSchema = UnExecutableSchemaGenerator.makeUnExecutableSchema(typeRegistry); SchemaValidator schemaValidation = new SchemaValidator(); Set<SchemaValidationError> validationErrors = schemaValidation.validateSchema(graphQLSchema); isValid = (validationErrors.toArray().length == 0); } catch (SchemaProblem e) { log.error("Unable to parse the GraphQL endpoint definition", e); } } return isValid; }

Target:
private boolean isValidEndpointDefinition(URL definitionURL, InputStream definitionFileInputStream, String definitionType) { String definitionContent = null; try { if (definitionFileInputStream != null) { definitionContent = IOUtils.toString(definitionFileInputStream); definitionFileInputStream.reset(); } else if (definitionURL != null) { definitionContent = IOUtils.toString(definitionURL.openStream()); } } catch (IOException e) { log.error("Error in reading endpoint definition content", e); return false; } if (StringUtils.isEmpty(definitionContent)) { log.error("No endpoint definition content found"); return false; } boolean isValid = false; if (RegistryEntryDTO.DefinitionTypeEnum.OAS.toString().equals(definitionType)) { try { APIDefinitionValidationResponse response = OASParserUtil.validateAPIDefinition(definitionContent,false); isValid = response.isValid(); } catch (APIManagementException | ClassCastException e) { log.error("Unable to parse the OpenAPI endpoint definition", e); } } else if (RegistryEntryDTO.DefinitionTypeEnum.WSDL1.toString().equals(definitionType) || RegistryEntryDTO.DefinitionTypeEnum.WSDL2.toString().equals(definitionType)) { try { if (definitionFileInputStream != null) { isValid = APIMWSDLReader.validateWSDLFile(definitionFileInputStream).isValid(); definitionFileInputStream.reset(); } else { isValid = APIMWSDLReader.validateWSDLUrl(definitionURL).isValid(); } } catch (APIManagementException e) { log.error("Unable to parse the WSDL endpoint definition", e); } catch (IOException e) { log.error("Error in reading endpoint definition file content", e); } } else if (RegistryEntryDTO.DefinitionTypeEnum.GQL_SDL.toString().equals(definitionType)) { try { SchemaParser schemaParser = new SchemaParser(); TypeDefinitionRegistry typeRegistry = schemaParser.parse(definitionContent); GraphQLSchema graphQLSchema = UnExecutableSchemaGenerator.makeUnExecutableSchema(typeRegistry); SchemaValidator schemaValidation = new SchemaValidator(); Set<SchemaValidationError> validationErrors = schemaValidation.validateSchema(graphQLSchema); isValid = (validationErrors.toArray().length == 0); } catch (SchemaProblem e) { log.error("Unable to parse the GraphQL endpoint definition", e); } } return isValid; }