Skip to content

Commit

Permalink
fix: Default structure delimiter in translations endpoint (#1468)
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCizmar committed Dec 22, 2022
1 parent 3a69f04 commit 83f0583
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Expand Up @@ -65,6 +65,7 @@ import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.PutMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.context.request.WebRequest
import java.util.*
Expand Down Expand Up @@ -130,7 +131,8 @@ e.g. For key "home.header.title" would result in {"home": {"header": {"title": "
When null, resulting file will be a flat key-value object.
""",
)
structureDelimiter: Char? = '.',
@RequestParam(value = "structureDelimiter", defaultValue = ".", required = false)
structureDelimiter: Char?,
request: WebRequest
): ResponseEntity<Map<String, Any>>? {
val lastModified: Long = projectTranslationLastModifiedManager.getLastModified(projectHolder.project.id)
Expand All @@ -142,7 +144,7 @@ When null, resulting file will be a flat key-value object.
val response = translationService.getTranslations(
languageTags = languages,
projectId = projectHolder.project.id,
structureDelimiter = structureDelimiter
structureDelimiter = request.getStructureDelimiter()
)

return ResponseEntity.ok()
Expand All @@ -153,6 +155,17 @@ When null, resulting file will be a flat key-value object.
)
}

/**
* It has to be handled manually since spring returns default value even when empty value provided
*/
private fun WebRequest.getStructureDelimiter(): Char? {
val structureDelimiterParam = this.parameterMap["structureDelimiter"]?.first() ?: return '.'
if (structureDelimiterParam == "") {
return null
}
return structureDelimiterParam.toCharArray().first()
}

@PutMapping("")
@AccessWithApiKey(scopes = [ApiScope.TRANSLATIONS_EDIT])
@AccessWithProjectPermission(permission = Permission.ProjectPermissionType.TRANSLATE)
Expand Down
Expand Up @@ -326,6 +326,9 @@ class V2TranslationsControllerViewTest : ProjectAuthControllerTest("/v2/projects
performProjectAuthGet("/translations/en,de?structureDelimiter=+").andIsOk.andAssertThatJson {
node("en.hello.i.am.plus.scoped").isEqualTo("yupee!")
}
performProjectAuthGet("/translations/en,de").andIsOk.andAssertThatJson {
node("en.hello.i.am.scoped").isEqualTo("yupee!")
}
}

@ProjectApiKeyAuthTestMethod(scopes = [ApiScope.TRANSLATIONS_VIEW])
Expand Down

0 comments on commit 83f0583

Please sign in to comment.