-
-
Notifications
You must be signed in to change notification settings - Fork 435
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
oneOf matches more than one #ref or Property #369
Comments
Analyzed code with some prints and found issue in visitJSONObject() function in schema.go file in visitJSONObject function, if it gets the propertyRef it is validating, if the propertyRef is not found then it function would return success all the time. this function will be called from visitSetOperations for all the oneof schemas, in which for all the schemas it returns success and fianlly visitSerOperations fuction has logic to fail if it is success for all the schema to fail. visitSetOperations
visitSetOperations
Questions i have here is
Solution i could think ofvisitJSONObject should fail if propertyRef is not present for the incoming data. |
@fenollp pls check this and comment. |
At this point there are many issues with this project's own schema validation code. We're looking to replace this code with a third party's lib. |
Hi @fenollp , any workaround we have for this issue? if you can estimate how much effort we need on supporting jsonschema may be i can try to contribute. |
@fenollp ? |
Hi there! Could you send a PR with your changes and a regression test? |
when i try to test oneOf under reference object, it matches single individual input data with all the schemas under oneOf and giving error as below.
verrsion i have used
github.com/getkin/kin-openapi v0.63.0
yaml i have used attached
openapi: 3.0.0
info:
title: test 123
description: description
contact:
email: [email protected]
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
version: 1.0.1
tags:
description: Everything
paths:
/testOneof:
patch:
tags:
- testOneof
summary: modify subscriber in network elements
description: |
This API is used to create
operationId: testOneof
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ModifyData'
responses:
"202":
description: Request for .
components:
schemas:
ModifyData:
required:
- '@type'
- neModifyData
type: object
properties:
'@type':
maxLength: 64
minLength: 2
type: string
example: neModifyData
default: neModifyData
neModifyData:
$ref: '#/components/schemas/neModifyData'
neModifyData:
type: object
oneOf:
- properties:
accountStatus:
type: string
description: Account status of this subscriber
example: active
default: active
enum:
- active
- suspended
- properties:
subscriberType:
type: string
enum:
- PRE
- POST
- POST
- HYBRID
- properties:
oneData :
$ref: '#/components/schemas/oneData'
- properties:
twoData:
$ref: '#/components/schemas/twoData'
- properties:
threeData:
$ref: '#/components/schemas/threeData'
securitySchemes:
basicAuth:
type: http
scheme: basic
sample inputs used for testing below. for any oneof data it is giving error.
{ "@type": "neModifyData", "neModifyData": { "accountStatus": "active" } }
{ "@type": "neModifyData", "neModifyData": { "subscriberType": "POST" } }
Golang server code used
`package main
import (
"context"
"fmt"
)
func requestHandler(response http.ResponseWriter, request *http.Request) {
fmt.Println("received request")
ctx := context.Background()
loader := &openapi3.Loader{Context: ctx}
doc, _ := loader.LoadFromFile("openapi_modify.yaml")
err := doc.Validate(ctx)
if err != nil {
fmt.Println("doc.Validate Error:", err)
return
}
}
func main() {
}
`
The text was updated successfully, but these errors were encountered: