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
7 changes: 5 additions & 2 deletions examples/petstore/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ func main() {
option.Request(new(Pet)),
option.Response(201, new(Pet)),
)
pet.Get("/findByStatus",
pet.Get(
"/findByStatus",
option.OperationID("findPetsByStatus"),
option.Summary("Find pets by status"),
option.Description("Finds Pets by status. Multiple status values can be provided with comma separated strings."),
option.Description(
"Finds Pets by status. Multiple status values can be provided with comma separated strings.",
),
option.Request(new(struct {
Status string `query:"status" enum:"available,pending,sold"` // Enum values for pet status
})),
Expand Down
2 changes: 1 addition & 1 deletion internal/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (b *Builder) ensurePathParameters(target string, op *openapi.Operation) {
return
}
for _, m := range matches {
name := m[1]
name, _, _ := strings.Cut(m[1], ":")
if _, ok := existing[name]; ok {
continue
}
Expand Down
5 changes: 3 additions & 2 deletions internal/validate/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ func ValidatePathParams(path, method string, params []*openapi.Parameter) []erro
matches := pathParamRe.FindAllStringSubmatch(path, -1)
templateNames := map[string]struct{}{}
for _, match := range matches {
templateNames[match[1]] = struct{}{}
name, _, _ := strings.Cut(match[1], ":")
templateNames[name] = struct{}{}
}
declared := map[string]bool{}
for _, p := range params {
Expand All @@ -104,7 +105,7 @@ func ValidatePathParams(path, method string, params []*openapi.Parameter) []erro
}
}
for _, match := range matches {
name := match[1]
name, _, _ := strings.Cut(match[1], ":")
if required, ok := declared[name]; !ok {
errs = append(errs, Errorf("%s %s missing path parameter %q", strings.ToUpper(method), path, name))
} else if !required {
Expand Down
2 changes: 1 addition & 1 deletion internal/validate/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

var (
pathParamRe = regexp.MustCompile(`\{([^{}]+)\}`)
pathParamRe = regexp.MustCompile(`\{((?:\\.|[^{}\\]|\{(?:\\.|[^{}\\])*\})*)\}`)
componentRe = regexp.MustCompile(`^[a-zA-Z0-9.\-_]+$`)
responseCodeRe = regexp.MustCompile(`^[1-5]([0-9]{2}|XX)$`)
)
Expand Down
9 changes: 9 additions & 0 deletions internal/validate/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ import (
func TestNormalizeTemplatedPath(t *testing.T) {
assert.Equal(t, "/users/{}", validate.NormalizeTemplatedPath("/users/{id}"))
assert.Equal(t, "/orgs/{}/repos/{}", validate.NormalizeTemplatedPath("/orgs/{org}/repos/{repo}"))
assert.Equal(t, "/type/{}", validate.NormalizeTemplatedPath("/type/{type:foo|bar}"))
assert.Equal(t, "/more/{}/{}", validate.NormalizeTemplatedPath("/more/{param}/{type:foo|bar}"))
Comment thread
GamerGirlandCo marked this conversation as resolved.
assert.Equal(t, "/complex/quantifier/{}", validate.NormalizeTemplatedPath("/complex/quantifier/{t:(\\d{4})}"))
assert.Equal(
t,
"/foo/bar/{}/two/{}/8/nine/{}",
validate.NormalizeTemplatedPath("/foo/bar/{one}/two/{three:(four|five){6,7}(eight|nine)}/8/nine/{wtf}"),
)
assert.Equal(t, "/curly/brace/{}/{}", validate.NormalizeTemplatedPath(`/curly/brace/{one:\{}/{two:\}\}}`))
assert.Equal(t, "/static", validate.NormalizeTemplatedPath("/static"))
}

Expand Down
Loading