Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions openapi2kong/openapi2kong.go
Original file line number Diff line number Diff line change
Expand Up @@ -1254,8 +1254,8 @@ func Convert(content []byte, opts O2kOptions) (map[string]interface{}, error) {
// match single segment; '/', '?', and '#' can mark the end of a segment
// see https://github.com/OAI/OpenAPI-Specification/issues/291#issuecomment-316593913
captureName := openapitools.SanitizeRegexCapture(varName, opts.InsoCompat)
if len(captureName) >= 32 {
return nil, fmt.Errorf("path-parameter name exceeds 32 characters: '%s' (sanitized to '%s')",
if len(captureName) >= 128 {
return nil, fmt.Errorf("path-parameter name exceeds 128 characters: '%s' (sanitized to '%s')",
varName, captureName)
}
regexMatch := "(?<" + captureName + ">[^#?/]+)"
Expand Down
13 changes: 8 additions & 5 deletions openapi2kong/openapi2kong_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ func Test_Openapi2kong_IgnoreCircularRefs(t *testing.T) {
}

func Test_Openapi2kong_pathParamLength(t *testing.T) {
testDataString := `
// 129 characters, exceeding the 128-character limit
longParamName := "something-very-long-that-is-way-beyond-the-previous-32-character-" +
"limit-and-now-valid-with-the-updated-128-character-limit-123456"
testDataString := fmt.Sprintf(`
openapi: 3.0.3
info:
title: Path parameter test
Expand All @@ -188,24 +191,24 @@ servers:
- url: "https://example.com"

paths:
/demo/{something-very-long-that-is-way-beyond-the-32-limit}/:
/demo/{%s}/:
get:
operationId: opsid
parameters:
- in: path
name: something-very-long-that-is-way-beyond-the-32-limit
name: %s
required: true
schema:
type: string
responses:
"200":
description: OK
`
`, longParamName, longParamName)
_, err := Convert([]byte(testDataString), O2kOptions{})
if err == nil {
t.Error("Expected error, but got none")
} else {
assert.Contains(t, err.Error(), "path-parameter name exceeds 32 characters")
assert.Contains(t, err.Error(), "path-parameter name exceeds 128 characters")
}
}

Expand Down
Loading