io.vrap.codegen.languages.extensions.ResourceExtensions.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of codegen-renderers Show documentation
Show all versions of codegen-renderers Show documentation
RAML API client code generators based on the REST Modeling Framework. https://github.com/vrapio/rest-modeling-framework
The newest version!
package io.vrap.codegen.languages.extensions
import com.damnhandy.uri.template.Expression
import com.google.common.base.CaseFormat
import io.vrap.rmf.raml.model.resources.Method
import io.vrap.rmf.raml.model.resources.Resource
import io.vrap.rmf.raml.model.types.BooleanInstance
import io.vrap.rmf.raml.model.types.StringInstance
import io.vrap.rmf.raml.model.util.StringCaseFormat
fun Resource.getMethodName(): String {
val annotation = this.getAnnotation("methodName")
if (annotation != null) {
return (annotation.getValue() as StringInstance).value
}
val parts = this.relativeUri.components
.filter { uriTemplatePart -> uriTemplatePart is Expression }
.map { uriTemplatePart -> uriTemplatePart as Expression }
.toList()
if (parts.isNotEmpty()) {
return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, this.relativeUri.toParamName("With", "Value"))
}
val uri = this.relativeUri.template
return StringCaseFormat.LOWER_CAMEL_CASE.apply(uri.replaceFirst("/".toRegex(), "").replace("/", "_"))
}
fun Resource.toResourceName(): String = this.fullUri.toParamName("By")
fun Resource.deprecated() : Boolean {
val anno = this.getAnnotation("deprecated")
return (anno != null && (anno.value as BooleanInstance).value)
}
fun Resource.markDeprecated() : Boolean {
val anno = this.getAnnotation("markDeprecated")
return (anno != null && (anno.value as BooleanInstance).value)
}