1 | "use strict";
|
2 | var api_load_resolve_1 = require('./api-load-resolve');
|
3 | var api_page_component_1 = require('./api-page.component');
|
4 | var _ = require('lodash');
|
5 | function createApiRoutes(def) {
|
6 | var routes = [];
|
7 | if (def['versions'] && def['files']) {
|
8 | var apiDefinition_1 = def;
|
9 | apiDefinition_1.versions.forEach(function (apiVersion) {
|
10 | var apiVersionName = apiVersion.name;
|
11 | apiDefinition_1.files.forEach(function (apiFile) {
|
12 | var fileName = apiFile.apiTitle;
|
13 | var apiUrl = apiVersionName + '/' + fileName;
|
14 | apiVersion.exclude = apiVersion.exclude || [];
|
15 | if (apiVersion.exclude && apiVersion.exclude.indexOf(fileName) === -1) {
|
16 | routes.push({
|
17 | path: apiUrl,
|
18 | component: api_page_component_1.ApiPageComponent,
|
19 | resolve: {
|
20 | resolveData: api_load_resolve_1.ApiLoadResolve
|
21 | },
|
22 | data: {
|
23 | isStaticApi: false,
|
24 | apiDefinition: apiDefinition_1,
|
25 | apiVersion: apiVersion,
|
26 | apiFile: apiFile
|
27 | }
|
28 | });
|
29 | }
|
30 | });
|
31 | });
|
32 | }
|
33 | else if (def['apis']) {
|
34 | var apiDefinition_2 = def;
|
35 | apiDefinition_2.apis.forEach(function (apiItem) {
|
36 | var apiVersion = apiItem.version;
|
37 | if (apiItem.ref && apiItem.ref !== '') {
|
38 | var refApiItem = apiDefinition_2.apis.find(function (item) {
|
39 | return item.version === apiItem.ref;
|
40 | });
|
41 | apiItem.files = refApiItem.files;
|
42 | }
|
43 | if (apiItem.alongWith && apiItem.alongWith !== '') {
|
44 | var alongApiItem = apiDefinition_2.apis.find(function (item) {
|
45 | return item.version === apiItem.alongWith;
|
46 | });
|
47 | var withoutDups = _.filter(alongApiItem.files, function (item) {
|
48 | var found = apiItem.files.find(function (existsItem) {
|
49 | return existsItem.name === item.name;
|
50 | });
|
51 | return !found;
|
52 | });
|
53 | apiItem.files = apiItem.files.concat(withoutDups);
|
54 | }
|
55 | var redirectionUrl = '/';
|
56 | apiItem.files.forEach(function (apiFile, index) {
|
57 | var apiUrl = apiVersion + '/' + apiFile.urlName;
|
58 | if (index === 0) {
|
59 | redirectionUrl = apiUrl;
|
60 | }
|
61 | routes.push({
|
62 | path: apiUrl,
|
63 | component: api_page_component_1.ApiPageComponent,
|
64 | resolve: {
|
65 | resolveData: api_load_resolve_1.ApiLoadResolve
|
66 | },
|
67 | data: {
|
68 | isStaticApi: true,
|
69 | apiDefinition: apiDefinition_2,
|
70 | apiVersion: apiItem,
|
71 | apiFile: apiFile
|
72 | }
|
73 | });
|
74 | });
|
75 | routes.push({
|
76 | path: apiVersion,
|
77 | redirectTo: redirectionUrl
|
78 | });
|
79 | });
|
80 | }
|
81 | return routes;
|
82 | }
|
83 | exports.createApiRoutes = createApiRoutes;
|
84 |
|
\ | No newline at end of file |