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

TypeError: __init__() missing 1 required positional argument: 'required' #19

Closed beli68 closed 3 years ago

beli68 commented 3 years ago

Get the file from the swagger-petstore and save it as petstore.yml.

I get an error when I run the code below.

from openapi_parser import parse

a = parse('./petstore.yml')

Looking at the debug messages, builders are working fine until halfway through, so is it a problem with the yaml file? Thanks in advance.

Traceback ``` Traceback (most recent call last): File "/usr/local/lib/python3.9/runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/local/lib/python3.9/runpy.py", line 87, in _run_code exec(code, run_globals) File "/root/.vscode-server/extensions/ms-python.python-2021.6.944021595/pythonFiles/lib/python/debugpy/__main__.py", line 45, in cli.main() File "/root/.vscode-server/extensions/ms-python.python-2021.6.944021595/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 444, in main run() File "/root/.vscode-server/extensions/ms-python.python-2021.6.944021595/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 285, in run_file runpy.run_path(target_as_str, run_name=compat.force_str("__main__")) File "/usr/local/lib/python3.9/runpy.py", line 268, in run_path return _run_module_code(code, init_globals, run_name, File "/usr/local/lib/python3.9/runpy.py", line 97, in _run_module_code _run_code(code, mod_globals, init_globals, File "/usr/local/lib/python3.9/runpy.py", line 87, in _run_code exec(code, run_globals) File "/workspaces/learn_owl/openapi.py", line 3, in a = parse('./petstore.yml') File "/workspaces/learn_owl/.venv/lib/python3.9/site-packages/openapi_parser/parser.py", line 118, in parse return parser.load_specification(specification) File "/workspaces/learn_owl/.venv/lib/python3.9/site-packages/openapi_parser/parser.py", line 63, in load_specification attrs = extract_typed_props(data, attrs_map) File "/workspaces/learn_owl/.venv/lib/python3.9/site-packages/openapi_parser/builders/common.py", line 33, in extract_typed_props custom_attrs = { File "/workspaces/learn_owl/.venv/lib/python3.9/site-packages/openapi_parser/builders/common.py", line 34, in attr_name: cast_value(attr_info.name, data[attr_info.name], attr_info.cast) File "/workspaces/learn_owl/.venv/lib/python3.9/site-packages/openapi_parser/builders/common.py", line 26, in cast_value return type_cast_func(value) \ File "/workspaces/learn_owl/.venv/lib/python3.9/site-packages/openapi_parser/builders/path.py", line 21, in build_list return [ File "/workspaces/learn_owl/.venv/lib/python3.9/site-packages/openapi_parser/builders/path.py", line 22, in self._build_path(url, path) File "/workspaces/learn_owl/.venv/lib/python3.9/site-packages/openapi_parser/builders/path.py", line 39, in _build_path attrs["operations"] = [ File "/workspaces/learn_owl/.venv/lib/python3.9/site-packages/openapi_parser/builders/path.py", line 40, in self.operation_builder.build(method, data[method.value]) File "/workspaces/learn_owl/.venv/lib/python3.9/site-packages/openapi_parser/builders/operation.py", line 44, in build attrs = extract_typed_props(data, attrs_map) File "/workspaces/learn_owl/.venv/lib/python3.9/site-packages/openapi_parser/builders/common.py", line 33, in extract_typed_props custom_attrs = { File "/workspaces/learn_owl/.venv/lib/python3.9/site-packages/openapi_parser/builders/common.py", line 34, in attr_name: cast_value(attr_info.name, data[attr_info.name], attr_info.cast) File "/workspaces/learn_owl/.venv/lib/python3.9/site-packages/openapi_parser/builders/common.py", line 26, in cast_value return type_cast_func(value) \ File "/workspaces/learn_owl/.venv/lib/python3.9/site-packages/openapi_parser/builders/parameter.py", line 19, in build_list return [self.build(parameter) for parameter in parameters] File "/workspaces/learn_owl/.venv/lib/python3.9/site-packages/openapi_parser/builders/parameter.py", line 19, in return [self.build(parameter) for parameter in parameters] File "/workspaces/learn_owl/.venv/lib/python3.9/site-packages/openapi_parser/builders/parameter.py", line 35, in build return Parameter(**attrs) TypeError: __init__() missing 1 required positional argument: 'required' ```
manchenkoff commented 3 years ago

Hi, it seems like an error while parsing, I'll check it and return with details

manchenkoff commented 3 years ago

@beli68 I've just fixed some problems with parser by extending enumeration of ContentTypes to support application/octet-stream and making required property of request parameter optional, now it should work fine.

Anyway, you should replace default responses with some HTTP codes like 200, 404, etc because it's unconvertible to Python dictionary correctly.

To test it you should use version v1.1.1

beli68 commented 3 years ago

@manchenkoff Thank you for the swift response. I think it would be better to support default in the future because it is a description allowed by the OAS.

manchenkoff commented 3 years ago

@beli68 yeah, I'll fix it in another issue