Last active
March 3, 2016 15:16
-
-
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
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
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'); | |
} | |
); |
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
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' |
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
paths: | |
/me: | |
$ref: 'v1-assets/paths/me.yaml' |
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
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