Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing trailing slash #154

Open
myrho opened this issue Nov 4, 2024 · 2 comments
Open

Missing trailing slash #154

myrho opened this issue Nov 4, 2024 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@myrho
Copy link

myrho commented Nov 4, 2024

Thank you for your tremendous work on this package!
I have found this issue:

Given this spec

{
  "openapi": "3.1.0",
  "info": {
    "title": "API",
    "version": "0.1.0"
  },
  "servers": [
    {
      "url": "https://example.com"
    }
  ],
  "paths": {
    "/api/v1/product/": {
      "get": {
        "tags": [
          "Product"
        ],
        "summary": "List Products",
        "operationId": "Product-list_products",
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "items": {
                    "$ref": "#/components/schemas/Product"
                  },
                  "type": "array",
                  "title": "Response Product-List Products"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Product": {
        "properties": {
          "Artikelnr": {
            "type": "string",
            "title": "Artikelnr"
          }
        },
        "type": "object",
        "required": [
          "Artikelnr"
        ],
        "title": "Product"
      }
    }
  }
}

which contains a path with a trailing slash, elm-open-api 0.7.0 generates:

productListProductsRisky config =
    Http.riskyRequest
        { url =
            Url.Builder.crossOrigin
                "https://example.com"
                [ "api", "v1", "product" ]
                []
        , method = "GET"
        , headers = []
        , expect =
            OpenApi.Common.expectJsonCustom
                config.toMsg
                (Dict.fromList [])
                (Json.Decode.list Api.Json.decodeProduct)
        , body = Http.emptyBody
        , timeout = Nothing
        , tracker = Nothing
        }

which in turn results in a request to the endpoint without the trailing slash.

I would expect the generated request paths to exactly match the spec.

This was a related issue: #72

@miniBill
Copy link
Collaborator

miniBill commented Nov 4, 2024

I guess generating [ "api", "v1", "product", "" ] would work?

@wolfadex
Copy link
Owner

wolfadex commented Nov 5, 2024

Yeah, that seems like a good fix

@wolfadex wolfadex added bug Something isn't working good first issue Good for newcomers labels Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants