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

Fix Swagger apidocs validation errors #180

Closed
kkaris opened this issue Sep 11, 2024 · 1 comment · Fixed by #181
Closed

Fix Swagger apidocs validation errors #180

kkaris opened this issue Sep 11, 2024 · 1 comment · Fixed by #181
Labels
documentation Improvements or additions to documentation

Comments

@kkaris
Copy link
Collaborator

kkaris commented Sep 11, 2024

When running the example for indra_subnetwork_relations, there is an error that looks like the payload is badly formatted. The given example is correct, but the swagger docs seems to do some format checking and doesn't allow the example to be sent because of this.

image

The complaint is that indexes 0 and 1 in the list must be strings, although currently they are lists of strings. Fixing it to comply with the swagger error allows the request to be sent but yields an error on the backend instead (since now the payload is not properly formatted for it):

image
image

The backend errors with this:

ERROR: [2024-09-11 19:28:10] indra_cogex.apps.queries_web - norm_id() takes 2 positional arguments but 8 were given
ERROR: [2024-09-11 19:28:10] indra_cogex.apps.wsgi - Exception on /api/indra_subnetwork_relations [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/indra_cogex/apps/queries_web/__init__.py", line 141, in post
    result = func_mapping[self.func_name](**parsed_query, client=client)
  File "/usr/local/lib/python3.8/dist-packages/indra_cogex/client/neo4j_client.py", line 1130, in _wrapped
    rv = func(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/indra_cogex/client/subnetwork.py", line 40, in indra_subnetwork_relations
    nodes_str = ", ".join(["'%s'" % norm_id(*node) for node in nodes])
  File "/usr/local/lib/python3.8/dist-packages/indra_cogex/client/subnetwork.py", line 40, in <listcomp>
    nodes_str = ", ".join(["'%s'" % norm_id(*node) for node in nodes])
TypeError: norm_id() takes 2 positional arguments but 8 were given

I see two solutions worth exploring:

  1. Turn off validation if possible. I quickly tried locally to pass validate=False and format_checker=None to Flask restx's Api() class, but it didn't seem to make a difference, I might have been missing something.
  2. Fix potential source of issue: it looks like the code generating the endpoints assume that all parameters are just lists of strings (coming from parameters being tuples of (namespace, identifier), see queries_web/__init__.py, line 116. In the case above, the parameters is a list of lists (list of tuples in the python code). The fix here would be to make sure the correct flask_restx.fields type is used for the endpoint, perhaps by adding them next to the examples for the parameters.
@kkaris kkaris added the documentation Improvements or additions to documentation label Sep 11, 2024
@kkaris kkaris changed the title Fix Swagger apidocs - subnetwork relations Fix Swagger apidocs validation errors Sep 11, 2024
@kkaris
Copy link
Collaborator Author

kkaris commented Sep 11, 2024

I quickly tried option 2 and it seems to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant