diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..2bb9ad2 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,176 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/pom.xml b/pom.xml index a943109..00055d2 100644 --- a/pom.xml +++ b/pom.xml @@ -7,9 +7,10 @@ com.verapi.abyss abyss-spec-transformer 1.0-SNAPSHOT + jar - Abyss Spec Transformer - Abyss Spec Transformer Project + Abyss API Specification Transformer + Abyss API Specification Transformer Project https://apiportal.com @@ -48,7 +49,7 @@ Verapi https://verapi.com - Developer + Enterprise Architect +3 @@ -68,13 +69,15 @@ - 3.3.0 - 2.0.9 - 1.24 - 1.16.20 - 1.2.3 - 1.7.25 - 4.12 + UTF-8 + 1.6.3 + 2.0.11 + 2.0.7 + 1.24 + 2.9.8 + 2.9.8 + 2.9.8 + 4.12 3.0.0 2.5 3.7.1 @@ -83,6 +86,7 @@ 3.0.0-M2 3.1.0 3.1.1 + 3.2.1 3.8.0 3.1.0 2.8.2 @@ -99,34 +103,44 @@ - org.apache.cxf - cxf-rt-wsdl - ${cxf.version} + wsdl4j + wsdl4j + ${version.wsdl4j} io.swagger.parser.v3 swagger-parser - ${swagger.parser.version} + ${version.swagger-parser} + + + io.swagger.core.v3 + swagger-models + ${version.swagger-models} org.yaml snakeyaml - ${snakeYaml.version} + ${version.snakeYaml} + + + com.fasterxml.jackson.core + jackson-core + ${version.jackson-core} - org.projectlombok - lombok - ${lombok.version} + com.fasterxml.jackson.core + jackson-annotations + ${version.jackson-annotations} - ch.qos.logback - logback-classic - ${logback.version} + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + ${version.jackson-dataformat-yaml} junit junit - ${junit.version} + ${version.junit} test @@ -218,6 +232,24 @@ 1.8 + + org.apache.maven.plugins + maven-shade-plugin + ${version.maven-shade-plugin} + + + package + + shade + + + + ${project.build.directory}/${project.artifactId}-${project.version}-fat.jar + + + + + org.apache.maven.plugins maven-resources-plugin @@ -373,6 +405,53 @@ + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + ${version.maven-project-info-reports-plugin} + + + org.apache.maven.plugins + maven-dependency-plugin + + + + analyze-report + + + + + + org.apache.maven.plugins + maven-surefire-report-plugin + + + integration-tests + + failsafe-report-only + + + + + + org.codehaus.mojo + versions-maven-plugin + ${versions-maven-plugin} + + + + dependency-updates-report + plugin-updates-report + property-updates-report + + + + + + + release @@ -393,7 +472,7 @@ site - scm:git:https://github.com/apiportal/abyss-echoserver.git + scm:git:https://github.com/apiportal/abyss-spec-transformer.git diff --git a/src/main/java/io/abyss/spec/transformer/IAbyssTransformer.java b/src/main/java/com/verapi/abyss/spec/transformer/IAbyssTransformer.java similarity index 82% rename from src/main/java/io/abyss/spec/transformer/IAbyssTransformer.java rename to src/main/java/com/verapi/abyss/spec/transformer/IAbyssTransformer.java index 2497a50..91846ba 100644 --- a/src/main/java/io/abyss/spec/transformer/IAbyssTransformer.java +++ b/src/main/java/com/verapi/abyss/spec/transformer/IAbyssTransformer.java @@ -17,9 +17,10 @@ * under the License. */ -package io.abyss.spec.transformer; +package com.verapi.abyss.spec.transformer; import com.fasterxml.jackson.core.JsonProcessingException; + import javax.wsdl.WSDLException; /** @@ -27,14 +28,14 @@ * Created on 2019-04-23 */ -public interface IAbyssTransformer -{ +public interface IAbyssTransformer { /** * Transforms the WSDL which given with the definition * * @param path url or directory * @return yaml file - * @throws JsonProcessingException + * @throws JsonProcessingException encountered problem while processing JSON content + * @throws WSDLException encountered problem while processing WSDL content */ String transform(String path) throws JsonProcessingException, WSDLException; } diff --git a/src/main/java/io/abyss/spec/transformer/OpenAPITransformer.java b/src/main/java/com/verapi/abyss/spec/transformer/OpenAPITransformer.java similarity index 80% rename from src/main/java/io/abyss/spec/transformer/OpenAPITransformer.java rename to src/main/java/com/verapi/abyss/spec/transformer/OpenAPITransformer.java index 7cd0238..961499c 100644 --- a/src/main/java/io/abyss/spec/transformer/OpenAPITransformer.java +++ b/src/main/java/com/verapi/abyss/spec/transformer/OpenAPITransformer.java @@ -17,7 +17,7 @@ * under the License. */ -package io.abyss.spec.transformer; +package com.verapi.abyss.spec.transformer; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; @@ -48,11 +48,12 @@ import io.swagger.v3.oas.models.servers.Server; import io.swagger.v3.oas.models.tags.Tag; import io.swagger.v3.oas.models.*; -import lombok.extern.slf4j.Slf4j; import org.w3c.dom.*; + import javax.wsdl.*; import javax.wsdl.extensions.ExtensibilityElement; import java.util.*; + import io.swagger.v3.oas.models.info.Info; import org.yaml.snakeyaml.Yaml; @@ -61,9 +62,7 @@ * Created on 2019-04-23 */ -@Slf4j -public class OpenAPITransformer implements IAbyssTransformer -{ +public class OpenAPITransformer implements IAbyssTransformer { private static final String SOAP11_SERVICE_DESCRIPTION = "Soap 1.1 Service"; private static final String SOAP12_SERVICE_DESCRIPTION = "Soap 1.2 Service"; @@ -89,7 +88,6 @@ public class OpenAPITransformer implements IAbyssTransformer /** * Constructor. - * */ public OpenAPITransformer() { @@ -112,13 +110,12 @@ public OpenAPITransformer() { } /** - * @see io.abyss.spec.transformer.IAbyssTransformer#transform(String) - * - * Transforms the WSDL which defined with the path param - * * @param path url or directory * @return yaml file - * @throws JsonProcessingException + * @throws JsonProcessingException encountered problem while processing JSON content + * @see com.verapi.abyss.spec.transformer.IAbyssTransformer#transform(String) + *

