urls to swagger draft
This commit is contained in:
parent
8e8fb1ddee
commit
39588039f2
@ -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<String, Object>) 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<String, Object> 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<Map<String, Object>> endpoints = (List<Map<String, Object>>) apiMap.get("endpointURLs");
|
||||
Map<String, Object> endpoints = apiDef.getEndpointConfig();
|
||||
if (endpoints != null) {
|
||||
for (Map<String, Object> env : endpoints) {
|
||||
Map<String, String> urls = (Map<String, String>) env.get("URLs");
|
||||
if (urls == null || urls.isEmpty())
|
||||
continue;
|
||||
|
||||
Map<String, Object> prodEps = (Map<String, Object>) endpoints.get("production_endpoints");
|
||||
Map<String, Object> sandEps = (Map<String, Object>) endpoints.get("sandbox_endpoints");
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// Replace "servers" node
|
||||
swagger.set("servers", servers);
|
||||
}
|
||||
swagger.set("servers",servers);
|
||||
|
||||
private void addSubscriptionsToProps(Map<String, String> 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++;
|
||||
}
|
||||
}
|
||||
|
||||
private void addEndpointsToProps(Map<String, String> props, Map<String, Object> apiMap) {
|
||||
@ -303,29 +288,4 @@ public class Wso2v32ToApicurioFromDir extends AbstractProcess {
|
||||
}
|
||||
return references;
|
||||
}
|
||||
|
||||
private void addSubscriptionsToReferences(List<ArtifactReference> 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<String, String> 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);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user