Issue #6372
closedKeyError when generating api schema with nested routes
Description
In our api schema generation code, we iterate through a sorted list of endpoints[0]. We build a list of resource examples as we go. We store them by a 'resource_path' (eg /pulp/api/v3/repositories/file/file/{repository_pk}/'
)[1] but look them up 'resource_other_path' (eg /pulp/api/v3/repositories/file/file/{pulp_id}/'
)[2].
Consider the following sorted set of endpoints:
'/pulp/api/v3/repositories/file/file/{pulp_id}/'
'/pulp/api/v3/repositories/file/file/{repository_pk}/versions/'
'/pulp/api/v3/repositories/file/file/{repository_pk}/versions/{number}/'
When we get to the second endpoint, the resource_other_path is '/pulp/api/v3/repositories/file/file/{pulp_id}/'
which exists in our resource_example because it was added when we processed '/pulp/api/v3/repositories/file/file/{pulp_id}/'
.
But now consider a second set of endpoints:
'/pulp/api/v3/exporters/file/filesystem/{exporter_pk}/exports/',
'/pulp/api/v3/exporters/file/filesystem/{exporter_pk}/exports/{pulp_id}/',
'/pulp/api/v3/exporters/file/filesystem/{pulp_id}/',
When it goes to process the first item, it will try to lookup '/pulp/api/v3/exporters/file/filesystem/{pulp_id}/'
which doesn't yet exist.
[0] https://github.com/pulp/pulpcore/blob/4a63e05e9aa6f383c7ba756635c0d11c092d539c/pulpcore/app/openapigenerator.py#L72 [1] https://github.com/pulp/pulpcore/blob/master/pulpcore/app/openapigenerator.py#L119 [2] https://github.com/pulp/pulpcore/blob/master/pulpcore/app/openapigenerator.py#L121
Updated by dkliban@redhat.com over 4 years ago
- Status changed from NEW to ASSIGNED
- Assignee set to dkliban@redhat.com
- Sprint set to Sprint 69
Updated by dkliban@redhat.com over 4 years ago
- Status changed from ASSIGNED to POST
Added by dkliban@redhat.com over 4 years ago
Updated by dkliban@redhat.com over 4 years ago
- Status changed from POST to MODIFIED
Applied in changeset pulpcore|3a62068d91fd39130255b5381c276012c5bdbeb2.
Updated by ttereshc over 4 years ago
- Status changed from MODIFIED to CLOSED - CURRENTRELEASE
- Sprint/Milestone set to 3.3.0
Normalize PK path parameter names used in openapi schema generation
This ensures that when the endpoints are sorted, the parent endpoint appears before the endpoints nested under it.
fixes: #6372 https://pulp.plan.io/issues/6372