Skip to content

Commit

Permalink
Fix issues with revamp swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
chashikajw committed Oct 9, 2023
1 parent edf1603 commit a7d7fef
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function getAPIByIdTest() {
@test:Config {dependsOn: [createAPITest]}
function getAPIDefinitionTest() {
APIDefinition|commons:APKError getAPIDef = getAPIDefinition("01ed75e2-b30b-18c8-wwf2-25da7edd2231");
if getAPIDef is API {
if getAPIDef is APIDefinition {
test:assertTrue(true, "Successfully retrieve API Definition");
log:printInfo(getAPIDef.toString());
} else if getAPIDef is commons:APKError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public function getApiDataProvider() returns map<[string, string, anydata]> {
"context": "pizzssa",
"version": "1.0.0",
"organization": "1111-1111-1111-1111",
"lifeCycleStatus" : (),
"provider": (),
"type": "HTTP",
"state": "CREATED",
"status": "CREATED"
Expand All @@ -135,7 +137,8 @@ function updateInternalAPITest() {
"version":"1.0.0",
"lifeCycleStatus":"CREATED",
"organization":"1111-1111-1111-1111",
"type":"HTTP"
"type":"HTTP",
"provider":"admin"
},
"Definition" : {
"openapi": "3.0.0",
Expand Down
12 changes: 6 additions & 6 deletions devportal/devportal-domain-service/ballerina/apiDAO.bal
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ isolated function getAPIByIdDAO(string apiId) returns API|commons:APKError|NotFo
}
}

isolated function getAPIsDAO(string org) returns API[]|commons:APKError {
isolated function getAPIsDAO(string org) returns APIInfo[]|commons:APKError {
postgresql:Client | error dbClient = getConnection();
if dbClient is error {
string message = "Error while retrieving connection";
Expand All @@ -61,8 +61,8 @@ isolated function getAPIsDAO(string org) returns API[]|commons:APKError {
API_NAME as NAME, API_VERSION as VERSION,CONTEXT, ORGANIZATION,STATUS,
API_TYPE as TYPE, ARTIFACT as ARTIFACT FROM API WHERE ORGANIZATION =${org} AND
STATUS IN (${PUBLISHED},${PROTOTYPED},${DEPRECATED})`;
stream<API, sql:Error?> apisStream = dbClient->query(query);
API[] apis = check from API api in apisStream select api;
stream<APIInfo, sql:Error?> apisStream = dbClient->query(query);
APIInfo[] apis = check from APIInfo api in apisStream select api;
check apisStream.close();
return apis;
} on fail var e {
Expand All @@ -72,7 +72,7 @@ isolated function getAPIsDAO(string org) returns API[]|commons:APKError {
}
}

isolated function getAPIsByQueryDAO(string payload, string org) returns API[]|commons:APKError {
isolated function getAPIsByQueryDAO(string payload, string org) returns APIInfo[]|commons:APKError {
postgresql:Client | error dbClient = getConnection();
if dbClient is error {
string message = "Error while retrieving connection";
Expand All @@ -84,8 +84,8 @@ isolated function getAPIsByQueryDAO(string payload, string org) returns API[]|co
API_TYPE as TYPE, ARTIFACT as ARTIFACT FROM API JOIN JSONB_EACH_TEXT(ARTIFACT) e ON true
WHERE ORGANIZATION =${org} AND e.value LIKE ${payload} AND
STATUS IN (${PUBLISHED},${PROTOTYPED},${DEPRECATED})`;
stream<API, sql:Error?> apisStream = dbClient->query(query);
API[] apis = check from API api in apisStream select api;
stream<APIInfo, sql:Error?> apisStream = dbClient->query(query);
APIInfo[] apis = check from APIInfo api in apisStream select api;
check apisStream.close();
return apis;
} on fail var e {
Expand Down
21 changes: 10 additions & 11 deletions devportal/devportal-domain-service/ballerina/apiImpl.bal
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ isolated function getAPIByAPIId(string apiId) returns API|NotFoundError|commons:

isolated function getAPIList(int 'limit, int offset, string? query, commons:Organization organization) returns APIList|commons:APKError {
if query !is string {
API[]|commons:APKError apis = getAPIsDAO(organization.uuid);
if apis is API[] {
API[] limitSet = [];
APIInfo[]|commons:APKError apis = getAPIsDAO(organization.uuid);
if apis is APIInfo[] {
APIInfo[] limitSet = [];
if apis.length() > offset {
foreach int i in offset ... (apis.length() - 1) {
if limitSet.length() < 'limit {
Expand All @@ -51,9 +51,9 @@ isolated function getAPIList(int 'limit, int offset, string? query, commons:Orga
int? index = query.indexOf(":");
if index is int {
string modifiedQuery = "%" + query.substring(index + 1) + "%";
API[]|commons:APKError apis = getAPIsByQueryDAO(modifiedQuery, organization.uuid);
if apis is API[] {
API[] limitSet = [];
APIInfo[]|commons:APKError apis = getAPIsByQueryDAO(modifiedQuery, organization.uuid);
if apis is APIInfo[] {
APIInfo[] limitSet = [];
if apis.length() > offset {
foreach int i in offset ... (apis.length() - 1) {
if limitSet.length() < 'limit {
Expand Down Expand Up @@ -181,9 +181,9 @@ isolated function getDocumentMetaData(string apiId, string documentId) returns D
documentId: getDocumentMetaData.documentId,
name: getDocumentMetaData.name,
summary: getDocumentMetaData.summary,
sourceType: getDocumentMetaData.sourceType,
sourceType: <"INLINE"|"MARKDOWN"|"URL"|"FILE">getDocumentMetaData.sourceType,
sourceUrl: getDocumentMetaData.sourceUrl,
documentType: getDocumentMetaData.documentType,
documentType: <"HOWTO"|"SAMPLES"|"PUBLIC_FORUM"|"SUPPORT_FORUM"|"API_MESSAGE_FORMAT"|"SWAGGER_DOC"|"OTHER">getDocumentMetaData.documentType,
otherTypeName: getDocumentMetaData.otherTypeName
};
return document;
Expand Down Expand Up @@ -241,8 +241,7 @@ isolated function getDocumentList(string apiId, int 'limit, int offset) returns
} else {
return documents;
}
} else {
string message = "Internal Error occured while retrieving API for Docuements retieval";
return error(message, message = message, description = message, code = 909001, statusCode = 500);
} else if api is NotFoundError|commons:APKError {
return api;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ isolated function getApplicationByIdDAO(string appId, string org) returns Applic
}
}

isolated function getApplicationsDAO(string org) returns Application[]|commons:APKError {
isolated function getApplicationsDAO(string org) returns ApplicationInfo[]|commons:APKError {
postgresql:Client|error dbClient = getConnection();
if dbClient is error {
string message = "Error while retrieving connection";
Expand All @@ -119,8 +119,8 @@ isolated function getApplicationsDAO(string org) returns Application[]|commons:A
do {
sql:ParameterizedQuery query = `SELECT NAME, UUID as APPLICATIONID, DESCRIPTION, APPLICATION_TIER as THROTTLINGPOLICY, TOKEN_TYPE as TOKENTYPE, ORGANIZATION,
APPLICATION_STATUS as STATUS FROM APPLICATION WHERE ORGANIZATION =${org}`;
stream<Application, sql:Error?> applicationStream = dbClient->query(query);
Application[] applications = check from Application application in applicationStream
stream<ApplicationInfo, sql:Error?> applicationStream = dbClient->query(query);
ApplicationInfo[] applications = check from ApplicationInfo application in applicationStream
select application;
check applicationStream.close();
return applications;
Expand Down
28 changes: 14 additions & 14 deletions devportal/devportal-domain-service/ballerina/applicationImpl.bal
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
// specific language governing permissions and limitations
// under the License.
//

import ballerina/log;
import ballerina/time;
import ballerina/uuid;

import wso2/apk_common_lib as commons;
import wso2/notification_grpc_client;
import devportal_service.types;
import devportal_service.kmclient;
import ballerina/time;

isolated function addApplication(Application application, commons:Organization org, string user) returns NotFoundError|Application|commons:APKError {
string applicationId = uuid:createType1AsString();
Expand Down Expand Up @@ -98,8 +98,8 @@ isolated function getApplicationById(string appId, commons:Organization org) ret
}

isolated function getApplicationList(string? sortBy, string? groupId, string? query, string? sortOrder, int 'limit, int offset, commons:Organization org) returns ApplicationList|commons:APKError {
Application[]|commons:APKError applications = getApplicationsDAO(org.uuid);
if applications is Application[] {
ApplicationInfo[]|commons:APKError applications = getApplicationsDAO(org.uuid);
if applications is ApplicationInfo[] {
int count = applications.length();
ApplicationList applicationsList = {count: count, list: applications};
return applicationsList;
Expand Down Expand Up @@ -199,9 +199,8 @@ isolated function deleteOauthApps(string appId, commons:Organization organizatio

isolated function generateAPIKey(APIKeyGenerateRequest payload, string appId, string keyType, string user, commons:Organization org) returns APIKey|commons:APKError|NotFoundError {
Application|NotFoundError application = check getApplicationById(appId, org);
if application !is Application {
string message = "Internal Error occured while retrieving Application Info for API Key";
return error(message, message = message, description = message, code = 909001, statusCode = 500);
if application is NotFoundError {
return application;
} else {
boolean userAllowed = checkUserAccessAllowedForApplication(application, user);
if userAllowed {
Expand Down Expand Up @@ -245,7 +244,7 @@ isolated function generateAPIKey(APIKeyGenerateRequest payload, string appId, st
}
}
}
APIKey|commons:APKError apiKey = generateAPIKeyForApplication(user, application, apiList, keyType, validityPeriod, addProperties);
APIKey|commons:APKError apiKey = generateAPIKeyForApplication(user, <Application>application, apiList, keyType, validityPeriod, addProperties);
return apiKey;
} else {
string message = "User:" + user + " doesn't have permission to Application with application id:" + appId;
Expand Down Expand Up @@ -295,7 +294,7 @@ isolated function retrieveManagementServerHostsList() returns string[]|commons:A
public isolated function generateKeysForApplication(Application application, ApplicationKeyGenerateRequest applicationKeyGenRequest, commons:Organization organization) returns OkApplicationKey|commons:APKError {
string? keyManager = applicationKeyGenRequest.keyManager;
if keyManager is string {
if check isKeyMappingEntryByApplicationAndKeyManagerExist(<string>application.applicationId, keyManager,applicationKeyGenRequest.keyType) {
if check isKeyMappingEntryByApplicationAndKeyManagerExist(<string>application.applicationId, keyManager, applicationKeyGenRequest.keyType) {
return error("Key Mapping Entry already exists for application " + application.name + " and keyManager " + keyManager, message = "Key Mapping Entry already exists for application " + application.name + " and keyManager " + keyManager, description = "Key Mapping Entry already exists for application " + application.name + " and keyManager " + keyManager, code = 900950, statusCode = 400);
}
KeyManagerDaoEntry keyManagerById = check getKeyManagerById(keyManager, organization);
Expand Down Expand Up @@ -439,8 +438,8 @@ isolated function fromKeyMappingDaoEntryToApplicationKey(types:KeyMappingDaoEntr
keyMappingId: item.uuid,
consumerKey: item.consumer_key,
keyManager: item.key_manager_uuid,
keyType: item.key_type,
mode: item.create_mode,
keyType: <"PRODUCTION"|"SANDBOX">item.key_type,
mode: <"MAPPED"|"CREATED">item.create_mode,
keyState: "CREATED"
};
if oauthAppResponse is kmclient:ClientRegistrationResponse {
Expand Down Expand Up @@ -527,18 +526,19 @@ public isolated function updateOauthApp(Application application, string keyMappi
types:KeyMappingDaoEntry updatedKeyMappingentry = keyMappingEntry.clone();
updatedKeyMappingentry.app_info = oauthApplicationByClientId.toJsonString().toBytes();
check updateKeyMappingEntry(updatedKeyMappingentry);
return {
ApplicationKey applicationKey = {
keyMappingId: keyMappingEntry.uuid,
consumerKey: oauthApplicationByClientId.client_id,
consumerSecret: oauthApplicationByClientId.client_secret,
keyManager: keyMappingEntry.key_manager_uuid,
keyType: keyMappingEntry.key_type,
mode: keyMappingEntry.create_mode,
keyType: <"PRODUCTION"|"SANDBOX">keyMappingEntry.key_type,
mode: <"MAPPED"|"CREATED">keyMappingEntry.create_mode,
keyState: "CREATED",
callbackUrls: oauthApplicationByClientId.redirect_uris,
supportedGrantTypes: oauthApplicationByClientId.grant_types,
additionalProperties: oauthApplicationByClientId.additional_properties
};
return applicationKey;
} else {
return error("Key Manager is disabled", message = "Key Manager is disabled", description = "Key Manager is disabled", code = 900951, statusCode = 400);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,89 +757,17 @@ isolated service http:InterceptableService /api/devportal on ep0 {
string|json sdkLanguages = check getSDKLanguages();
return sdkLanguages;
}
# Get available web hook subscriptions for a given application.
#
# + applicationId - **Application Identifier** consisting of the UUID of the Application.
# + apiId - **API ID** consisting of the **UUID** of the API.
# + 'x\-wso2\-tenant - For cross-tenant invocations, this is used to specify the tenant/organization domain, where the resource need to be retrieved from.
# + return - returns can be any of following types
# WebhookSubscriptionList (OK. Topic list returned.)
# NotFoundError (Not Found. The specified resource does not exist.)
# InternalServerErrorError (Internal Server Error.)
// resource function get webhooks/subscriptions(string? applicationId, string? apiId, @http:Header string? 'x\-wso2\-tenant) returns WebhookSubscriptionList|NotFoundError|InternalServerErrorError {
// }
# Retrieve Developer Portal settings
#
# + 'x\-wso2\-tenant - For cross-tenant invocations, this is used to specify the tenant/organization domain, where the resource need to be retrieved from.
# + return - returns can be any of following types
# Settings (OK. Settings returned)
# NotFoundError (Not Found. The specified resource does not exist.)
// resource function get settings(@http:Header string? 'x\-wso2\-tenant) returns Settings|NotFoundError {
// }
# Get All Application Attributes from Configuration
#
# + 'if\-none\-match - Validator for conditional requests; based on the ETag of the formerly retrieved variant of the resource.
# + return - returns can be any of following types
# ApplicationAttributeList (OK. Application attributes returned.)
# NotFoundError (Not Found. The specified resource does not exist.)
# NotAcceptableError (Not Acceptable. The requested media type is not supported.)
// resource function get settings/'application\-attributes(@http:Header string? 'if\-none\-match) returns ApplicationAttributeList|NotFoundError|NotAcceptableError {
// }
# Get Tenants by State
#
# + state - The state represents the current state of the tenant
# + 'limit - Maximum size of resource array to return.
# + offset - Starting point within the complete list of items qualified.
# + return - returns can be any of following types
# TenantList (OK. Tenant names returned.)
# NotFoundError (Not Found. The specified resource does not exist.)
# NotAcceptableError (Not Acceptable. The requested media type is not supported.)
// resource function get tenants(string state = "active", int 'limit = 25, int offset = 0) returns TenantList|NotFoundError|NotAcceptableError {
// }
# Give API Recommendations for a User
#
# + return - returns can be any of following types
# Recommendations (OK. Requested recommendations are returned)
# NotFoundError (Not Found. The specified resource does not exist.)
// resource function get recommendations() returns Recommendations|NotFoundError {
// }
# Get All API Categories
#
# + 'x\-wso2\-tenant - For cross-tenant invocations, this is used to specify the tenant/organization domain, where the resource need to be retrieved from.
# + return - OK. Categories returned
// resource function get 'api\-categories(@http:Header string? 'x\-wso2\-tenant) returns APICategoryList {
// }
resource function get 'api\-categories(@http:Header string? 'x\-wso2\-tenant) returns APICategoryList {
}

# Get All Key Managers
#
# + 'x\-wso2\-tenant - For cross-tenant invocations, this is used to specify the tenant/organization domain, where the resource need to be retrieved from.
# + return - OK. Key Manager list returned
// resource function get 'key\-managers(@http:Header string? 'x\-wso2\-tenant) returns KeyManagerList {
// }
# Get the Complexity Related Details of an API
#
# + apiId - **API ID** consisting of the **UUID** of the API.
# + return - returns can be any of following types
# GraphQLQueryComplexityInfo (OK. Requested complexity details returned.)
# http:NotFound (Not Found. Requested API does not contain any complexity details.)
// resource function get apis/[string apiId]/'graphql\-policies/complexity() returns GraphQLQueryComplexityInfo|http:NotFound {
// }
# Retrieve Types and Fields of a GraphQL Schema
#
# + apiId - **API ID** consisting of the **UUID** of the API.
# + return - returns can be any of following types
# GraphQLSchemaTypeList (OK. Types and fields returned successfully.)
# http:NotFound (Not Found. Retrieving types and fields failed.)
// resource function get apis/[string apiId]/'graphql\-policies/complexity/types() returns GraphQLSchemaTypeList|http:NotFound {
// }
# Change the Password of the user
#
# + payload - Current and new password of the user
# + return - returns can be any of following types
# http:Ok (OK. User password changed successfully)
# BadRequestError (Bad Request. Invalid request or validation error.)
isolated resource function post me/'change\-password(@http:Payload CurrentAndNewPasswords payload) returns http:Ok|BadRequestError {
BadRequestError badRequest = {body: {code: 400, message: "Invalid request or validation error."}};
return badRequest;
resource function get 'key\-managers(@http:Header string? 'x\-wso2\-tenant) returns KeyManagerList {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2883,6 +2883,9 @@ components:
- REJECTED
- TIER_UPDATE_PENDING
- DELETE_PENDING
subscriptionCreateState:
type: string
example: CREATED
redirectionParams:
type: string
description: A url and other parameters the subscriber can be redirected.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,8 @@ isolated function getSubscriptions(string? apiId, string? applicationId, string?
int count = subs.length();
SubscriptionList subList = {count: count, list: subs};
return subList;
} else {
string message = "Internal Error occured while retrieving Subscription";
return error(message, message = message, description = message, code = 909001, statusCode = 500);
} else if subscription is NotFoundError {
return subscription;
}
} else if apiId is string {
// Retrieve Subscriptions per given API Id
Expand Down
Loading

0 comments on commit a7d7fef

Please sign in to comment.