Search in sources :

Example 1 with AsyncAPISpecificationValidationResponseInfoDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.AsyncAPISpecificationValidationResponseInfoDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method getAsyncAPISpecificationValidationResponseFromModel.

public static AsyncAPISpecificationValidationResponseDTO getAsyncAPISpecificationValidationResponseFromModel(APIDefinitionValidationResponse model, boolean returnContent) throws APIManagementException {
    AsyncAPISpecificationValidationResponseDTO responseDTO = new AsyncAPISpecificationValidationResponseDTO();
    responseDTO.setIsValid(model.isValid());
    if (model.isValid()) {
        APIDefinitionValidationResponse.Info modelInfo = model.getInfo();
        if (modelInfo != null) {
            AsyncAPISpecificationValidationResponseInfoDTO infoDTO = new AsyncAPISpecificationValidationResponseInfoDTO();
            infoDTO.setAsyncAPIVersion(modelInfo.getOpenAPIVersion());
            infoDTO.setName(modelInfo.getName());
            infoDTO.setVersion(modelInfo.getVersion());
            infoDTO.setContext(modelInfo.getContext());
            infoDTO.setDescription(modelInfo.getDescription());
            infoDTO.setEndpoints(modelInfo.getEndpoints());
            infoDTO.setProtocol(model.getProtocol());
            Map<String, APIDefinition> apiDefinitionMap = APIUtil.getApiDefinitionParsersMap();
            apiDefinitionMap.remove(APIConstants.WSO2_GATEWAY_ENVIRONMENT);
            if (!apiDefinitionMap.isEmpty()) {
                for (Map.Entry<String, APIDefinition> apiDefinitionEntry : apiDefinitionMap.entrySet()) {
                    APIDefinition apiParser = apiDefinitionEntry.getValue();
                    String gatewayVendor = apiParser.getVendorFromExtension(model.getContent());
                    if (gatewayVendor != null) {
                        infoDTO.setGatewayVendor(gatewayVendor);
                        break;
                    }
                }
                infoDTO.asyncTransportProtocols(AsyncApiParser.getTransportProtocolsForAsyncAPI(model.getContent()));
            }
            // Set default value
            if (infoDTO.getGatewayVendor() == null) {
                infoDTO.setGatewayVendor(APIConstants.WSO2_GATEWAY_ENVIRONMENT);
            }
            responseDTO.setInfo(infoDTO);
        }
        if (returnContent) {
            responseDTO.setContent(model.getContent());
        }
    } else {
        responseDTO.setErrors(getErrorListItemsDTOsFromErrorHandlers(model.getErrorItems()));
    }
    return responseDTO;
}
Also used : AsyncAPISpecificationValidationResponseDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.AsyncAPISpecificationValidationResponseDTO) AsyncAPISpecificationValidationResponseInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.AsyncAPISpecificationValidationResponseInfoDTO) APIDefinition(org.wso2.carbon.apimgt.api.APIDefinition) Map(java.util.Map) HashMap(java.util.HashMap) APIDefinitionValidationResponse(org.wso2.carbon.apimgt.api.APIDefinitionValidationResponse)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 APIDefinition (org.wso2.carbon.apimgt.api.APIDefinition)1 APIDefinitionValidationResponse (org.wso2.carbon.apimgt.api.APIDefinitionValidationResponse)1 AsyncAPISpecificationValidationResponseDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.AsyncAPISpecificationValidationResponseDTO)1 AsyncAPISpecificationValidationResponseInfoDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.AsyncAPISpecificationValidationResponseInfoDTO)1