openapi3-parser
openapi3-parser copied to clipboard
[Feature] add support for OpenAPI 3.1
tmp.yaml.txt Describe the bug The YAML file we use fails to be parsed. I believe have tracked it down to: type: - string
The error is shown as: File "/home/***/.local/lib/python3.10/site-packages/openapi_parser/builders/schema.py", line 135, in create raise ParserError(f"Invalid schema type '{schema_type}'") from None openapi_parser.errors.ParserError: Invalid schema type '['string']'
I'm quite confident that the YAML syntax is correct. We use it just fine and Swagger does not complain.
To Reproduce Use attached YAML file and type: python3 from openapi_parser import parse all_parse = parse('tmp.yaml')
Expected behavior No error parsing the file.
System details (please complete the following information):
- OS: Kubuntu 22.04
- OpenAPI / Swagger version 3.1.0
- Python version 3.10.12
Additional context
Hey @asdfasdfasdfasdfasasdf, looks like you are using type field as array instead of plain value, it should be like others in your specs:
openapi: 3.1.0
info:
version: unknown
title: unknown
description: unknown
servers:
- url: https://localhost
description: unknown
paths:
/slots:
get:
operationId: getSlots
tags:
- backplane
responses:
"200":
description: Successful operation
content:
application/json:
schema:
$ref: "#/components/schemas/slots"
components:
schemas:
slots:
type: array
items:
$ref: "#/components/schemas/slot"
object_create:
type: object
properties:
id:
type: integer
slot:
type: object
properties:
id:
type: integer
occupied:
type: string
enabled:
type: boolean
module:
$ref: "#/components/schemas/slot_module"
slot_module:
type: object
properties:
serial:
type: string # fixed line
Hi and thanks for your quick reply.
I'm no expert in YAML, trying to get a hang of it. I believe that we use the "- string" to handle cases where it can be a string or null. In these cases it looks like
slot_module:
type: object
properties:
serial:
type:
- string
- 'null'
But in the code attached to this ticket, we only have 1 member in the array.
I believe that we use the "- string" to handle cases where it can be a string or null. In these cases, it looks like
I see, but unfortunately, this is the wrong way of doing that in OpenAPI specs, you can check the details and example of a proper way of handling multiple types here in docs. Specifically in the Mixed Types section.
In Open API 3.1 it seems as if it is allowed: https://github.com/OAI/OpenAPI-Specification/issues/2244#issuecomment-899084964
@asdfasdfasdfasdfasasdf Yeah, I think you're right, my bad. However, the problem is the current package supports only 3.0.* specs, so to solve that you can either roll your specs back to 3.0 or wait for the support of 3.1, but I cannot give you an exact deadline since I do not have enough time/support to deliver new big features right now. By the way, feel free to contribute if you have some free time, I would be glad to help with that!
You are correct, this is part of version 3.1. I would really like to help out but I'm afraid that my skills in both YAML and Python are way to low.
May I suggest that you add the supported Open API version to https://github.com/manchenkoff/openapi3-parser? Currently it says
A simple package to parse your OpenAPI 3 documents
but it would be nice if it stated 3.0.*.
Regards, Jonas
May I suggest that you add the supported Open API version to https://github.com/manchenkoff/openapi3-parser?
Yep, that would make sense! Will update readme 👍