Skip to content

Commit

Permalink
Fix API definition content search with anonymous user
Browse files Browse the repository at this point in the history
  • Loading branch information
Avishka-Shamendra committed Sep 18, 2024
1 parent bb03db3 commit 3fa71ef
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4114,7 +4114,7 @@ private void addAPIDefinitionSearchContent(String resourcePath, Registry registr
} else {
index = resourcePath.indexOf(APIConstants.API_OAS_DEFINITION_RESOURCE_NAME);
// swagger.json is included in all types of APIs, hence we need to properly set the API type
setAPITypeForSwagger(resourcePath, index, content, registry);
setAPITypeForSwagger(resourcePath, index, content, registry, apiArtifactManager);
}

String apiPath = resourcePath.substring(0, index) + APIConstants.API_KEY;
Expand Down Expand Up @@ -4160,39 +4160,37 @@ private void addAPIDefinitionSearchContent(String resourcePath, Registry registr
* This method is used to set the correct API Type for swagger.json as all API types have a swagger.json
* file in registry
*
* @param resourcePath registry resourcePath
* @param index int index
* @param content APIDefSearchContent obj.
* @param registry registry obj.
* @param resourcePath registry resourcePath
* @param index int index
* @param content APIDefSearchContent obj.
* @param registry registry obj.
* @param artifactManager artifact manager
* @throws RegistryException on failure
*/
private void setAPITypeForSwagger(String resourcePath, int index,
APIDefSearchContent content, Registry registry) throws RegistryException {
String directoryPath = resourcePath.substring(0, index);
Resource directoryResource = registry.get(directoryPath);

if (directoryResource instanceof Collection) {
Collection collection = (Collection) directoryResource;
int childrenCount = collection.getChildCount();
String[] childPaths = collection.getChildren();
if (childrenCount > 2) {
for (String childPath : childPaths) {
if (childPath.contains(APIConstants.API_ASYNC_API_DEFINITION_RESOURCE_NAME)) {
content.setApiType(APIDefSearchContent.ApiType.ASYNC);
break;
} else if (childPath.contains(APIConstants.GRAPHQL_SCHEMA_FILE_EXTENSION)) {
content.setApiType(APIDefSearchContent.ApiType.GRAPHQL);
break;
} else if (childPath.contains(APIConstants.WSDL_FILE_EXTENSION)) {
content.setApiType(APIDefSearchContent.ApiType.SOAP);
break;
}
}
}
if (content.getApiType() == null) {
APIDefSearchContent content, Registry registry,
GenericArtifactManager
artifactManager) throws RegistryException {

String apiPath = resourcePath.substring(0, index) + APIConstants.API_KEY;
Resource apiResource = registry.get(apiPath);
String apiArtifactId = apiResource.getUUID();
if (apiArtifactId != null) {
GenericArtifact artifact = artifactManager.getGenericArtifact(apiArtifactId);
String type = artifact.getAttribute(APIConstants.API_OVERVIEW_TYPE);
if (APIConstants.API_TYPE_SOAP.equals(type) ||
APIConstants.API_TYPE_SOAPTOREST.equals(type)) {
content.setApiType(APIDefSearchContent.ApiType.SOAP);
} else if (APIConstants.API_TYPE_GRAPHQL.equals(type)) {
content.setApiType(APIDefSearchContent.ApiType.GRAPHQL);
} else if (APIConstants.API_TYPE_WS.equals(type) ||
APIConstants.API_TYPE_WEBHOOK.equals(type) ||
APIConstants.API_TYPE_SSE.equals(type) ||
APIConstants.API_TYPE_WEBSUB.equals(type)) {
content.setApiType(APIDefSearchContent.ApiType.ASYNC);
} else {
content.setApiType(APIDefSearchContent.ApiType.REST);
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public static void setPaginationParams(SearchResultListDTO resultListDTO, String
apiDefSearchResultDTO.setApiType(apiDefResult.getApiType());
apiDefSearchResultDTO.setAssociatedType(apiDefResult.getAssociatedType());
if (apiDefResult.getName().contains("swagger")) {
apiDefSearchResultDTO.setName(apiDefResult.getApiName() + " Swagger Definition");
apiDefSearchResultDTO.setName(apiDefResult.getApiName() + " REST API Definition");
} else if (apiDefResult.getName().contains("graphql")) {
apiDefSearchResultDTO.setName(apiDefResult.getApiName() + " GraphQL Definition");
} else if (apiDefResult.getName().contains("async")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public static void setPaginationParams(SearchResultListDTO resultListDTO, String
apiDefSearchResultDTO.setApiType(apiDefResult.getApiType());
apiDefSearchResultDTO.setAssociatedType(apiDefResult.getAssociatedType());
if (apiDefResult.getName().contains("swagger")) {
apiDefSearchResultDTO.setName(apiDefResult.getApiName() + " Swagger Definition");
apiDefSearchResultDTO.setName(apiDefResult.getApiName() + " REST API Definition");
} else if (apiDefResult.getName().contains("graphql")) {
apiDefSearchResultDTO.setName(apiDefResult.getApiName() + " GraphQL Definition");
} else if (apiDefResult.getName().contains("async")) {
Expand Down

0 comments on commit 3fa71ef

Please sign in to comment.