Skip to content

Commit bc33a6a

Browse files
committed
Update Token API JSON from staging + implement new URL structure
1 parent 66419a2 commit bc33a6a

File tree

1,478 files changed

+10448
-8666
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,478 files changed

+10448
-8666
lines changed

website/src/openApi/index.ts

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,34 @@ export const API_IDS = ['tokenApi'] as const
99
export const APIS = {
1010
tokenApi: {
1111
name: 'Token API',
12-
url: 'https://token-api.thegraph.com/openapi', // production
13-
// url: 'https://token-api.service.stage.pinax.network/openapi', // staging
12+
// url: 'https://token-api.thegraph.com/openapi', // production
13+
url: 'https://token-api.service.stage.pinax.network/openapi', // staging
1414
document: tokenApi as OpenAPIV3_1.Document,
1515
sections: {
16-
EVM: '/token-api/evm',
17-
SVM: '/token-api/svm',
18-
Monitoring: '/token-api/monitoring',
16+
'EVM Tokens': {
17+
path: '/token-api/v1/evm-tokens',
18+
operationIdPrefixes: ['getV1Evm'],
19+
},
20+
'EVM DEXs': {
21+
path: '/token-api/v1/evm-dexs',
22+
operationIdPrefixes: ['getV1Evm'],
23+
},
24+
'EVM NFTs': {
25+
path: '/token-api/v1/evm-nfts',
26+
operationIdPrefixes: ['getV1EvmNft'],
27+
},
28+
'SVM Tokens': {
29+
path: '/token-api/v1/svm-tokens',
30+
operationIdPrefixes: ['getV1Svm'],
31+
},
32+
'SVM DEXs': {
33+
path: '/token-api/v1/svm-dexs',
34+
operationIdPrefixes: ['getV1Svm'],
35+
},
36+
Monitoring: {
37+
path: '/token-api/v1/monitoring',
38+
operationIdPrefixes: ['getV1'],
39+
},
1940
},
2041
},
2142
} satisfies Record<ApiId, ApiConfig>
@@ -26,7 +47,12 @@ export type ApiConfig = {
2647
name: string
2748
url: string
2849
document: OpenAPIV3_1.Document
29-
sections: Record<string, string>
50+
sections: Record<string, ApiSectionConfig>
51+
}
52+
53+
export type ApiSectionConfig = {
54+
path: string
55+
operationIdPrefixes?: string[]
3056
}
3157

3258
export type ApiSection = {
@@ -119,14 +145,15 @@ export function getApi(apiId: ApiId, passedDocument?: OpenAPIV3_1.Document): Api
119145
const sectionName = documentOperation.tags.find((tag) => tag in config.sections) as
120146
| keyof typeof config.sections
121147
| undefined
122-
const sectionPath = sectionName ? config.sections[sectionName] : undefined
123-
if (!sectionName || !sectionPath || !('operationId' in documentOperation) || !documentOperation.operationId) {
148+
const section = sectionName ? config.sections[sectionName] : undefined
149+
if (!sectionName || !section || !('operationId' in documentOperation) || !documentOperation.operationId) {
124150
continue
125151
}
152+
const operationId = documentOperation.operationId
126153
if (!sections[sectionName]) {
127154
sections[sectionName] = {
128155
name: sectionName,
129-
path: sectionPath,
156+
path: section.path,
130157
operations: [],
131158
}
132159
}
@@ -174,10 +201,19 @@ export function getApi(apiId: ApiId, passedDocument?: OpenAPIV3_1.Document): Api
174201
})
175202
}
176203

204+
const longestOperationIdPrefixThatMatches = (section.operationIdPrefixes ?? [])
205+
.filter((prefix) => operationId.startsWith(prefix))
206+
.sort((a, b) => b.length - a.length)[0]
207+
const slug = camelToKebab(
208+
longestOperationIdPrefixThatMatches
209+
? operationId.slice(longestOperationIdPrefixThatMatches.length)
210+
: operationId,
211+
)
212+
177213
const operation: ApiOperation = {
178214
...documentOperation,
179-
operationId: documentOperation.operationId,
180-
slug: camelToKebab(documentOperation.operationId),
215+
operationId,
216+
slug,
181217
method: method.toUpperCase(),
182218
baseUrl,
183219
path,

0 commit comments

Comments
 (0)