Task #3580
closedDocument how to generate REST API bindings using swagger-codegen
0%
Description
With help from swagger-codegen[0], Pulp's API schema can be used to generate bindings in many different languages.
I was able to GET the schema in JSON format from http://localhost:8000/api/v3/docs/api.json and then uploaded the JSON file to swagger editor[1]. I then clicked on "Generate Client" and selected "Python". This produced a ZIP archive that contained a python package with the bindings and documentation. The hosted solution is backed by a Java application called swagger-codegen[2].
The goal of this task is to document how swagger-codegen can be used from the command line to generate bindings in any language supported by swagger-codegen.
[0] https://swagger.io/swagger-codegen/
[1] http://editor.swagger.io/#/
[2] https://github.com/swagger-api/swagger-codegen
Related issues
Updated by dkliban@redhat.com over 6 years ago
- Copied from Task #3579: Publish REST API bindings for Python on PyPI added
Updated by dkliban@redhat.com over 6 years ago
- Subject changed from Publish REST API bindings for Ruby on rubygems.org to Document how to generate REST API bindings using swagger-codegen
- Description updated (diff)
- Tags Documentation added
Updated by daviddavis over 6 years ago
- Sprint set to Sprint 36
Be sure to add a note that any installed plugins will be included in the bindings.
Updated by daviddavis over 6 years ago
Apparently the instructions are here:
https://www.redhat.com/archives/pulp-dev/2018-May/msg00098.html
However, I am not too keen on having to manually apply a patch every time we want to generate our bindings. Is there a way to submit a patch upstream or fork the swagger-codegen repo maybe?
Updated by dkliban@redhat.com over 6 years ago
The instructions should tell the user to download the jar from fedorapeople.org[0].
https://repos.fedorapeople.org/pulp/pulp/swagger/swagger-codegen-cli.jar
Updated by daviddavis over 6 years ago
I'm testing out the python bindings but they don't seem to work. I generated the python bindings and am trying to call the versions content endpoint:
from swagger_client.api.repositories_api import RepositoriesApi
api = RepositoriesApi()
api.repositories_versions_content("http://localhost:8000/pulp/api/v3/repositories/3a723819-6302-4352-8ac6-3875ac7b7429/versions/2/") # fails
api.repositories_versions_content("/repositories/3a723819-6302-4352-8ac6-3875ac7b7429/versions/2/") # doesn't work either
It looks like the bindings are calling:
[12/Jul/2018 13:20:23] "GET /pulp/api/v3http%3A%2F%2Flocalhost%3A8000%2Fpulp%2Fapi%2Fv3%2Frepositories%2F3a723819-6302-4352-8ac6-3875ac7b7429%2Fversions%2F2%2F HTTP/1.1" 404 3183
It's also kind of strange that there's no "content" in the url which leads me to believe that I have to specify /pulp/api/v3/repositories/3a723819-6302-4352-8ac6-3875ac7b7429/versions/2/content/
as the href but that doesn't seem right either.
Edit: Found a solution to the urlencoding. Looks like you have to set safe_chars_for_path_param
to '/'
in the configuration of the python bindings.
Updated by dkliban@redhat.com over 6 years ago
- Sprint changed from Sprint 39 to Sprint 40
Updated by daviddavis over 6 years ago
- Tags API Bindings added
- Tags deleted (
Documentation, Pulp 3)
Updated by dkliban@redhat.com about 6 years ago
- Status changed from NEW to ASSIGNED
- Assignee set to dkliban@redhat.com
Updated by dkliban@redhat.com about 6 years ago
- Status changed from ASSIGNED to CLOSED - COMPLETE
I wrote a blog post about this.
https://pulpproject.org/2018/09/04/generate-pulp-3-python-client-using-swagger-codegen/