How to create client libraries for my Apigee proxies from my swagger spec

Not applicable

We have a detailed swagger spec for our APIs at https://github.com/amadeus-travel-innovation-sandb... We'd like to use this to provide API libraries for our clients from our developer portal.

Other than the Generate Client dropdown menu at editor.swagger.io, I can't find any public services that host swagger-codegen; the project that can generate client libraries for various programming languages from a swagger spec. Does Apigee host a swagger-codegen service for clients to use?

I thought it might also be possible to run this as a Java Callout in a new API proxy running entirely on Apigee, but looking at the cookbooks, I realized this might be quite difficult to do. If such a service doesn't do this, is it possible to do it this way?

1 1 1,032
1 REPLY 1

Not applicable

OK, turns out that generator.swagger.io hosts a public service to generate client API libraries from your Swagger spec. Unfortunately, it uses POST to get the URL of the Swagger document, so it's not that easy to embed in a HTML page. Fortunately, you can build an API proxy quite easily to make it build a variety of clients for your Swagger spec.

  1. Make a new API proxy that targets https://generator.swagger.io/api/gen/clients
  2. Add an Assign Message policy to your Request Preflow that does the following
    <Set>
            <Verb>POST</Verb>
            <Headers>
                <Header name="Content-Type">application/json</Header>
            </Headers>
            <Payload>\{"swaggerUrl":"https://link.to/your-swagger-spec.yml"}</Payload>
        </Set>
  3. Add a Javascript policy to your Response Postflow that does this
    var content = context.getVariable('response.content');
    var body = JSON.parse(content);
    context.setVariable('response.header.Location', "" + body.link);
    context.setVariable('response.status.code', 303);

And you're all done. When you go to http://you.apigee.net/proxy-name-from-step-1/language it will give a redirect back to your browser to download the client library generated from your swagger spec in the language you put in the URL.

Enjoy!