Hi,
I a using kin-openapi latest version (v0.106.0)
The following code fails although both schema and request are valid:
package main
import (
"context"
"fmt"
"net/http"
"github.com/getkin/kin-openapi/openapi3"
"github.com/getkin/kin-openapi/openapi3filter"
"github.com/getkin/kin-openapi/routers/gorillamux"
)
func main() {
ctx := context.Background()
loader := &openapi3.Loader{Context: ctx, IsExternalRefsAllowed: true}
schema :=
`
openapi: 3.0.0
info:
version: 1.0.0
title: Sample API
paths:
/items:
get:
parameters:
- description: "test object"
explode: false
in: query
name: test
required: false
style: form
schema:
allOf:
- pattern: "^[0-9]{1,4}$"
- pattern: "^[0-9]{1,4}$"
type: string
responses:
'200':
description: Successful response`
doc, err := loader.LoadFromData([]byte(schema))
if err != nil {
fmt.Println("failed to load schema. " + err.Error())
return
}
// Validate document
if err = doc.Validate(ctx); err != nil {
fmt.Println("failed to validate schema. " + err.Error())
return
}
router, _ := gorillamux.NewRouter(doc)
httpReq, _ := http.NewRequest(http.MethodGet, "/items?test=51", nil)
// Find route
route, pathParams, _ := router.FindRoute(httpReq)
// Validate request
requestValidationInput := &openapi3filter.RequestValidationInput{
Request: httpReq,
PathParams: pathParams,
Route: route,
}
err = openapi3filter.ValidateRequest(ctx, requestValidationInput)
if err != nil {
fmt.Println("failed to validate request. " + err.Error())
return
}
}
Running the code above results in the following error:
failed to validate request. parameter "test" in query has an error: empty value is not allowed
Please run the code to verify the bug.
It seems that the issue is that the schemas defined under the "allOf" has pattern property but no type (but this is valid, because if there is pattern property, then the schema type is always string).
Same issue also when using "oneOf" or "anyOf".
Thanks,
Oren
Hi,
I a using kin-openapi latest version (v0.106.0)
The following code fails although both schema and request are valid:
Running the code above results in the following error:
Please run the code to verify the bug.
It seems that the issue is that the schemas defined under the "allOf" has pattern property but no type (but this is valid, because if there is pattern property, then the schema type is always string).
Same issue also when using "oneOf" or "anyOf".
Thanks,
Oren