+ * Transforms the WSDL which defined with the path param */ @Override public String transform(final String path) throws JsonProcessingException, WSDLException { @@ -139,13 +136,13 @@ public String transform(final String path) throws JsonProcessingException, WSDLE /** * Resolves servers from services collection * - * @param services services that are resolved from WSDL + * @param services services that are resolved from WSDL * @param portBindingsMap port bindings map include binding definitions, it forwarded to other methods - * @param openAPI opeanAPI + * @param openAPI opeanAPI * @return OpenAPITransformer */ private OpenAPITransformer resolveServers(final Collection services, final Map> portBindingsMap, - final OpenAPI openAPI){ + final OpenAPI openAPI) { final List serverList = new ArrayList<>(); services.forEach(service -> { setInformation(service.getQName().getLocalPart(), openAPI); @@ -165,13 +162,13 @@ private OpenAPITransformer resolveServers(final Collection services, fi /** * Iterates ports for resolve binding name and accessing extensibility elements * - * @param ports ports that are resolved from WSDL + * @param ports ports that are resolved from WSDL * @param portBindingsMap port bindings map include binding definitions, it forwarded to other methods * @return locations list that identify servers */ - private final Set resolvePortsAndBindings(final Collection ports, final Map> portBindingsMap){ + private final Set resolvePortsAndBindings(final Collection ports, final Map> portBindingsMap) { final Set locations = new HashSet<>(); - for(Port port :ports){ + for (Port port : ports) { final String bindingName = port.getBinding().getQName().getLocalPart(); resolvePortExtensibilityElement(port, bindingName, port.getExtensibilityElements(), portBindingsMap, locations); } @@ -182,29 +179,29 @@ private final Set resolvePortsAndBindings(final Collection ports, /** * Iterates extensibility elements for resolve information of soap and http operations * - * @param port port it is resolved from WSDL - * @param bindingName binding name - * @param extElements extensibility elements of the port + * @param port port it is resolved from WSDL + * @param bindingName binding name + * @param extElements extensibility elements of the port * @param portBindingsMap port bindings map include binding definitions - * @param locations locations list that identify servers + * @param locations locations list that identify servers */ private void resolvePortExtensibilityElement(final Port port, final String bindingName, final List extElements, - final Map> portBindingsMap, final Set locations){ + final Map> portBindingsMap, final Set locations) { extElements.forEach(element -> { final Map portBinginAttributes = new HashMap<>(); - if(element instanceof SOAPAddressImpl){ + if (element instanceof SOAPAddressImpl) { portBinginAttributes.put("url", ((SOAPAddressImpl) element).getLocationURI()); portBinginAttributes.put(DESCRIPTION, SOAP11_SERVICE_DESCRIPTION); addOperationsName(port.getBinding().getBindingOperations(), portBinginAttributes); portBindingsMap.put(bindingName, portBinginAttributes); locations.add(((SOAPAddressImpl) element).getLocationURI()); - } else if(element instanceof SOAP12AddressImpl){ + } else if (element instanceof SOAP12AddressImpl) { portBinginAttributes.put("url", ((SOAP12AddressImpl) element).getLocationURI()); portBinginAttributes.put(DESCRIPTION, SOAP12_SERVICE_DESCRIPTION); addOperationsName(port.getBinding().getBindingOperations(), portBinginAttributes); portBindingsMap.put(bindingName, portBinginAttributes); locations.add(((SOAP12AddressImpl) element).getLocationURI()); - } else if(element instanceof HTTPAddressImpl){ + } else if (element instanceof HTTPAddressImpl) { portBinginAttributes.put("url", ((HTTPAddressImpl) element).getLocationURI()); portBinginAttributes.put(DESCRIPTION, HTTP_SERVICE_DESCRIPTION); addOperationsName(port.getBinding().getBindingOperations(), portBinginAttributes); @@ -217,11 +214,11 @@ private void resolvePortExtensibilityElement(final Port port, final String bindi /** * Resolves schemas from types which are declared in the WSDL * - * @param types types it is resolved from WSDL + * @param types types it is resolved from WSDL * @param openAPI opeanAPI * @return OpenAPITransformer */ - private OpenAPITransformer getSchemas(final Types types, final OpenAPI openAPI){ + private OpenAPITransformer getSchemas(final Types types, final OpenAPI openAPI) { final Components components = new Components(); final Map resolvedSchemas = new HashMap<>(); Optional.ofNullable(types).ifPresent(type -> { @@ -241,9 +238,9 @@ private OpenAPITransformer getSchemas(final Types types, final OpenAPI openAPI){ * Resolves schemas from types which are included in the WSDL * * @param schemaReferences schema references includes schemas included in WSDL - * @param resolvedSchemas it contains resolved schemas + * @param resolvedSchemas it contains resolved schemas */ - private void resolveIncludedSchemas(List schemaReferences, final Map resolvedSchemas){ + private void resolveIncludedSchemas(List schemaReferences, final Map resolvedSchemas) { schemaReferences.forEach(schema -> resolvedSchemas.putAll(saveSchemas(schema.getReferencedSchema().getElement().getChildNodes()))); } @@ -251,15 +248,15 @@ private void resolveIncludedSchemas(List schemaReferences, /** * Resolves schemas from types which are imported in the WSDL * - * @param imports imports includes schemas imported in WSDL + * @param imports imports includes schemas imported in WSDL * @param resolvedSchemas it contains resolved schemas */ - private void resolveImportedSchemas(final Map imports, final Map resolvedSchemas){ + private void resolveImportedSchemas(final Map imports, final Map resolvedSchemas) { imports.forEach((k, v) -> - v.forEach(vector -> { - SchemaImportImpl impl = (SchemaImportImpl) vector; - Optional.ofNullable(impl.getReferencedSchema()).ifPresent(schema -> resolvedSchemas.putAll(saveSchemas(schema.getElement().getChildNodes()))); - })); + v.forEach(vector -> { + SchemaImportImpl impl = (SchemaImportImpl) vector; + Optional.ofNullable(impl.getReferencedSchema()).ifPresent(schema -> resolvedSchemas.putAll(saveSchemas(schema.getElement().getChildNodes()))); + })); } /** @@ -268,14 +265,14 @@ private void resolveImportedSchemas(final Map imports, final Map * @param nodeList node list child nodes from dom * @return resolved schemas */ - private Map saveSchemas(final NodeList nodeList){ + private Map saveSchemas(final NodeList nodeList) { final Map schemas = new HashMap<>(); - for(int i=0; i schemas.put(name, childComplexTypeSchema)); - } else if(null != parentNode.getAttributes()) { + } else if (null != parentNode.getAttributes()) { final Schema schema = parseAttributes(parentNode); Optional.ofNullable(schema.getName()).ifPresent(name -> schemas.put(name, schema)); } @@ -290,10 +287,10 @@ private Map saveSchemas(final NodeList nodeList){ * @param nodeList node list * @return schema */ - private Schema checkComplexTypeInChildNodes(final NodeList nodeList){ - for(int i=0; i 0){ + if (sibling.getChildNodes().getLength() > 0) { resolveSiblingChildNodes(schema, sibling.getChildNodes()); } } @@ -349,17 +346,17 @@ private void parseComplexType(final Schema schema, final Node complexType){ /** * Parsing simple type * - * @param schema schema + * @param schema schema * @param nodeList node list */ - private void parseSimpleTypeObject(final Schema schema, final NodeList nodeList){ - for(int i=0; i 0){ + if (sequenceNode.getAttributes() != null && sequenceNode.getAttributes().getLength() > 0) { resolveSequenceNodeMap(schema, sequenceNode.getAttributes()); } } @@ -385,13 +382,13 @@ private void resolveSiblingChildNodes(final Schema schema, final NodeList siblin /** * Resolves sequence node map * - * @param schema schema + * @param schema schema * @param sequenceNodeMap sequence node map */ - private void resolveSequenceNodeMap(final Schema schema, final NamedNodeMap sequenceNodeMap){ - for(int i = 0; i messages, final OpenAPI openAPI){ + private OpenAPITransformer resolveMessages(final Collection messages, final OpenAPI openAPI) { final Map extensions = new HashMap<>(); final Map schemaMap = openAPI.getComponents().getSchemas(); @@ -481,7 +478,7 @@ private OpenAPITransformer resolveMessages(final Collection messages, f attributes.put("$ref", "#/components/schemas/" + messageName); extensions.put(messageName, attributes); - if(null == schemaMap.get(messageName)){ + if (null == schemaMap.get(messageName)) { final Schema schema = new Schema(); schema.setName(messageName); schema.setTitle(messageName); @@ -505,16 +502,16 @@ private OpenAPITransformer resolveMessages(final Collection messages, f /** * Generates schemas for message extensions * - * @param schema schema - * @param itemName item name - * @param type type + * @param schema schema + * @param itemName item name + * @param type type * @param schemaMap schema map */ - private void getSchemaForMessages(final Schema schema, final String itemName, final String type, final Map schemaMap){ + private void getSchemaForMessages(final Schema schema, final String itemName, final String type, final Map schemaMap) { schema.addRequiredItem(itemName); Schema propertyItem = new Schema(); - if(null != schemaMap.get(type)){ + if (null != schemaMap.get(type)) { propertyItem.set$ref("#/components/schemas/" + type); } else { propertyItem = getPropertyItem(dataTypes.get(type)); @@ -525,13 +522,13 @@ private void getSchemaForMessages(final Schema schema, final String itemName, fi /** * Resolves tags and paths from bindings for Open API * - * @param bindings bindings that are resolved from WSDL + * @param bindings bindings that are resolved from WSDL * @param portBindingsMap port bindings map include binding definitions - * @param openAPI openAPI + * @param openAPI openAPI */ - private OpenAPITransformer resolveTagsAndSetPaths(final Collection bindings, final Map> portBindingsMap, final OpenAPI openAPI){ + private OpenAPITransformer resolveTagsAndSetPaths(final Collection bindings, final Map> portBindingsMap, final OpenAPI openAPI) { final List tagList = new ArrayList<>(); - final Map> discoveredPathsMap = new HashMap<>(); + final Map> discoveredPathsMap = new HashMap<>(); bindings.forEach(binding -> { final String httpMethod = resolveHttpMethod(binding.getExtensibilityElements()); final Map tagAttributes = portBindingsMap.get(binding.getQName().getLocalPart()); @@ -558,10 +555,10 @@ private OpenAPITransformer resolveTagsAndSetPaths(final Collection bind * @param exElements exElements list of extensibility element * @return http method */ - private String resolveHttpMethod(final List exElements){ + private String resolveHttpMethod(final List exElements) { String httpMethod = "post"; - for(ExtensibilityElement element :exElements){ - if(element instanceof HTTPBindingImpl){ + for (ExtensibilityElement element : exElements) { + if (element instanceof HTTPBindingImpl) { httpMethod = ((HTTPBindingImpl) element).getVerb().toLowerCase(); } } @@ -571,25 +568,25 @@ private String resolveHttpMethod(final List exElements){ /** * Discovers paths from binding operations for Open API * - * @param httpMethod http method + * @param httpMethod http method * @param bindingOperations binding operations that are resolved from the WSDL - * @param portBindingsMap port bindings map include binding definitions - * @param discoveredPaths discovered paths include paths + * @param portBindingsMap port bindings map include binding definitions + * @param discoveredPaths discovered paths include paths */ private void discoverPaths(final String httpMethod, final List bindingOperations, - final Map> portBindingsMap, final Map> discoveredPaths){ - for(BindingOperationImpl impl :bindingOperations){ + final Map> portBindingsMap, final Map> discoveredPaths) { + for (BindingOperationImpl impl : bindingOperations) { final List exList = impl.getExtensibilityElements(); Map pathAttributes; - for(ExtensibilityElement element :exList){ - if(element instanceof SOAPOperationImpl || element instanceof SOAP12OperationImpl){ + for (ExtensibilityElement element : exList) { + if (element instanceof SOAPOperationImpl || element instanceof SOAP12OperationImpl) { pathAttributes = setPathAttributes("SoapService", impl.getName(), httpMethod, impl.getOperation().getInput().getMessage(), impl.getOperation().getOutput().getMessage(), impl.getOperation().getFaults()); addPathTags(impl.getName(), "soap", pathAttributes, portBindingsMap); discoveredPaths.put(impl.getName(), pathAttributes); - } else if(element instanceof HTTPOperationImpl){ + } else if (element instanceof HTTPOperationImpl) { pathAttributes = setPathAttributes("HttpService", impl.getName(), httpMethod, impl.getOperation().getInput().getMessage(), impl.getOperation().getOutput().getMessage(), impl.getOperation().getFaults()); @@ -603,22 +600,22 @@ private void discoverPaths(final String httpMethod, final List setPathAttributes(final String description, final String operationName, final String httpMethod, - final Message inputMessage, final Message outputMessage, final Map faultMap){ + final Message inputMessage, final Message outputMessage, final Map faultMap) { final Map pathAttributes = new HashMap<>(); pathAttributes.put(DESCRIPTION, description); pathAttributes.put("operation", operationName); pathAttributes.put("method", httpMethod); - Optional.ofNullable(inputMessage).ifPresent(message -> pathAttributes.put(REQUEST_BODY_KEY, message.getQName().getLocalPart())); + Optional.ofNullable(inputMessage).ifPresent(message -> pathAttributes.put(REQUEST_BODY_KEY, message.getQName().getLocalPart())); Optional.ofNullable(outputMessage).ifPresent(message -> pathAttributes.put(RESPONSE_KEY, message.getQName().getLocalPart())); pathAttributes.put("faults", !faultMap.isEmpty()); @@ -628,27 +625,27 @@ private final Map setPathAttributes(final String description, fi /** * Defines tags for paths * - * @param operationName operation name - * @param requestType request type - * @param pathAttributes path attributes + * @param operationName operation name + * @param requestType request type + * @param pathAttributes path attributes * @param portBindingsMap port bindings map include binding definitions */ private void addPathTags(final String operationName, final String requestType, - final Map pathAttributes, final Map> portBindingsMap){ + final Map pathAttributes, final Map> portBindingsMap) { portBindingsMap.forEach((key, value) -> { final Map attributes = value; attributes.forEach((k, v) -> { - if(k.equals("operations")){ + if (k.equals("operations")) { final List names = (List) v; final List tags = null != pathAttributes.get("tags") - ?(List) pathAttributes.get("tags"):new ArrayList<>(); + ? (List) pathAttributes.get("tags") : new ArrayList<>(); final Set locations = null != pathAttributes.get(LOCATIONS_KEY) - ?(Set) pathAttributes.get(LOCATIONS_KEY):new HashSet<>(); + ? (Set) pathAttributes.get(LOCATIONS_KEY) : new HashSet<>(); names.forEach(n -> { final String desc = value.get(DESCRIPTION).toString().toLowerCase(); - if(n.equals(operationName) && desc.contains(requestType)){ - tags.add(key); - locations.add((String) value.get("url")); + if (n.equals(operationName) && desc.contains(requestType)) { + tags.add(key); + locations.add((String) value.get("url")); } pathAttributes.put("tags", tags); pathAttributes.put(LOCATIONS_KEY, locations); @@ -664,9 +661,9 @@ private void addPathTags(final String operationName, final String requestType, * @param nodeList node list * @return documentation information */ - private String getDocumentation(final NodeList nodeList){ + private String getDocumentation(final NodeList nodeList) { String data = ""; - for(int i=0; i bindingOperations, final Map portBindingAttributes){ + private void addOperationsName(final List bindingOperations, final Map portBindingAttributes) { final List names = new ArrayList<>(); bindingOperations.forEach(operation -> names.add(operation.getName())); portBindingAttributes.put("operations", names); @@ -704,9 +701,9 @@ private void addOperationsName(final List bindingOperations, f * Sets paths on Open API * * @param discoveredPathsMap discovered paths map - * @param openAPI openAPI + * @param openAPI openAPI */ - private void setPaths(final Map> discoveredPathsMap, final OpenAPI openAPI){ + private void setPaths(final Map> discoveredPathsMap, final OpenAPI openAPI) { final Paths paths = new Paths(); discoveredPathsMap.forEach((k, v) -> { @@ -731,26 +728,26 @@ private void setPaths(final Map> discoveredPathsMap * @param bodyName body name * @return RequestBody */ - private RequestBody getRequestBodyForPath(final String bodyName){ + private RequestBody getRequestBodyForPath(final String bodyName) { final RequestBody requestBody = new RequestBody(); requestBody.set$ref("#/components/requestBodies/" + bodyName); return requestBody; } /** - * Returns api responses for Open API + * Returns api responses for Open API * * @param response response - * @param faults faults + * @param faults faults * @return ApiResponses */ - private ApiResponses getApiResponseForPath(final String response, final boolean faults){ + private ApiResponses getApiResponseForPath(final String response, final boolean faults) { final ApiResponses apiResponses = new ApiResponses(); final ApiResponse okResponse = new ApiResponse(); okResponse.set$ref("#/components/responses/200_" + response); apiResponses.addApiResponse(DEFAULT_SUCCESS_RESPONSE_CODE, okResponse); - if(faults){ + if (faults) { final ApiResponse faultResponse = new ApiResponse(); faultResponse.set$ref(DEFAULT_FAULT_RESPONSE_REF); apiResponses.addApiResponse(DEFAULT_FAULT_RESPONSE_CODE, faultResponse); @@ -765,9 +762,9 @@ private ApiResponses getApiResponseForPath(final String response, final boolean * @param httpMethod http method * @return PathItem */ - private PathItem getPathItem(final String httpMethod, final Operation operation){ + private PathItem getPathItem(final String httpMethod, final Operation operation) { final PathItem pathItem = new PathItem(); - switch (httpMethod){ + switch (httpMethod) { case "get": pathItem.setGet(operation); break; @@ -791,11 +788,11 @@ private PathItem getPathItem(final String httpMethod, final Operation operation) /** * Overrides servers on paths if more than one * - * @param servers servers + * @param servers servers * @param pathItem path item */ - private void overrideServersIfMoreThanOne(final List servers, final Set location, final PathItem pathItem){ - if(servers.size() > 1){ + private void overrideServersIfMoreThanOne(final List servers, final Set location, final PathItem pathItem) { + if (servers.size() > 1) { final List serverList = new ArrayList<>(); location.forEach(s -> { final Server server = new Server(); @@ -811,23 +808,23 @@ private void overrideServersIfMoreThanOne(final List servers, final Set< * Adds request bodies and responses on Open API * * @param portTypes port types - * @param openAPI openAPI + * @param openAPI openAPI * @return OpenAPITransformer */ - private OpenAPITransformer addRequestBodiesAndResponses(final Collection portTypes, final OpenAPI openAPI){ + private OpenAPITransformer addRequestBodiesAndResponses(final Collection portTypes, final OpenAPI openAPI) { final Optional> componentExt = Optional.ofNullable(openAPI.getComponents().getExtensions()); componentExt.ifPresent(ext -> { final Map extensions = (Map) ext.get(MESSAGE_EXTENSIONS); - for(PortType portType :portTypes){ + for (PortType portType : portTypes) { final List operations = portType.getOperations(); - for(javax.wsdl.Operation operation :operations){ - if(null != operation.getInput().getMessage()) { + for (javax.wsdl.Operation operation : operations) { + if (null != operation.getInput().getMessage()) { addRequestBodies(operation.getInput().getMessage().getQName().getLocalPart(), extensions, openAPI); } - if(null != operation.getOutput().getMessage()) { + if (null != operation.getOutput().getMessage()) { addResponses(operation.getOutput().getMessage().getQName().getLocalPart(), extensions, openAPI); } - if(!operation.getFaults().isEmpty()){ + if (!operation.getFaults().isEmpty()) { addFaultResponses(operation.getFaults(), openAPI); } } @@ -840,12 +837,12 @@ private OpenAPITransformer addRequestBodiesAndResponses(final Collection extensions, final OpenAPI openAPI){ - if(null != extensions.get(bodyName)){ + private void addRequestBodies(final String bodyName, final Map extensions, final OpenAPI openAPI) { + if (null != extensions.get(bodyName)) { final RequestBody requestBody = new RequestBody(); final Schema bodySchema = new Schema(); requestBody.setDescription(bodyName + " message object as request body"); @@ -860,11 +857,11 @@ private void addRequestBodies(final String bodyName, final Map e * Adds responses on Open API * * @param responseName response name - * @param extensions extensions - * @param openAPI openAPI + * @param extensions extensions + * @param openAPI openAPI */ - private void addResponses(final String responseName, final Map extensions, final OpenAPI openAPI){ - if(null != extensions.get(responseName)){ + private void addResponses(final String responseName, final Map extensions, final OpenAPI openAPI) { + if (null != extensions.get(responseName)) { openAPI.getComponents().addResponses(String.join("_", DEFAULT_SUCCESS_RESPONSE_CODE, responseName), getResponse(responseName, "Successful operation")); } } @@ -872,11 +869,11 @@ private void addResponses(final String responseName, final Map e /** * Returns api response * - * @param name name + * @param name name * @param description description * @return ApiResponse */ - private ApiResponse getResponse(final String name, final String description){ + private ApiResponse getResponse(final String name, final String description) { final ApiResponse apiResponse = new ApiResponse(); final Schema responseSchema = new Schema(); responseSchema.set$ref(MESSAGE_EXTENSIONS_PREFIX + name); @@ -890,16 +887,16 @@ private ApiResponse getResponse(final String name, final String description){ * Adds fault responses on Open API * * @param faultMap fault map - * @param openAPI openAPI + * @param openAPI openAPI */ - private void addFaultResponses(final Map faultMap, final OpenAPI openAPI){ + private void addFaultResponses(final Map faultMap, final OpenAPI openAPI) { final ComposedSchema composedSchema = new ComposedSchema(); faultMap.forEach((k, v) -> - Optional.ofNullable(v.getMessage().getQName()).ifPresent(q -> { - final Schema schema = new Schema(); - schema.set$ref("#/components/" + MESSAGE_EXTENSIONS + "/" + q.getLocalPart()); - composedSchema.addOneOfItem(schema); - })); + Optional.ofNullable(v.getMessage().getQName()).ifPresent(q -> { + final Schema schema = new Schema(); + schema.set$ref("#/components/" + MESSAGE_EXTENSIONS + "/" + q.getLocalPart()); + composedSchema.addOneOfItem(schema); + })); final ApiResponse faultResponse = new ApiResponse(); faultResponse.setDescription("Fault Error"); @@ -912,7 +909,7 @@ private void addFaultResponses(final Map faultMap, final OpenAPI * * @param openAPI openAPI * @return yaml file - * @throws JsonProcessingException + * @throws JsonProcessingException encountered problem while processing JSON content */ private String generateYamlFile(final OpenAPI openAPI) throws JsonProcessingException { final YAMLFactory yamlFactory = new YAMLFactory() diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml deleted file mode 100644 index 10283b7..0000000 --- a/src/main/resources/logback.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - log/abyss-spec-transformer.log - - - abyss-%d{yyyy-MM-dd}.%i.log - - 100MB - 60 - 20GB - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{35} - %msg%n - - - - - - - - - \ No newline at end of file diff --git a/src/test/java/io/abyss/spec/transformer/SwaggerFileTest.java b/src/test/java/com/verapi/abyss/spec/transformer/SwaggerFileTest.java similarity index 93% rename from src/test/java/io/abyss/spec/transformer/SwaggerFileTest.java rename to src/test/java/com/verapi/abyss/spec/transformer/SwaggerFileTest.java index 223bde8..0dddb18 100644 --- a/src/test/java/io/abyss/spec/transformer/SwaggerFileTest.java +++ b/src/test/java/com/verapi/abyss/spec/transformer/SwaggerFileTest.java @@ -1,10 +1,12 @@ -package io.abyss.spec.transformer; +package com.verapi.abyss.spec.transformer; import com.fasterxml.jackson.core.JsonProcessingException; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; + import static org.junit.Assert.assertFalse; + import javax.wsdl.WSDLException; /**