Forum Discussion

br0wnf0x's avatar
Occasional Visitor
5 months ago

passing url as variable to a swagger specification 2 file converts the double slash to 1 slash

We're currently using Terraform to pass a url to a swagger specification 2 file. When I passed in the variable the double slash on the url becomes 1 slash.

on the template, we have this:

      operationId: GET /api/counties
         address: "${myUrl}"
         path_translation: APPEND_PATH_TO_ADDRESS

from terraform, I'm passing the variable like this: 


openapi_documents {
document {
path = "spec.yaml"
contents = filebase64(templatefile("apigateway/openapi2-runner.tftplt",{myUrl = trimprefix(var.CrSrvApp,"https://"),urlprefix = "https://"}))

When then pipeline runs, it fails because the url on the swagger template file is "http:/"
How to fix this?

1 Reply

  • abeermalik's avatar
    New Contributor

    It looks like the issue is occurring because of the URL formatting in your Terraform configuration. The URL is being passed with an extra slash when you specify it in the template. To resolve this issue, you can make sure that the URL is correctly formatted in the Terraform template. Here's how you can fix it:

    1. Update your Terraform template to format the URL correctly. You can use the `format` function to ensure that the URL is correctly formatted download vsco mod:

    openapi_documents {
    document {
    path = "spec.yaml"
    contents = filebase64(templatefile("apigateway/openapi2-runner.tftplt", {
    myUrl = format("https://%s", var.CrSrvApp)

    In this example, the `format` function is used to add "https://" before the URL specified in `var.CrSrvApp`.

    2. Ensure that the `CrSrvApp` variable does not include "https://" since it is added in the Terraform template.

    By making these changes, you should pass a correctly formatted URL to your Swagger specification, and the issue with double slashes should be resolved.