All Downloads are FREE. Search and download functionalities are using the official Maven repository.

chapi.app.frontend.identify.AxiosHttpIdentify.kt Maven / Gradle / Ivy

Go to download

Chapi is A common language meta information convertor, convert different languages to same meta-data model

There is a newer version: 1.5.10
Show newest version
package chapi.app.frontend.identify

import chapi.app.frontend.ContainerDemand
import chapi.domain.core.CodeCall
import chapi.domain.core.CodeImport

open class AxiosHttpIdentify : HttpIdentify {
    override fun isMatch(call: CodeCall, imports: Array): Boolean {
        if (call.FunctionName == "axios" || call.FunctionName.startsWith("axios.")) {
            if (call.Parameters.isNotEmpty()) {
                return true
            }
        }

        return false
    }

    override fun convert(call: CodeCall): ContainerDemand {
        val httpApi = ContainerDemand()
        call.Parameters.forEach { prop ->
            for (codeProperty in prop.ObjectValue) {
                when (codeProperty.TypeValue) {
                    "baseURL" -> {
                        httpApi.base = codeProperty.ObjectValue[0].TypeValue
                    }
                    "url" -> {
                        httpApi.target_url = codeProperty.ObjectValue[0].TypeValue
                    }
                    "method" -> {
                        httpApi.target_http_method = codeProperty.ObjectValue[0].TypeValue
                    }
                    "data" -> {
                        httpApi.call_data = codeProperty.ObjectValue[0].TypeValue
                    }
                }
            }
        }

        return httpApi
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy