REST API schema for Postman & more
Posted: Mon Sep 11, 2023 6:20 am
While not "scripting", I had a JavaScript implementation that using /system/console via REST to generate a RAML 1.0 scheme. I just hadn't written it up here, so here it is.
It isn't exactly 100%, perhaps 90%. e.g.
- especially the arguments – and like ChatGPT – it may make a few — but most should work, especially POST ones.
- in most cases, it it's NOT picky on types – most are marked an "any".
- there BUGS in /console/inspect using request=syntax – some crash so not a lot of "syntax" data is used
- has all packages, except calea
- return attributes are "inexact" – it just marked as "any" JSON
- arguments are generally list (perhaps not in all cases), but again types are "any"
- since it's automatically generated, there are no "examples" or "documentation" in schema – just endpoints and args
- GET is not fully specified for root commands (GET /ip/address) – it should show query params and array output
- some postman-defaults could be better, but unsure how to control via RAML...
- likely others...
Anyway still good start to a more formalized schema. While not directly OpenAPI/swagger, the RAML imports into postman just fine.
RAML Schema for Download
The generated RAML schema for import (~6MB, 250K lines of YAML) can be download from:
https://tikoci.github.io/restraml
Check the website for new ones.
Newer version are on the GitHub project but orginal files from time of this posting remain:
7.12 - https://tikoci.github.io/restraml/routeros.raml
7.13 - https://tikoci.github.io/restraml/routeros.7.13.raml
Using Postman... (and other HTTP tools)
For use in Postman
1. Go to API section
2. Click "Import" button on near top of API section
3. Upload the RAML file from above:
4. Click "View import setting", selecting "Schema" – NOT the default "example" — as source for postman request/response data:
5. Hit back icon in upper left, then click "Import"
6. Wait... (postman shows progress in status bar)
7. Go to "Collections" section on left side of Postman, and notice the new RouterOS one
8. Using postman is more up-to-you... at least the following need to be added by user for it call REST API on a RouterOS device:
- "Basic Auth" should be set either on collection (or elsewhere)
- {{baseUrl}} needs to be set to your router's IP using the environment variables in postman
Converting RAML to OpenAPI / swagger formats
This web site seem to take a RAML schema, and get then an OpenAPI schema from it:
https://mulesoft.github.io/oas-raml-converter/
which gets an OpenAPI formatted scheme from RAML.
Generated OpenAPI Schema
https://tikoci.github.io/restraml/route ... napi3.json
Although I didn't test it much, it does seems to load in Postman at least.
I'm sure there other CLI tools to do same, but RAML is support by postman which was concern.
JavaScript to generate RAML
Mainly for reference. It takes ~30 minutes, to make 30K+ REST calls, on beefy MacBook.... JS source code is in a GitHub project:
https://github.com/tikoci/restraml
Not the pretty code, but works. I'll leave containering for it for another day
Note: I would have used RouterOS script, but the 4K chucks of 6MBs didn't sound fun – but yes a RSC script, or a container, theoretically work here too. Just JS was easier/quicker since I'd done most of it a while back.
Postman in VSCode with RouterOS REST...
Using the VSCode extension for Postman also works, once the schema has been loaded:
Including postman's code generation from REST schema:
edits:
- added TODO
- fixed references to use GH project instead of a git for RAML schema download
- add screenshot of VSCode with postman plugin
- updated URL to generate OpenAPI schema
- updated to reference GitHub project.
It isn't exactly 100%, perhaps 90%. e.g.
- especially the arguments – and like ChatGPT – it may make a few — but most should work, especially POST ones.
- in most cases, it it's NOT picky on types – most are marked an "any".
- there BUGS in /console/inspect using request=syntax – some crash so not a lot of "syntax" data is used
- has all packages, except calea
- return attributes are "inexact" – it just marked as "any" JSON
- arguments are generally list (perhaps not in all cases), but again types are "any"
- since it's automatically generated, there are no "examples" or "documentation" in schema – just endpoints and args
- GET is not fully specified for root commands (GET /ip/address) – it should show query params and array output
- some postman-defaults could be better, but unsure how to control via RAML...
- likely others...
Anyway still good start to a more formalized schema. While not directly OpenAPI/swagger, the RAML imports into postman just fine.
RAML Schema for Download
The generated RAML schema for import (~6MB, 250K lines of YAML) can be download from:
https://tikoci.github.io/restraml
Check the website for new ones.
Newer version are on the GitHub project but orginal files from time of this posting remain:
7.12 - https://tikoci.github.io/restraml/routeros.raml
7.13 - https://tikoci.github.io/restraml/routeros.7.13.raml
Using Postman... (and other HTTP tools)
For use in Postman
1. Go to API section
2. Click "Import" button on near top of API section
3. Upload the RAML file from above:
4. Click "View import setting", selecting "Schema" – NOT the default "example" — as source for postman request/response data:
5. Hit back icon in upper left, then click "Import"
6. Wait... (postman shows progress in status bar)
7. Go to "Collections" section on left side of Postman, and notice the new RouterOS one
8. Using postman is more up-to-you... at least the following need to be added by user for it call REST API on a RouterOS device:
- "Basic Auth" should be set either on collection (or elsewhere)
- {{baseUrl}} needs to be set to your router's IP using the environment variables in postman
Converting RAML to OpenAPI / swagger formats
This web site seem to take a RAML schema, and get then an OpenAPI schema from it:
https://mulesoft.github.io/oas-raml-converter/
which gets an OpenAPI formatted scheme from RAML.
Generated OpenAPI Schema
https://tikoci.github.io/restraml/route ... napi3.json
Although I didn't test it much, it does seems to load in Postman at least.
I'm sure there other CLI tools to do same, but RAML is support by postman which was concern.
JavaScript to generate RAML
Mainly for reference. It takes ~30 minutes, to make 30K+ REST calls, on beefy MacBook.... JS source code is in a GitHub project:
https://github.com/tikoci/restraml
Not the pretty code, but works. I'll leave containering for it for another day
Note: I would have used RouterOS script, but the 4K chucks of 6MBs didn't sound fun – but yes a RSC script, or a container, theoretically work here too. Just JS was easier/quicker since I'd done most of it a while back.
Postman in VSCode with RouterOS REST...
Using the VSCode extension for Postman also works, once the schema has been loaded:
Including postman's code generation from REST schema:
edits:
- added TODO
- fixed references to use GH project instead of a git for RAML schema download
- add screenshot of VSCode with postman plugin
- updated URL to generate OpenAPI schema
- updated to reference GitHub project.