pulp / pulp/pulpcore

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

Open
#1,991 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue
Dominant language
Python
Stars
598
Forks
168
Avg merge
1d 4h
Merged PRs (30d)
86

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with pulpcore.openapi.PulpSchemaGenerator.convert_endpoint_path_params() and trace how it is called during spec parsing. Compare the generated output for /api/automation-hub/v3/namespaces/{name}/ with the logged example. Done means endpoint paths with path parameters remain valid in the generated OpenAPI schema instead of being replaced by href-only paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.