Skip to content

Commit

Permalink
Unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
martinw-ct committed May 23, 2024
1 parent 94bc1a0 commit 5e5f4b4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -29,10 +22,10 @@ class BrunoMethodRenderer constructor(val api: Api, override val vrapTypeProvide
fun allResourceMethods(): List<Method> = api.allContainedResources.flatMap { it.methods }

override fun produceFiles(): List<TemplateFile> {
return methods(api)
return methods()
}

fun methods(api: Api): List<TemplateFile> {
private fun methods(): List<TemplateFile> {
return allResourceMethods().mapIndexed { index, method -> render(index, method) }
}

Expand Down Expand Up @@ -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()
}
}


Original file line number Diff line number Diff line change
@@ -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<CodeGenerator>(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,11 +17,11 @@ class BrunoModuleRenderer constructor(val api: Api, override val vrapTypeProvide
override fun produceFiles(): List<TemplateFile> {
return listOf(
brunoJson(api),
collectionBru(api),
clientCredentialsBru(api),
collectionBru(),
clientCredentialsBru(),
exampleEnvironment(api),
dotEnvEnvironment(api),
dotEnvSample(api),
dotEnvSample(),
gitIgnore()
)
}
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 5e5f4b4

Please sign in to comment.