swagger-angular-client

WebJar for swagger-angular-client

License

License

APACHE 2
Categories

Categories

Angular User Interface Web Frameworks CLI Swagger Program Interface REST Frameworks
GroupId

GroupId

org.webjars.bower
ArtifactId

ArtifactId

swagger-angular-client
Last Version

Last Version

0.1.12
Release Date

Release Date

Type

Type

jar
Description

Description

swagger-angular-client
WebJar for swagger-angular-client
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/signalfx/swagger-angular-client

Download swagger-angular-client

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.bower/swagger-angular-client/ -->
<dependency>
    <groupId>org.webjars.bower</groupId>
    <artifactId>swagger-angular-client</artifactId>
    <version>0.1.12</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.bower/swagger-angular-client/
implementation 'org.webjars.bower:swagger-angular-client:0.1.12'
// https://jarcasting.com/artifacts/org.webjars.bower/swagger-angular-client/
implementation ("org.webjars.bower:swagger-angular-client:0.1.12")
'org.webjars.bower:swagger-angular-client:jar:0.1.12'
<dependency org="org.webjars.bower" name="swagger-angular-client" rev="0.1.12">
  <artifact name="swagger-angular-client" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.bower', module='swagger-angular-client', version='0.1.12')
)
libraryDependencies += "org.webjars.bower" % "swagger-angular-client" % "0.1.12"
[org.webjars.bower/swagger-angular-client "0.1.12"]

Dependencies

compile (1)

Group / Artifact Type Version
org.webjars.bower : angular jar [1.0.0,2)

Project Modules

There are no modules declared in this project.

swagger-angular-client

AngularJS service for communicating with endpoints described by swagger v1.2.

Usage

To use, include one of these files in your application:

You may also bower install swagger-angular-client to install using bower. Once you've included the script, you can include the swagger-client module as a dependency to your existing application and use the swaggerClient service to generate api clients.

Schemas can be generated using fetch-swagger-schema.

Simple Example

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Example</title>
  <script src="angular.js"></script>
</head>
<body ng-app="myApp" ng-cloak>
    Pet: {{ pet.name || 'Loading...' }}

  <script src="swagger-client.js"></script>

  <!-- `petStoreSchema.js` exposes the JSON object generated by [fetch-swagger-schema] when run against http://petstore.swagger.wordnik.com/api/api-docs to the window as `PetStoreSchema` (see `examples/petStoreSchema.js`). -->
  <script src="petStoreSchema.js"></script>

  <script>
  angular.module('myApp', ['swagger-client'])
    .run(function($rootScope, swaggerClient){
      var api = swaggerClient(PetStoreSchema);

      api.auth('secret-key');
      api.pet.addPet({id: 1, name: 'Bob'}).then(function(){
        return api.pet.getPetById(1);
      }).then(function(pet){
        $rootScope.pet = pet;
      });
    });
  </script>
</body>
</html>

Real-world Example

'use strict';

// First, we need to define a provider for the api client, we'll call it 'myAPI'
angular.module('data').provider('myAPI',
['window', function(window){
  var schema = window.API_SCHEMA,
    auth;

  // Override the base path to enable pointing to different backends
  this.basePath = function(basePath){
    schema.apis.forEach(function(api){
      api.apiDeclaration.basePath = basePath;
    });
  };

  // Allows for setting the auth token during .config() phase of app start up.
  this.auth = function(authToken){
    auth = authToken;
  };

  // Instantiates the swagger-angular-client
  this.$get = ['$rootScope', 'swaggerClient', function($rootScope, swaggerClient){
    var api = swaggerClient(schema);
    api.authorization(auth);

    // Handle any future api token changes
    $rootScope.$on('api token changed', function($event, authToken){
      api.authorization(authToken);
    });

    return api;
  }];
}])

// Now we'll configure myAPI during app start up by setting the auth token.
// You would decide where this token comes from. Maybe it's ok to embed directly
// in the code. Maybe it comes from a cookie. Maybe you don't even need auth.
// This all depends on your auth scheme.
.config(['myAPIProvider', function(myAPIProvider){
  myAPIProvider.auth(THE_TOKEN);
}])

// Finally, we can start using myAPI in the application
.run(['myAPI', function(myAPI){
  // This would be an application-specific call. In this example, we make an
  // http request to a api endpoint to notify the metrics resource that the
  // application has loaded.
  myAPI.metrics.appLoaded({
    time: Date.now()
  });
}]);
org.webjars.bower

SignalFx

Versions

Version
0.1.12