我正在开发angular js app。我正在尝试使用模块“Swagger angular client”来生成api。我使用以下swagger angular客户端模块:"signalfx:swagger-angular-client"
为了理解这个模块,我制作了一个简单的swagger模式。但是我在谷歌浏览器检查器中遇到了这个错误:
angular.min.js:117 TypeError: Cannot read property 'forEach' of undefined
at processSchema (_prelude.js:102)
at createClient (_prelude.js:11)
at swaggerClient.js:32
.................
.............
我不知道这个问题的根本原因。似乎招摇角度模块不接受我的招摇模式。
有人可以帮忙解决这个问题吗?
谢谢你的帮助!
这是我的app.js
angular.module('myApp', ['swagger-client']);
这是我的索引:
<!DOCTYPE html>
<html>
<head>
<script src="angular.min.js"></script>
<script src="swagger-angular-client.js"></script>
<script src="app.js"></script>
<script src="mySwaggerFactory.js"></script>
<script src="myController.js"></script>
</head>
<body ng-app="myApp">
<div ng-controller="Maincontroller">
<h1>Swagger Angular</h1>
</div>
</body>
</html>
这是我的事实
angular.module('myApp').factory('myApi', ['swaggerClient', function(swaggerClient){
var schema={
"swagger" : "2.0",
"info" : {
"description" : "Tidiane application store.",
"version" : "0.1",
"title" : "Tidiane application store.",
"contact" : {
"name" : "Tidiane"
},
"license" : {
"name" : "TODO: thanks for asking, yes it's copyrighted, I have to ask our jurists.",
"url" : "http://licenseUrl"
}
},
"host" : "replace.me.please",
"basePath" : "/api/0.1",
"tags" : [ {
"name" : "services"
}, {
"name" : "user"
} ],
"paths" : {
"/services/applications/{applicationID}" : {
"get" : {
"tags" : [ "services" ],
"summary" : "find one application by its id",
"description" : "",
"operationId" : "getApplicationById",
"parameters" : [ {
"name" : "applicationID",
"in" : "path",
"description" : "The application id",
"required" : true,
"type" : "string"
} ],
"responses" : {
"200" : {
"description" : "successful operation",
"schema" : {
"$ref" : "#/definitions/ApplicationData"
}
}
}
}
}
},
"definitions" : {
"ApplicationInfo" : {
"type" : "object",
"required" : [ "name" ],
"properties" : {
"id" : {
"type" : "string",
"example" : "slkkdiijqhq__çç_çç",
"description" : ""
},
"name" : {
"type" : "string",
"example" : "Service",
"description" : "The short name"
}
},
"description" : "short info about application"
},
"ApplicationData" : {
"type" : "object",
"required" : [ "applicationType", "deploymentMode", "description", "isEnabled", "name", "theme" ],
"properties" : {
"id" : {
"type" : "string",
"example" : "ç__z_z_è-d-xhjsyuhdycy",
"description" : "description"
},
"name" : {
"type" : "string",
"example" : "Services 1",
"description" : "The short name"
},
"applicationType" : {
"type" : "string",
"example" : "INTERNAL",
"description" : "Application description"
},
"deploymentMode" : {
"type" : "string",
"example" : "UNIQUE",
"description" : "Application description."
},
"description" : {
"type" : "string",
"description" : "Description of the application"
},
"dateTime" : {
"type" : "string",
"format" : "date-time",
"example" : "2016-01-01",
"description" : "Creation date of the application",
"readOnly" : true
},
"isEnabled" : {
"type" : "boolean",
"example" : true,
"description" : "Application description.",
"default" : false
},
"theme" : {
"type" : "string",
"example" : "Service Management",
"description" : "the name of the Service"
}
}
}
}
};
return {
// Instantiates the swagger-angular-client
getApi: function(){
var api = swaggerClient(schema);
console.log("this api", api);
return api;
}
};
}]);
这是我的控制器
angular.module('myApp').controller('Maincontroller',['$scope','myApi',function($scope, myApi){
$scope.api = myApi.getApi();
}]);