manchenkoff / openapi3-parser

OpenAPI 3 parser to use a specification inside of the code in your projects
https://pypi.org/project/openapi3-parser/
MIT License
65 stars 34 forks source link

[BUG] StringFormat needs URL? #59

Closed arquicanedo closed 1 year ago

arquicanedo commented 1 year ago

Describe the bug I'm trying to parse the 1password yaml spec (https://api.apis.guru/v2/specs/1password.local/connect/1.5.7/openapi.yaml). Openapi3-parser failed with this error.

Traceback (most recent call last):
  File "c:\xxx\.conda\lib\site-packages\openapi_parser\builders\common.py", line 22, in cast_value
    return type_cast_func(value) \
  File "c:\xxx\.conda\lib\enum.py", line 385, in __call__
    return cls.__new__(cls, value)
  File "c:\xxx\.conda\lib\enum.py", line 710, in __new__
    raise ve_exc
ValueError: 'url' is not a valid StringFormat

Adding URL to StringFormat in enumeration.py does the trick. Not sure if this is not supposed to be this way but now I'm able to parse this file.

@unique
class StringFormat(Enum):
    BYTE = 'byte'
    BINARY = 'binary'
    DATE = 'date'
    DATETIME = 'date-time'
    PASSWORD = 'password'
    UUID = 'uuid'
    EMAIL = 'email'
    URI = 'uri'
    URL = 'url'

To Reproduce Steps to reproduce the behavior:

  1. specification = parse('collection/1password.yaml')

Expected behavior Correctly parse this spec.

System details (please complete the following information):

Additional context None

manchenkoff commented 1 year ago

Hey @arquicanedo, thank you for opening this! I've checked the original specification, and they do not have that strict rules anymore - https://swagger.io/docs/specification/data-models/data-types#format.

So, since they allow to use any other format, the proper solution could be either extending the enumeration to provide more options or removing it from the data classes.

The enumeration extension looks more applicable from a backward compatibility perspective and I will try to publish the change soon, or if you have some time, feel free to contribute! 👍

manchenkoff commented 1 year ago

Published as v1.1.10