From 39588039f27e4b2cb2d1cb8351c07e96a510ada7 Mon Sep 17 00:00:00 2001 From: rdavidek Date: Mon, 15 Dec 2025 14:17:49 +0100 Subject: [PATCH] urls to swagger draft --- .../impl/v32/Wso2v32ToApicurioFromDir.java | 74 +++++-------------- 1 file changed, 17 insertions(+), 57 deletions(-) diff --git a/src/main/java/cz/trask/migration/impl/v32/Wso2v32ToApicurioFromDir.java b/src/main/java/cz/trask/migration/impl/v32/Wso2v32ToApicurioFromDir.java index c909269..dc14d66 100644 --- a/src/main/java/cz/trask/migration/impl/v32/Wso2v32ToApicurioFromDir.java +++ b/src/main/java/cz/trask/migration/impl/v32/Wso2v32ToApicurioFromDir.java @@ -107,9 +107,10 @@ public class Wso2v32ToApicurioFromDir extends AbstractProcess { APIInfo api = new APIInfo(); api.setName(apiDef.getId().getApiName()); api.setVersion(apiDef.getId().getVersion()); - api.setContext(apiDef.getContext()); + api.setContext(apiDef.getContext().substring(0, apiDef.getContext().indexOf('/', 1))); api.setDescription((String) ((Map) swaggerMap.get("info")).get("description")); api.setType(apiDef.getType()); + api.setId(apiDef.getUuid()); System.out.println("Context: " + apiDef.getContext()); @@ -134,7 +135,7 @@ public class Wso2v32ToApicurioFromDir extends AbstractProcess { + devPortUrl; ObjectNode swaggerObj = mapperYaml.valueToTree(swaggerMap); - // updateSwagger(swaggerObj, apiMap, fullDesc); + updateSwagger(swaggerObj, apiDef, fullDesc); String group = config.getApicurio().getDefaultApiGroup(); String mainArtifactId = api.getName() + api.getContext(); @@ -209,7 +210,7 @@ public class Wso2v32ToApicurioFromDir extends AbstractProcess { /* Helper methods */ /* --------------------------------------------------------------------- */ - private void updateSwagger(ObjectNode swagger, Map apiMap, String description) { + private void updateSwagger(ObjectNode swagger, ApiDefinition32 apiDef, String description) { // Update "info.description" ObjectNode info = (ObjectNode) swagger.get("info"); if (info != null) { @@ -219,41 +220,25 @@ public class Wso2v32ToApicurioFromDir extends AbstractProcess { // Build "servers" array ArrayNode servers = mapper.createArrayNode(); - List> endpoints = (List>) apiMap.get("endpointURLs"); + Map endpoints = apiDef.getEndpointConfig(); if (endpoints != null) { - for (Map env : endpoints) { - Map urls = (Map) env.get("URLs"); - if (urls == null || urls.isEmpty()) - continue; - ObjectNode server = mapper.createObjectNode(); - urls.forEach((k, v) -> { - if (v != null && !v.isBlank()) { - if (k.equals("https") || k.equals("wss")) { - server.put("url", v); - } - } - }); - server.put("description", "Gateway: " + env.getOrDefault("environmentName", "")); - servers.add(server); + Map prodEps = (Map) endpoints.get("production_endpoints"); + Map sandEps = (Map) endpoints.get("sandbox_endpoints"); + + + ObjectNode server = mapper.createObjectNode(); + if (k.equals("https") || k.equals("wss")) { + server.put("url", v); } + server.put("description", "Gateway: " + env.getOrDefault("environmentName", "")); + servers.add(server); } - - // Replace "servers" node - swagger.set("servers", servers); } - private void addSubscriptionsToProps(Map props, Subscriptions subs) { - if (subs == null || subs.getList() == null || subs.getList().isEmpty()) - return; - int i = 1; - for (Subscription sub : subs.getList()) { - ApplicationInfo appInfo = sub.getApplicationInfo(); - if (appInfo == null) - continue; - props.put("subscription" + i, appInfo.getName() + " (Owner: " + appInfo.getSubscriber() + ")"); - i++; - } + // Replace "servers" node + swagger.set("servers",servers); + } private void addEndpointsToProps(Map props, Map apiMap) { @@ -303,29 +288,4 @@ public class Wso2v32ToApicurioFromDir extends AbstractProcess { } return references; } - - private void addSubscriptionsToReferences(List references, Subscriptions subs, APIInfo api) - throws Exception { - if (subs == null || subs.getList() == null || subs.getList().isEmpty()) - return; - - String artifactId = api.getName() + "/" + api.getVersion() + "/" + ARTIFACT_NAME_SUBSCRIPTIONS; - - byte[] subsBytes = mapperYaml.writeValueAsBytes(subs); - - try (ByteArrayInputStream is = new ByteArrayInputStream(subsBytes)) { - ArtifactMetaData meta = client.createArtifactWithVersion(ARTIFACT_GROUP_SUBSCRIPTIONS, artifactId, - api.getVersion(), is); - Map props = new LinkedHashMap<>(); - props.put(PARAM_SOURCE_APIM, VERSION_32); - setArtifactMetaData(meta, props); - } - - ArtifactReference ref = new ArtifactReference(); - ref.setName(ARTIFACT_NAME_SUBSCRIPTIONS); - ref.setGroupId(ARTIFACT_GROUP_SUBSCRIPTIONS); - ref.setArtifactId(artifactId); - ref.setVersion(api.getVersion()); - references.add(ref); - } }