We have a brand new and shiny Tyk VS Code Extension to share with you!
TL;DR
Tyk Schemas VS Code extension makes your work with Tyk in VS Code feel like writing in a native programming language with autocompletion capabilities. The extension enables you to write and validate Tyk API definition, keys and config files using VS Code’s IntelliSense so you can enjoy all of its amazing capabilities:
- Autocomplete fields
- Validates files and shows required/optional fields
- Provides default values for fields
- Offers autocomplete examples OOTB and even field descriptions so you don’t need to stop and look it up in our docs.
Tyk’s extension aims to reduce friction in your engineering work by making it faster and easier. This way, you don’t need to learn and memorise the Tyk ins and outs, can avoid the back-and-forth copy+amend code snippet from the docs, and just start using Tyk instantly with no learning curve.
Why do I need it?
When you want to write API definitions for Tyk gateway or Tyk dashboard, you need to create a JSON file with all the required fields and POST it as a payload with the endpoint that creates the API definition (/tyk/apis in Tyk Open source or /api/apis in Tyk Self managed).
This is what the minimum API definition looks like:
{ "name": "My New Api", "api_id": "mynewpi", "org_id": "default", "proxy": { "listen_path": "/myapi/", "target_url": "https://httpbin.org", "strip_listen_path": true, "preserve_host_header": true }, "version_data": { "versions": { "Default": { "name": "Default" } }, "not_versioned": true }, "active": true, "use_keyless": true }
The same goes for policies, keys, users and catalogues, and also the various config files every component is using on start up.
As you can see, writing such a file could be quite cumbersome. For example, you could search the API definition in the docs, paste it in VS Code, amend the values, search for fields that were not included in the example and add them. Another way is to GET /tyk/apis/{some-other-api} > api-myapi.json and then edit the file. This time, you’d need to read about the existing fields so you know which one you can delete and which to amend since the new API has completely different middleware configuration.
How to find and install the Tyk extension?
You can just look up “Tyk” in the extensions section of the VS Code Marketplace and click the “Install” button.
How do I use the Tyk extension?
Once the Tyk Schemas extension is installed, you are ready to start using it. The only requirement is to rename your file in the following format:
- tyk*.conf – For Tyk gateway config file
- apikey*.json – For Tyk gateway keys files/payloads
- apidef*.json, TykDefinition*.json – For Tyk API definition files/payloads
- oasapidef*.json, TykOasApiDef*.json – For Tyk OAS API definition files/payloads
As you can see in the first screenshot of this blog, when you name the file in the correct format, you’ll see a pop-up window with a suggestion to auto-complete just as it would with any programming language. If you can’t see the pop-up, click control+space.
How does the Tyk extension work under the hood?
As you probably expect, to use IntelliSense (to achieve the validation, descriptions, examples and default values), we are using JSON schemas underneath. Tyk-schemas Github repository is powering the Tyk VS Code extension and is our home for all Tyk JSON schemas (it is still a WIP, and we’ll add and publish more schema types and versions, especially as more users ask for it).
You can also find information about the extension in our official docs.
How do I publish an API in 30 seconds?
You can quickly create the API definition using the example provided via IntelliSense’s pop-up and then POST it to the Tyk OSS Gateway.
What’s next?
This project is very much in its infancy. We’d like it to be driven by real-life usage, so please do share your feedback with us if you like it and want us to continue improving and developing it.
We have two main GitHub repos for communicating with us:
- Vscode-tyk – https://github.com/TykTechnologies/vscode-tyk/issues – for bugs and features related directly to the extension. For example, if you want us to support more file formats or you found a missing description.
- Tyk-schemas – https://github.com/tykTechnologies/tyk-schemas/issues – if you feel like taking a deep dive into the schemas that are the foundation of the extension. For example, you want to add a new schema or improve an existing one with descriptions or examples.
We also welcome code contributions, in both repos and in any of Tyk open source projects.
If you want to get in touch directly, you can email us at [email protected]
And lastly, if you liked this extension, please give us a review in the VS Code marketplace.