pulp / pulpcore

Pulp 3 pulpcore package https://pypi.org/project/pulpcore/
GNU General Public License v2.0
301 stars 116 forks source link

openapi generation replaces entire url of endpoints with path_params with {*_href} urls #1991

Open pulpbot opened 2 years ago

pulpbot commented 2 years ago

Author: alikins (alikins)

Redmine Issue: 8715, https://pulp.plan.io/issues/8715


For example:

/api/automation-hub/v3/namespaces/{name}/

gets transformed to

{galaxy_namespace_href}

This happens for any urls with a path param unless they bound to 'list' or 'create' actions. ie, except for POST and GET list'y things, all the endpoint urls in the generated spec get replaced.

I think the reason why the generated openapi schema is so weird and wrong (like for the spec generated for galaxy namespaces mentioned in https://issues.redhat.com/browse/AAH-450). If a url path has any path param in it, pulpcore.openapi.PulpSchemaGenerator.convert_endpoint_path_params() replaces it with some variation of {blah_href}.

For ex, GET /api/automation-hub/v3/namespaces/{name}/ is mogrified into GET {galaxy_namespace_href}. But 'list' and 'create' actions dont get modified

So except for 'list' and 'create' actions all of the galaxy_ng endpoint urls in the spec are broken. For galaxy_ng, this can be confirmed by looking at /api/automation-hub/v3/swagger-ui/

Some output from logging the spec generation for the /api/automation-hub/v3/namespaces/ endpoints:

 pulpcore.openapi __init__.parse:381   165 - path=/api/automation-hub/v3/namespaces/
 pulpcore.openapi __init__.parse:382   165 - path_regex=api/automation-hub/v3/^namespaces/$
 pulpcore.openapi __init__.parse:383   165 - method=POST
 pulpcore.openapi __init__.parse:384   165 - view=<galaxy_ng.app.api.v3.viewsets.namespace.NamespaceViewSet object at 0x7f5a4e729ef0>
 pulpcore.openapi __init__.parse:396   165 - path2=/api/automation-hub/v3/namespaces/
^ -- path not munged for a POST / 'create'

 pulpcore.openapi __init__.parse:400   165 - operation={'operationId': 'api_automation_hub_v3_namespaces_create', 'description': 'Override to validate for name duplication before serializer validation.', 'summary': 'Create a namespace', 'tags': ['Api: Automation-Hub Namespaces'], 'requestBody': {'content': {'application/json': {'schema': {'$ref': '#/components/schemas/Namespace'}}, 'application/x-www-form-urlencoded': {'schema': {'$ref': '#/components/schemas/Namespace'}}, 'multipart/form-data': {'schema': {'$ref': '#/components/schemas/Namespace'}}}, 'required': True}, 'security': [{'cookieAuth': []}, {'tokenAuth': []}], 'responses': {'201': {'content': {'application/json': {'schema': {'$ref': '#/components/schemas/NamespaceResponse'}}}, 'description': ''}}}
 pulpcore.openapi __init__.parse:401   165 - schema.method=POST

 pulpcore.openapi __init__.parse:381   165 - path=/api/automation-hub/v3/namespaces/{name}/
 pulpcore.openapi __init__.parse:382   165 - path_regex=api/automation-hub/v3/^namespaces/(?P<name>[^/.]+)/$
 pulpcore.openapi __init__.parse:383   165 - method=GET
 pulpcore.openapi __init__.parse:384   165 - view=<galaxy_ng.app.api.v3.viewsets.namespace.NamespaceViewSet object at 0x7f5a4e729f28>
 pulpcore.openapi __init__.convert_endpoint_path_params:345   165 - view=<galaxy_ng.app.api.v3.viewsets.namespace.NamespaceViewSet object at 0x7f5a4e729f28>, parent_viewset=None
 pulpcore.openapi __init__.parse:396   165 - path2={galaxy_namespace_href}
 ^ -- path is munged for a GET /  'retrieve'

 pulpcore.openapi __init__.parse:400   165 - operation={'operationId': 'namespace_instance_read', 'description': '', 'summary': 'Inspect a namespace', 'parameters': [{'in': 'path', 'name': 'galaxy_namespace_href', 'schema': {'type': 'string'}, 'required': True}], 'tags': ['Namespace: Instance'], 'security': [{'cookieAuth': []}, {'tokenAuth': []}], 'responses': {'200': {'content': {'application/json': {'schema': {'$ref': '#/components/schemas/NamespaceResponse'}}}, 'description': ''}}}
 pulpcore.openapi __init__.parse:401   165 - schema.method=GET
pulpbot commented 2 years ago

From: alikins (alikins) Date: 2021-05-07T00:06:33Z


I forgot to mention this is observed with the pulpcore 3.11 branch.

stale[bot] commented 2 years ago

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

stale[bot] commented 2 years ago

This issue is no longer marked for closure.