Project

Profile

Help

Task #3580

closed

Document how to generate REST API bindings using swagger-codegen

Added by dkliban@redhat.com almost 6 years ago. Updated almost 5 years ago.

Status:
CLOSED - COMPLETE
Priority:
Normal
Category:
-
Sprint/Milestone:
Start date:
Due date:
% Done:

0%

Estimated time:
Platform Release:
Groomed:
Yes
Sprint Candidate:
Yes
Tags:
API Bindings, Pulp 2
Sprint:
Sprint 42
Quarter:

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

Copied from Python Support - Task #3579: Publish REST API bindings for Python on PyPICLOSED - COMPLETE

Actions
Actions #1

Updated by dkliban@redhat.com almost 6 years ago

  • Copied from Task #3579: Publish REST API bindings for Python on PyPI added
Actions #2

Updated by dkliban@redhat.com almost 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
Actions #3

Updated by CodeHeeler almost 6 years ago

  • Groomed changed from No to Yes
Actions #4

Updated by daviddavis almost 6 years ago

  • Sprint set to Sprint 36

Be sure to add a note that any installed plugins will be included in the bindings.

Actions #5

Updated by rchan almost 6 years ago

  • Sprint changed from Sprint 36 to Sprint 37
Actions #6

Updated by rchan almost 6 years ago

  • Sprint changed from Sprint 37 to Sprint 38
Actions #7

Updated by rchan almost 6 years ago

  • Sprint changed from Sprint 38 to Sprint 39
Actions #8

Updated by daviddavis over 5 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?

Actions #9

Updated by dkliban@redhat.com over 5 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

Actions #10

Updated by daviddavis over 5 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.

Actions #11

Updated by dkliban@redhat.com over 5 years ago

  • Sprint changed from Sprint 39 to Sprint 40
Actions #12

Updated by daviddavis over 5 years ago

  • Tags API Bindings added
  • Tags deleted (Documentation, Pulp 3)
Actions #13

Updated by rchan over 5 years ago

  • Sprint changed from Sprint 40 to Sprint 41
Actions #14

Updated by rchan over 5 years ago

  • Sprint changed from Sprint 41 to Sprint 42
Actions #15

Updated by dkliban@redhat.com over 5 years ago

  • Status changed from NEW to ASSIGNED
  • Assignee set to dkliban@redhat.com
Actions #16

Updated by dkliban@redhat.com over 5 years ago

  • Status changed from ASSIGNED to CLOSED - COMPLETE
Actions #17

Updated by bmbouter almost 5 years ago

  • Tags Pulp 2 added

Also available in: Atom PDF