Skip to content
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

[Feature] add support for OpenAPI 3.1 #85

Open
asdfasdfasdfasdfasasdf opened this issue Apr 17, 2024 · 7 comments
Open

[Feature] add support for OpenAPI 3.1 #85

asdfasdfasdfasdfasasdf opened this issue Apr 17, 2024 · 7 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed
Milestone

Comments

@asdfasdfasdfasdfasasdf
Copy link

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

@manchenkoff
Copy link
Owner

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

@manchenkoff manchenkoff added question Further information is requested and removed bug Something isn't working labels Apr 17, 2024
@asdfasdfasdfasdfasasdf
Copy link
Author

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.

@manchenkoff
Copy link
Owner

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.

@asdfasdfasdfasdfasasdf
Copy link
Author

asdfasdfasdfasdfasasdf commented Apr 17, 2024

In Open API 3.1 it seems as if it is allowed: OAI/OpenAPI-Specification#2244 (comment)

@manchenkoff
Copy link
Owner

@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!

@manchenkoff manchenkoff added enhancement New feature or request help wanted Extra attention is needed and removed question Further information is requested labels Apr 17, 2024
@manchenkoff manchenkoff added this to the v2.0.0 milestone Apr 17, 2024
@asdfasdfasdfasdfasasdf
Copy link
Author

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

@manchenkoff
Copy link
Owner

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 👍

@manchenkoff manchenkoff changed the title openapi_parser.errors.ParserError: Invalid schema type '['string']' feature: add support for OpenAPI 3.1 Apr 18, 2024
@manchenkoff manchenkoff changed the title feature: add support for OpenAPI 3.1 [Feature] add support for OpenAPI 3.1 Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants