-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add OpenAPI view at /api/automation-hub/v3/openapi.json * Also add openapi.yaml and redoc at /api/automation-hub/docs/ * Add swaggerui view too * Add some drf_spect hooks to config * Exclude /pulp and /_ui for now * Add Meta.ref_name to ui.serializers.Serializer based... Serializers ui.Serializer is metaclass that changes that populates the ref name based on some heuristics. The generated ref_name was conflicting with the drf_spectacular finds the serializer name resulting in weirdness. Issue: AAH-57
- Loading branch information
Showing
7 changed files
with
137 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
Enable OpenAPI spec at cloud.redhat.com/api/automation-hub/v3/openapi.json | ||
|
||
Update docs and decorators on viewsets and serializers to generate correct | ||
spec. | ||
|
||
Modify pulpcore openapigenerator to include concrete hrefs in addition | ||
to {ansible_collection_href}/ style endpoints. | ||
|
||
Need to provide the existing pulp /pulp/api/v3/docs/ view and | ||
a new view at /api/automation-hub/v3/openapi.json | ||
- new viewset may need drf-spectacular tweaks | ||
|
||
Sub tasks: | ||
- Create a snapshot of the OpenAPI spec in CI. | ||
- setup any useful tooling for validating/verifying the spec | ||
- openapidiff ? | ||
- Enable swaggerui view (/v3/swagger/ ?) | ||
|
||
Potential problems: | ||
|
||
- May want/need to import pulpcore openapi generator utils, which may not be in plugin | ||
api | ||
|
||
Before: | ||
|
||
Pulp uses drf-spectacular | ||
|
||
A "live" generated version of the API is available at | ||
|
||
http://localhost:5001/pulp/api/v3/docs/api.json | ||
http://localhost:5001/pulp/api/v3/docs/api.yaml | ||
|
||
And a "redoc" view at: | ||
http://localhost:5001/pulp/api/v3/docs/ | ||
|
||
Note some issues: | ||
|
||
- Lots of endpoints are in the form "{ansible_collection_import_href}" | ||
- in theory, all endpoints should start with a "/" but even | ||
when evaluated, the above is "ansible/ansible/v3/collections/artifacts" | ||
|
||
- schema objects are inconsistent named | ||
- pulpcore has no prefix | ||
- pulp_ansible has ansible. prefix | ||
- galaxy_ng sometimes? has galaxy. prefix and sometimes Galaxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import logging | ||
|
||
log = logging.getLogger(__name__) | ||
log.debug('openapi autoschema') | ||
|
||
|
||
def preprocess_debug_logger(endpoints, **kwargs): | ||
"""Log and then return an iterable of (path, path_regex, method, callback) tuples""" | ||
|
||
log.debug("kwargs: %s", repr(kwargs)) | ||
|
||
for path, path_regex, method, callback in endpoints: | ||
log.debug('path=%s, path_regex=%s, method=%s, callback=%s', | ||
path, path_regex, method, callback) | ||
|
||
return endpoints | ||
# return [ | ||
# (path, path_regex, method, callback) for path, path_regex, method, callback in endpoints | ||
# if log.debug('path=%s, path_regex=%s, method=%s, callback=%s', | ||
# path, path_regex, method, callback) | ||
# ] | ||
|
||
|
||
def preprocess_exclude_endpoints(endpoints, **kwargs): | ||
"""Return an iterable of (path, path_regex, method, callback) with some endpoints removed | ||
For example, the default is to to remove '/pulp' and '/_ui/' api endpoints. | ||
""" | ||
|
||
return [ | ||
(path, path_regex, method, callback) for path, path_regex, method, callback in endpoints | ||
if not path.startswith('/pulp') and '/_ui/' not in path | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters