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

Path parameter bug when registering different methods on similar route structures #2201

Closed
3 tasks done
rtheunissen opened this issue Jun 9, 2022 · 4 comments
Closed
3 tasks done

Comments

@rtheunissen
Copy link

Issue Description

When registering these routes, we are seeing unexpected behavior:

  • GET "/task/:customer/:type"
  • DELETE "/task/:customer/:uuid"

The parameters of the DELETE endpoint is now customer and type, instead of customer and uuid.

Checklist

  • Dependencies installed
  • No typos
  • Searched existing issues and docs

Expected behaviour

The parameters of the DELETE endpoint is customer and uuid.

Actual behaviour

The parameters of the DELETE endpoint is customer and type.

Steps to reproduce

Working code to debug

package main

import (
	"fmt"
	"net/http"
	"time"
	"github.com/labstack/echo/v4"
)

func main() {
	server := echo.New()
	server.HideBanner = true

	server.GET("/task/:customer/:type", func(c echo.Context) error {
		fmt.Printf("GET: %v", c.ParamNames())
		return nil
	})
	server.DELETE("/task/:customer/:uuid", func(c echo.Context) error {
		fmt.Printf("DELETE: %v", c.ParamNames())
		return nil
	})

	// Start server
	go server.Start("127.0.0.1:8080")

	// Create client and make request
	client := &http.Client{}
	req, _ := http.NewRequest("DELETE", "http://127.0.0.1:8080/task/CUSTOMER/UUID", nil)
	client.Do(req)
}

Output:

⇨ http server started on 127.0.0.1:8080
DELETE: [customer type]%  

Version/commit

v4.7.2

@amoiseiev
Copy link

amoiseiev commented Jun 12, 2022

In my understanding, these are the same "endpoints/paths" but different "operations". You are technically mixing two different path parameters with the same hierarchy, which is undesirable and prohibited in some specs. For instance: https://swagger.io/specification/#paths-object (OAM 3.0.3)

While different "operations" may have different "parameters", as per the same spec, path parameters cannot be different between operations as they must be derived from path. So, the tooling is not guaranteed to behave in a specific way here.

@aldas
Copy link
Contributor

aldas commented Jun 13, 2022

This is current limitation of router. This thread discusses this issue #1726 (comment)

We have reworked that limitation in v5 (no idea exactly when it will be released)

@ortyomka
Copy link
Contributor

@aldas closed?

@aldas
Copy link
Contributor

aldas commented Jul 11, 2022

seems so. PR #2209 solved this "feature"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants