@@ -9,12 +9,7 @@ import { Badge } from "@/components/ui/badge";
9
9
import JsonTreeContainer , { JsonTree } from "@/components/JsonTree" ;
10
10
import ApiButtons from "@/components/ApiButtons" ;
11
11
import VisitCounter from "@/components/VisitCounter" ;
12
-
13
- interface ApiVersion {
14
- version : string ;
15
- swaggerUrl : string ;
16
- swaggerYamlUrl : string ;
17
- }
12
+ import type { ApiVersion } from "@/types/api" ;
18
13
19
14
function stripMarkdown ( markdown : string ) : string {
20
15
return markdown
@@ -37,85 +32,95 @@ export function getData(
37
32
? `${ providerSlug } :${ serviceSlug } `
38
33
: providerSlug ;
39
34
35
+ if ( apiList [ targetKey ] ) {
36
+ return processApiData ( targetKey , apiList [ targetKey ] ) ;
37
+ }
38
+
40
39
for ( const key in apiList ) {
41
- if ( apiList . hasOwnProperty ( key ) && key === targetKey ) {
42
- try {
43
- const api = apiList [ key ] ;
44
- const versions = api . versions || { } ;
45
- const preferred = api . preferred || Object . keys ( versions ) [ 0 ] || "" ;
46
- const preferredVersion = versions [ preferred ] || { } ;
47
- const info = preferredVersion . info || { } ;
48
- const externalDocs = preferredVersion . externalDocs || { } ;
49
- const contact = info . contact || { } ;
50
-
51
- const logo = {
52
- url : info [ "x-logo" ] ?. url || "/assets/images/no-logo.svg" ,
53
- backgroundColor : info [ "x-logo" ] ?. backgroundColor || null ,
54
- } ;
55
-
56
- const externalUrl =
57
- externalDocs . url ||
58
- contact . url ||
59
- ( key . indexOf ( ".local" ) < 0 ? `https://${ key . split ( ":" ) [ 0 ] } ` : "" ) ;
60
-
61
- let origUrl = "" ;
62
- if (
63
- info [ "x-origin" ] &&
64
- Array . isArray ( info [ "x-origin" ] ) &&
65
- info [ "x-origin" ] . length > 0
66
- ) {
67
- origUrl =
68
- info [ "x-origin" ] [ 0 ] ?. url || preferredVersion . swaggerUrl || "" ;
69
- } else {
70
- origUrl = preferredVersion . swaggerUrl || "" ;
71
- }
72
-
73
- const categories = info [ "x-apisguru-categories" ] || [ ] ;
74
- const tags = info [ "x-tags" ] || [ ] ;
75
-
76
- const versionsArray = Object . entries ( versions ) . map (
77
- ( [ version , details ] : [ string , any ] ) => ( {
78
- version,
79
- swaggerUrl : details ?. swaggerUrl || "" ,
80
- swaggerYamlUrl : details ?. swaggerYamlUrl || "" ,
81
- } )
82
- ) ;
83
-
84
- const description = info . description || "No description available" ;
85
- const cardDescription = marked ( description ) ;
86
- const cardDescriptionPlain = stripMarkdown ( description ) ;
87
-
88
- return {
89
- name : key ,
90
- preferred : api . preferred || "" ,
91
- info,
92
- api : {
93
- swaggerUrl : preferredVersion . swaggerUrl || "" ,
94
- swaggerYamlUrl : preferredVersion . swaggerYamlUrl || "" ,
95
- } ,
96
- logo,
97
- externalUrl,
98
- origUrl,
99
- versions : versionsArray ,
100
- cardDescription,
101
- cardDescriptionPlain,
102
- categories,
103
- tags,
104
- integrations : api . integrations || [ ] ,
105
- updated : preferredVersion . updated || "" , // Include the updated field
106
- } ;
107
- } catch ( error ) {
108
- console . error ( `Error processing API ${ key } :` , error ) ;
109
- return null ;
110
- }
40
+ if (
41
+ apiList . hasOwnProperty ( key ) &&
42
+ key . toLowerCase ( ) === targetKey . toLowerCase ( )
43
+ ) {
44
+ return processApiData ( key , apiList [ key ] ) ;
111
45
}
112
46
}
47
+
113
48
console . warn (
114
49
`No API found for provider: ${ providerSlug } , service: ${ serviceSlug } `
115
50
) ;
116
51
return null ;
117
52
}
118
53
54
+ function processApiData ( key : string , api : any ) {
55
+ try {
56
+ const versions = api . versions || { } ;
57
+ const preferred = api . preferred || Object . keys ( versions ) [ 0 ] || "" ;
58
+ const preferredVersion = versions [ preferred ] || { } ;
59
+ const info = preferredVersion . info || { } ;
60
+ const externalDocs = preferredVersion . externalDocs || { } ;
61
+ const contact = info . contact || { } ;
62
+
63
+ const logo = {
64
+ url : info [ "x-logo" ] ?. url || "/assets/images/no-logo.svg" ,
65
+ backgroundColor : info [ "x-logo" ] ?. backgroundColor || null ,
66
+ } ;
67
+
68
+ const externalUrl =
69
+ externalDocs . url ||
70
+ contact . url ||
71
+ ( key . indexOf ( ".local" ) < 0 ? `https://${ key . split ( ":" ) [ 0 ] } ` : "" ) ;
72
+
73
+ let origUrl = "" ;
74
+ if (
75
+ info [ "x-origin" ] &&
76
+ Array . isArray ( info [ "x-origin" ] ) &&
77
+ info [ "x-origin" ] . length > 0
78
+ ) {
79
+ origUrl = info [ "x-origin" ] [ 0 ] ?. url || preferredVersion . swaggerUrl || "" ;
80
+ } else {
81
+ origUrl = preferredVersion . swaggerUrl || "" ;
82
+ }
83
+
84
+ const categories = info [ "x-apisguru-categories" ] || [ ] ;
85
+ const tags = info [ "x-tags" ] || [ ] ;
86
+
87
+ const versionsArray = Object . entries ( versions ) . map (
88
+ ( [ version , details ] : [ string , any ] ) => ( {
89
+ version,
90
+ swaggerUrl : details ?. swaggerUrl || "" ,
91
+ swaggerYamlUrl : details ?. swaggerYamlUrl || "" ,
92
+ } )
93
+ ) ;
94
+
95
+ const description = info . description || "No description available" ;
96
+ const cardDescription = marked ( description ) ;
97
+ const cardDescriptionPlain = stripMarkdown ( description ) ;
98
+
99
+ return {
100
+ name : key ,
101
+ preferred : api . preferred || "" ,
102
+ info,
103
+ api : {
104
+ swaggerUrl : preferredVersion . swaggerUrl || "" ,
105
+ swaggerYamlUrl : preferredVersion . swaggerYamlUrl || "" ,
106
+ } ,
107
+ logo,
108
+ externalUrl,
109
+ origUrl,
110
+ versions : versionsArray ,
111
+ cardDescription,
112
+ cardDescriptionPlain,
113
+ categories,
114
+ tags,
115
+ integrations : api . integrations || [ ] ,
116
+ updated : preferredVersion . updated || "" ,
117
+ } ;
118
+ } catch ( error ) {
119
+ console . error ( `Error processing API ${ key } :` , error ) ;
120
+ return null ;
121
+ }
122
+ }
123
+
119
124
export async function generateStaticParams ( ) {
120
125
const apiList = list as Record < string , any > ;
121
126
const params : { providerSlug : string ; serviceSlug : string } [ ] = [ ] ;
@@ -213,10 +218,7 @@ export default async function ApiPage({
213
218
214
219
return (
215
220
< div className = "container mx-auto p-6 max-w-4xl" >
216
- < VisitCounter
217
- providerSlug = { providerSlug }
218
- serviceSlug = { serviceSlug }
219
- />
221
+ < VisitCounter providerSlug = { providerSlug } serviceSlug = { serviceSlug } />
220
222
221
223
< div className = "flex flex-col md:flex-row gap-6 mb-8" >
222
224
< div className = "flex-shrink-0" >
0 commit comments