Neoteroi / essentials-openapi

Functions to handle OpenAPI Documentation.
MIT License
21 stars 9 forks source link

RequestBody Reference #21

Closed juliusmh closed 1 year ago

juliusmh commented 1 year ago

Marshalling the following spec fails, probably because operation.requestBody.content is null/undefined during template stage. I assume the problem is related to resolving the reference

Spec:

paths:
  "/something":
    post:
      requestBody:
        $ref: "#/components/requestBodies/SomeBody"

components:
  requestBodies:
    SomeBody:
      description: Foo Bar.
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              a:
                type: string
Full StackTrace ``` Traceback (most recent call last): File "/opt/homebrew/bin/oad", line 8, in sys.exit(main()) File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 1130, in __call__ return self.main(*args, **kwargs) File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 1055, in main rv = self.invoke(ctx) File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 1657, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 1404, in invoke return ctx.invoke(self.callback, **ctx.params) File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 760, in invoke return __callback(*args, **kwargs) File "/opt/homebrew/lib/python3.10/site-packages/openapidocs/commands/docs.py", line 51, in generate_documents_command generate_document(source, destination, style) File "/opt/homebrew/lib/python3.10/site-packages/openapidocs/mk/generate.py", line 14, in generate_document html = handler.write() File "/opt/homebrew/lib/python3.10/site-packages/openapidocs/mk/v3/__init__.py", line 417, in write return self._writer.write( File "/opt/homebrew/lib/python3.10/site-packages/openapidocs/mk/jinja.py", line 109, in write return template.render(data, **kwargs) File "/opt/homebrew/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render self.environment.handle_exception() File "/opt/homebrew/lib/python3.10/site-packages/jinja2/environment.py", line 936, in handle_exception raise rewrite_traceback_stack(source=source) File "/opt/homebrew/lib/python3.10/site-packages/openapidocs/mk/v3/views_mkdocs/layout.html", line 14, in top-level template code {% include "partial/path-items.html" %} File "/opt/homebrew/lib/python3.10/site-packages/openapidocs/mk/v3/views_mkdocs/partial/path-items.html", line 26, in top-level template code {% include "partial/request-body.html" %} File "/opt/homebrew/lib/python3.10/site-packages/openapidocs/mk/v3/views_mkdocs/partial/request-body.html", line 1, in top-level template code

{{texts.request_body}}

File "/opt/homebrew/lib/python3.10/site-packages/openapidocs/mk/v3/__init__.py", line 260, in simplify_content simplified_content = copy.deepcopy(content) File "/opt/homebrew/Cellar/python@3.10/3.10.6_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/copy.py", line 161, in deepcopy rv = reductor(4) TypeError: cannot pickle 'Undefined' object ```
juliusmh commented 1 year ago

Would be very nice to inline the request body right there in "request-body.html". However I am not sure how to do that in the template directly.

RobertoPrevato commented 1 year ago

Hi @juliusmh Thank You for submitting this issue. I apologize for replying late - I read your message immediately but didn't have the time to reply earlier. I'll look into this and fix the issue - the latest next week, since I have a few days of holidays and time for it.

juliusmh commented 1 year ago

No worries. Enjoy the holidays 🎄

RobertoPrevato commented 1 year ago

Thanks again @juliusmh for reporting this issue. Finally I was focused on my web frameworks in the last (several) weeks and I postponed this fix.

I corrected this yesterday, with https://pypi.org/project/essentials-openapi/1.0.6/