@@ -85,7 +85,7 @@ async function main() {
85
85
86
86
// @ts -ignore
87
87
const servers = api . servers as OpenAPIV3_1 . ServerObject [ ] ;
88
- const { chains , networks } = extractChainAndNetworks ( servers [ 0 ] ) ;
88
+ const chainsToNetworks = extractChainAndNetworks ( servers [ 0 ] ) ;
89
89
90
90
const paths = api . paths ;
91
91
if ( ! paths ) throw new Error ( 'Paths not found in spec' ) ;
@@ -97,8 +97,7 @@ async function main() {
97
97
for ( const [ method , operation ] of Object . entries ( pathItem ) ) {
98
98
// console.log(method, operation);
99
99
100
- console . log ( chains , networks ) ;
101
- for ( const chain of chains ) {
100
+ for ( const [ chain , networks ] of chainsToNetworks ) {
102
101
for ( const network of networks ) {
103
102
const entry = {
104
103
fileName,
@@ -121,17 +120,15 @@ async function main() {
121
120
122
121
main ( ) ;
123
122
124
- function extractChainAndNetworks ( servers : OpenAPIV3_1 . ServerObject ) : {
125
- chains : string [ ] ;
126
- networks : string [ ] ;
127
- } {
123
+ function extractChainAndNetworks (
124
+ servers : OpenAPIV3_1 . ServerObject ,
125
+ ) : Map < string , Set < string > > {
128
126
const { url, variables } = servers ;
129
127
130
128
// if variables key exists in spec - lets get the networks
131
129
// if not let's parse the URL
132
130
133
- const chains : string [ ] = [ ] ;
134
- const networks : string [ ] = [ ] ;
131
+ const chainsToNetworks : Map < string , Set < string > > = new Map ( ) ;
135
132
136
133
if ( variables ) {
137
134
const values = variables . network . enum ?? [ ] ;
@@ -142,8 +139,13 @@ function extractChainAndNetworks(servers: OpenAPIV3_1.ServerObject): {
142
139
}
143
140
const chain = parts [ 0 ] ;
144
141
const network = parts [ 1 ] ;
145
- chains . push ( chain ) ;
146
- networks . push ( network ) ;
142
+
143
+ const networks = chainsToNetworks . get ( chain ) ;
144
+ if ( networks ) {
145
+ chainsToNetworks . set ( chain , networks . add ( network ) ) ;
146
+ } else {
147
+ chainsToNetworks . set ( chain , new Set ( [ network ] ) ) ;
148
+ }
147
149
}
148
150
} else {
149
151
const subdomain = extractSubdomain ( url ) ;
@@ -156,10 +158,15 @@ function extractChainAndNetworks(servers: OpenAPIV3_1.ServerObject): {
156
158
}
157
159
const chain = parts [ 0 ] ;
158
160
const network = parts [ 1 ] ;
159
- chains . push ( chain ) ;
160
- networks . push ( network ) ;
161
+
162
+ const networks = chainsToNetworks . get ( chain ) ;
163
+ if ( networks ) {
164
+ chainsToNetworks . set ( chain , networks . add ( network ) ) ;
165
+ } else {
166
+ chainsToNetworks . set ( chain , new Set ( [ network ] ) ) ;
167
+ }
161
168
}
162
- return { chains , networks } ;
169
+ return chainsToNetworks ;
163
170
}
164
171
165
172
function extractSubdomain ( url : string ) : string | null {
0 commit comments