Created
February 27, 2020 01:54
-
-
Save nupamore/ff7ce22cead927bed3a6af2e8863c711 to your computer and use it in GitHub Desktop.
Swagger HTML to JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 1. Go to Swagger API html page | |
* 2. Click block | |
* 3. Copy and paste this code at develop console | |
*/ | |
// parse | |
[...document.querySelectorAll('.opblock-summary')] | |
.map(el => { | |
const [_, ...comment] = el.textContent.split(' ') | |
const [method, ...uri] = _.split('/') | |
return [method, uri.join('/'), comment.join(' ')] | |
}) | |
//render | |
.reduce((p, [method, uri, comment], index) => { | |
p += `// ${comment}\n` | |
p += `${index}: ['${method}', '/${uri}'],\n` | |
return p | |
}, '{\n') + '}' | |
/* | |
{ | |
// comment | |
0: ['METHOD', /uri] | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment