Skip to content

oneOf matches more than one #ref or Property  #369

@ramswish

Description

@ramswish

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.

request body has an error: doesn't match the schema: input matches more than one oneOf schemas

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:

  • name: testOneof
    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'

oneData:
  type: object
  properties:
    oneDataService: 
      type: string
      minLength: 1
      maxLength: 20
twoData:
  type: object
  properties:
    twoDataService: 
      type: string
      minLength: 1
      maxLength: 20
threeData:
  type: object
  properties:
    twoDataService: 
      type: string
      minLength: 1
      maxLength: 20

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"

"net/http"

"github.com/getkin/kin-openapi/openapi3"
"github.com/getkin/kin-openapi/openapi3filter"
legacyrouter "github.com/getkin/kin-openapi/routers/legacy"

)

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
}

router, _ := legacyrouter.NewRouter(doc)

// Find route
route, pathParams, _ := router.FindRoute(request)

// Validate request
requestValidationInput := &openapi3filter.RequestValidationInput{
	Request:    request,
	PathParams: pathParams,
	Route:      route,
}

if err := openapi3filter.ValidateRequest(ctx, requestValidationInput); err != nil {
	fmt.Println("Request Validation Failed!!!", err)
} else {
	fmt.Println("Request Validation Success!!!")
}

}

func main() {

http.HandleFunc("/", requestHandler)

http.ListenAndServe(":8090", nil)

}
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions