Skip to content

Instantly share code, notes, and snippets.

@asselin
Last active March 3, 2016 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asselin/29ea9566cbe435d7107e to your computer and use it in GitHub Desktop.
Save asselin/29ea9566cbe435d7107e to your computer and use it in GitHub Desktop.
Code for 'Client Side Swagger Support for AngularJS' http://www.pointsource.com/blog/client-side-swagger-support-for-angularjs
var SwaggerParser = require('swagger-parser');
var fs = require('fs');
var CodeGen = require('swagger-js-codegen').CodeGen;
SwaggerParser.validate('uber-v1.yaml').then(
function(api) {
var angularjsSourceCode = CodeGen.getAngularCode({
className: 'UberV1',
swagger: api
});
fs.writeFileSync('uber-v1.js',
angularjsSourceCode,
'utf-8');
}
);
get:
summary: User Profile
description: >
The User Profile endpoint returns information
about the Uber user that has authorized with
the application.
tags:
- User
responses:
200:
description: Profile information for a user
schema:
$ref: '../definitions/Profile.yaml'
default:
description: Unexpected error
schema:
$ref: '../definitions/Error.yaml'
paths:
/me:
$ref: 'v1-assets/paths/me.yaml'
MyController.$inject = ['UberV1'];
function MyController(UberV1) {
var uber = new UberV1();
uber.getMe().then(
function(res) {
console.log('success', res);
},
function(err) {
console.log('error', err);
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment