Skip to content

Instantly share code, notes, and snippets.

@nupamore
Created February 27, 2020 01:54
Show Gist options
  • Save nupamore/ff7ce22cead927bed3a6af2e8863c711 to your computer and use it in GitHub Desktop.
Save nupamore/ff7ce22cead927bed3a6af2e8863c711 to your computer and use it in GitHub Desktop.
Swagger HTML to JSON
/**
* 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