How to solve the "oneOf constraint failed"? #82
-
I'm now trying to use OpenAPI v3.1 and analyze the yaml to generate code in golang. First of all, I modified the example at https://github.com/swaggest/rest/blob/master/_examples/gingonic/main.go to OpenAPI v3.1 and generate a yaml file. After that, I created a sample code "main.go" to load the file and unmarshal to golang objects. Playground: https://go.dev/play/p/7NI2YKoZjBQ Thank you. package main
import (
"log"
"os"
"github.com/swaggest/openapi-go/openapi31"
)
func main() {
bytes, err := os.ReadFile("openapi.yaml")
if err != nil {
panic(err)
}
log.Println("Read OpenAPI spec:", string(bytes))
refl := openapi31.NewReflector()
err = refl.Spec.UnmarshalYAML(bytes)
if err != nil {
log.Println("Failed to unmarshal OpenAPI spec:", err)
} else {
log.Println("Unmarshaled OpenAPI spec:", refl.Spec)
}
} openapi: 3.1.0
info:
description: This services keeps track of albums.
title: Albums API
version: v1.2.3
paths:
/albums:
get:
responses:
"200":
content:
application/json:
schema:
items:
$ref: '#/components/schemas/Album'
type: array
description: OK
summary: List albums
tags:
- Albums
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Album'
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/Album'
description: OK
summary: Create an album
tags:
- Albums
/albums/{id}:
get:
parameters:
- in: path
name: id
required: true
schema:
type: string
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/Album'
description: OK
"404":
content:
application/json:
schema:
properties:
message:
type: string
type: object
description: Not Found
summary: Get album
tags:
- Albums
components:
schemas:
Album:
properties:
artist:
type: string
id:
type: string
price:
type: number
title:
type: string
type: object |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi, thank you for reporting this! This is definitely a bug, that should be fixed with new |
Beta Was this translation helpful? Give feedback.
Oh, sorry, my bad, I fixed the issue but actually did not tag a new version. 🤦
https://go.dev/play/p/_90QGRcabbe
v0.2.40
passes in playground.