diff --git a/languages/bruno/src/main/kotlin/io/vrap/codegen/languages/bruno/model/BrunoActionRenderer.kt b/languages/bruno/src/main/kotlin/io/vrap/codegen/languages/bruno/model/BrunoActionRenderer.kt index 67972d42..ea619bcc 100644 --- a/languages/bruno/src/main/kotlin/io/vrap/codegen/languages/bruno/model/BrunoActionRenderer.kt +++ b/languages/bruno/src/main/kotlin/io/vrap/codegen/languages/bruno/model/BrunoActionRenderer.kt @@ -4,25 +4,18 @@ import com.fasterxml.jackson.core.JsonProcessingException import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.module.SimpleModule import com.fasterxml.jackson.databind.node.ObjectNode -import com.google.common.collect.Lists import io.vrap.codegen.languages.extensions.* import io.vrap.rmf.codegen.firstUpperCase import io.vrap.rmf.codegen.io.TemplateFile import io.vrap.rmf.codegen.rendering.FileProducer -import io.vrap.rmf.codegen.rendering.MethodRenderer -import io.vrap.rmf.codegen.rendering.utils.escapeAll import io.vrap.rmf.codegen.rendering.utils.keepAngleIndent -import io.vrap.rmf.codegen.rendering.utils.keepIndentation -import io.vrap.rmf.codegen.types.VrapObjectType import io.vrap.rmf.codegen.types.VrapTypeProvider import io.vrap.rmf.raml.model.modules.Api import io.vrap.rmf.raml.model.resources.HttpMethod import io.vrap.rmf.raml.model.resources.Method import io.vrap.rmf.raml.model.resources.Resource import io.vrap.rmf.raml.model.types.* -import io.vrap.rmf.raml.model.types.Annotation import io.vrap.rmf.raml.model.util.StringCaseFormat -import org.eclipse.emf.ecore.EObject import java.io.IOException class BrunoActionRenderer constructor(val api: Api, override val vrapTypeProvider: VrapTypeProvider) : EObjectExtensions, FileProducer { @@ -48,9 +41,9 @@ class BrunoActionRenderer constructor(val api: Api, override val vrapTypeProvide } private fun renderAction(resource: Resource, method: Method, type: ObjectType, index: Int): TemplateFile { - val url = BrunoUrl(method.resource(), method) { resource, name -> when (name) { - "ID" -> resource.resourcePathName.singularize() + "-id" - "key" -> resource.resourcePathName.singularize() + "-key" + val url = BrunoUrl(method.resource(), method) { methodResource, name -> when (name) { + "ID" -> methodResource.resourcePathName.singularize() + "-id" + "key" -> methodResource.resourcePathName.singularize() + "-key" else -> StringCaseFormat.LOWER_HYPHEN_CASE.apply(name) }} val actionBody = resource.actionExample(type) diff --git a/languages/bruno/src/main/kotlin/io/vrap/codegen/languages/bruno/model/BrunoMethodRenderer.kt b/languages/bruno/src/main/kotlin/io/vrap/codegen/languages/bruno/model/BrunoMethodRenderer.kt index 31a6229d..8429b9c5 100644 --- a/languages/bruno/src/main/kotlin/io/vrap/codegen/languages/bruno/model/BrunoMethodRenderer.kt +++ b/languages/bruno/src/main/kotlin/io/vrap/codegen/languages/bruno/model/BrunoMethodRenderer.kt @@ -3,24 +3,17 @@ package io.vrap.codegen.languages.bruno.model import com.fasterxml.jackson.core.JsonProcessingException import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.module.SimpleModule -import com.google.common.collect.Lists import io.vrap.codegen.languages.extensions.* import io.vrap.rmf.codegen.firstUpperCase import io.vrap.rmf.codegen.io.TemplateFile import io.vrap.rmf.codegen.rendering.FileProducer -import io.vrap.rmf.codegen.rendering.MethodRenderer -import io.vrap.rmf.codegen.rendering.utils.escapeAll import io.vrap.rmf.codegen.rendering.utils.keepAngleIndent -import io.vrap.rmf.codegen.rendering.utils.keepIndentation -import io.vrap.rmf.codegen.types.VrapObjectType import io.vrap.rmf.codegen.types.VrapTypeProvider import io.vrap.rmf.raml.model.modules.Api import io.vrap.rmf.raml.model.resources.Method import io.vrap.rmf.raml.model.resources.Resource import io.vrap.rmf.raml.model.types.* -import io.vrap.rmf.raml.model.types.Annotation import io.vrap.rmf.raml.model.util.StringCaseFormat -import org.eclipse.emf.ecore.EObject class BrunoMethodRenderer constructor(val api: Api, override val vrapTypeProvider: VrapTypeProvider) : EObjectExtensions, FileProducer { @@ -29,10 +22,10 @@ class BrunoMethodRenderer constructor(val api: Api, override val vrapTypeProvide fun allResourceMethods(): List = api.allContainedResources.flatMap { it.methods } override fun produceFiles(): List { - return methods(api) + return methods() } - fun methods(api: Api): List { + private fun methods(): List { return allResourceMethods().mapIndexed { index, method -> render(index, method) } } @@ -112,6 +105,35 @@ class BrunoMethodRenderer constructor(val api: Api, override val vrapTypeProvide return example } + + fun Resource.testScript(param: String = ""): String { + return """ + |var data = res.body; + |if(res.status == 200 || res.status == 201) { + | if(data.results && data.results[0] && data.results[0].id && data.results[0].version){ + | bru.setEnvVar("${this.resourcePathName.singularize()}-id", data.results[0].id); + | bru.setEnvVar("${this.resourcePathName.singularize()}-version", data.results[0].version); + | } + | if(data.results && data.results[0] && data.results[0].key){ + | bru.setEnvVar("${this.resourcePathName.singularize()}-key", data.results[0].key); + | } + | if(data.version){ + | bru.setEnvVar("${this.resourcePathName.singularize()}-version", data.version); + | } + | if(data.id){ + | bru.setEnvVar("${this.resourcePathName.singularize()}-id", data.id); + | } + | if(data.key){ + | bru.setEnvVar("${this.resourcePathName.singularize()}-key", data.key); + | } + | ${if (param.isNotEmpty()) """ + | if(data.${param}){ + | bru.setEnvVar("${this.resourcePathName.singularize()}-${param}", data.${param}); + | } + |""".trimMargin() else ""} + |} + """.trimMargin() + } } diff --git a/languages/bruno/src/main/kotlin/io/vrap/codegen/languages/bruno/model/BrunoModelModule.kt b/languages/bruno/src/main/kotlin/io/vrap/codegen/languages/bruno/model/BrunoModelModule.kt index 29b781e6..13e8da3a 100644 --- a/languages/bruno/src/main/kotlin/io/vrap/codegen/languages/bruno/model/BrunoModelModule.kt +++ b/languages/bruno/src/main/kotlin/io/vrap/codegen/languages/bruno/model/BrunoModelModule.kt @@ -1,11 +1,9 @@ package io.vrap.codegen.languages.bruno.model -import io.vrap.codegen.languages.extensions.deprecated import io.vrap.rmf.codegen.di.RamlGeneratorModule import io.vrap.rmf.codegen.di.Module import io.vrap.rmf.codegen.rendering.CodeGenerator import io.vrap.rmf.codegen.rendering.FileGenerator -import io.vrap.rmf.codegen.rendering.MethodGenerator object BrunoModelModule : Module { override fun configure(generatorModule: RamlGeneratorModule) = setOf( diff --git a/languages/bruno/src/main/kotlin/io/vrap/codegen/languages/bruno/model/BrunoModuleRenderer.kt b/languages/bruno/src/main/kotlin/io/vrap/codegen/languages/bruno/model/BrunoModuleRenderer.kt index 1f24e832..5080c021 100644 --- a/languages/bruno/src/main/kotlin/io/vrap/codegen/languages/bruno/model/BrunoModuleRenderer.kt +++ b/languages/bruno/src/main/kotlin/io/vrap/codegen/languages/bruno/model/BrunoModuleRenderer.kt @@ -1,13 +1,11 @@ package io.vrap.codegen.languages.bruno.model -import com.damnhandy.uri.template.UriTemplate import com.fasterxml.jackson.core.JsonProcessingException import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.module.SimpleModule import io.vrap.codegen.languages.extensions.EObjectExtensions import io.vrap.rmf.codegen.io.TemplateFile import io.vrap.rmf.codegen.rendering.FileProducer -import io.vrap.rmf.codegen.rendering.utils.escapeAll import io.vrap.rmf.codegen.rendering.utils.keepAngleIndent import io.vrap.rmf.codegen.types.VrapTypeProvider import io.vrap.rmf.raml.model.modules.Api @@ -19,11 +17,11 @@ class BrunoModuleRenderer constructor(val api: Api, override val vrapTypeProvide override fun produceFiles(): List { return listOf( brunoJson(api), - collectionBru(api), - clientCredentialsBru(api), + collectionBru(), + clientCredentialsBru(), exampleEnvironment(api), dotEnvEnvironment(api), - dotEnvSample(api), + dotEnvSample(), gitIgnore() ) } @@ -56,7 +54,7 @@ class BrunoModuleRenderer constructor(val api: Api, override val vrapTypeProvide """.trimMargin() ) } - private fun dotEnvSample(api: Api): TemplateFile { + private fun dotEnvSample(): TemplateFile { return TemplateFile(relativePath = ".env.sample", content = """ |CTP_CLIENT_ID= @@ -102,7 +100,7 @@ class BrunoModuleRenderer constructor(val api: Api, override val vrapTypeProvide ) } - private fun collectionBru(api: Api): TemplateFile { + private fun collectionBru(): TemplateFile { return TemplateFile(relativePath = "collection.bru", content = """ |auth { @@ -116,7 +114,7 @@ class BrunoModuleRenderer constructor(val api: Api, override val vrapTypeProvide ) } - private fun clientCredentialsBru(api: Api): TemplateFile { + private fun clientCredentialsBru(): TemplateFile { return TemplateFile(relativePath = "auth/clientCredentials.bru", content = """ |meta {