Repository navigation
Tags
Tags
fix: match request paths the same way under every reading
Routers read request paths differently: some decode each segment, some
route on the fully decoded path, some on the escaped path, and some
remove empty and dot segments. The validator read a path one way, so
/users/m%65 matched /users/{id} while a router that decodes segments
dispatched it to /users/me.
The router now resolves the path as sent and under each normalized
reading: decoded path characters, decoded slashes, and empty and dot
segments removed. When two readings select different operations, the
request fails with ValidationSubType "ambiguousPath"
(router.ErrAmbiguousPath, which also matches router.ErrPathNotFound).
paths.FindPath does the same when no router is configured.
Server base paths are removed only on a segment boundary, so a base of
/api no longer turns /apistatus into /status.
The radix tree keeps empty segments, so /items//5 matches /items/{a}/{b}
as the regex matcher does. When the path as sent matches nothing,
doubled slashes are collapsed and matched again, as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fix: collapse object query param decode into one type assertion A nil map read is safe, so a missing key and a non-map value are the same failure as a nil decoded object. Keep one checked type assertion and one QueryParameterCannotBeDecoded path. Document QueryParameterCannotBeDecoded. The valid JSON and form cases, plus the invalid schema and unsupported content cases, still cover the changed lines. Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
fix: resolve open validation issues (#313 #316 #319 #320 #321 #322 #323) - router/paths: strip server base paths when the host has a variable, try every server whose base path prefixes the request, and read path parameters from the path the router matched (fixes a panic with strict server matching and a variable in the base path) (#313) - requests/responses: share one media-range matcher that prefers the most specific key and no longer panics on a Content-Type without a slash (#316) - responses: validate every response header that is present, by the readings its schema allows; match a default response without content; ignore Content-Type header declarations (#321) - parameters: accept whole numbers written as 1.0 or 1e3 for integers, compare integer enums numerically, schema-validate header and cookie numbers, reject NaN/Inf and empty matrix values (both panicked), and compile parameter schemas with their document's OpenAPI version (#319, #320) - parameters: ignore a path template's #fragment when the request has none, as the router does, instead of reporting the parameter missing - helpers: enforce OpenAPI int32/int64 formats with WithFormatAssertions (#320) - schema_validation: never marshal document-owned yaml nodes in place (#322) - tests: stop relying on json.Marshal rejecting map[interface{}]interface{}, which Go 1.27 accepts (#323) Fixes #313, fixes #316, fixes #319, fixes #320, fixes #321, fixes #322, fixes #323 Co-authored-by: adrienyhuel <14916484+adrienyhuel@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
chore: upgrade to libopenapi v0.41.1 and github.com/pb33f/go-yaml Move to libopenapi v0.41.1, and with it from go.yaml.in/yaml/v4 to github.com/pb33f/go-yaml v0.1.0, pb33f's fork. libopenapi's models carry the fork's yaml.Node, so the validator has to use the same module. The package is still named yaml, so the change is the import path. jsonpath moves to v0.8.4 and testify to v0.1.1, which use the same module. libopenapi requires Go 1.26, so go.mod does too. CI's build job now reads the Go version from go.mod (checking out first so the file exists), and golangci-lint moves to v2.12, which is built with Go 1.26. Since libopenapi v0.39, a schema built from a component-level $ref reports the index of the file its content came from, while its root node stays the authored $ref node in the referring file. buildSchemaDocumentResources looked for that node in the wrong document and failed with "schema node was not found in its root document". It now finds the node in the schema's index or, failing that, in its parent proxy's index, which libopenapi documents as the file the $ref was written in. This fixes TestSingleSchemaCompilePreferred_ResolvedExternalReferenceUsesSingleSchemaCompiler and TestCompileSchemaForValidation_NestedResourceRenderFailure. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PreviousNext