|
1 |
| -# docs-openapi-specs |
| 1 | +# Alchemy Docs |
2 | 2 |
|
3 |
| -OpenAPI Specs for methods on docs |
| 3 | +Hey there - thanks for checking our API docs! 👋 |
4 | 4 |
|
5 |
| -## Installation |
| 5 | +This repo holds the OpenAPI specs that power our API Playgrounds at [docs.alchemy.com/reference](https://docs.alchemy.com/reference) ("Try it" sections on the right). |
6 | 6 |
|
7 |
| -Get the `rdme` dev dependency |
| 7 | +## Getting started |
8 | 8 |
|
| 9 | +1. Clone the repo. |
| 10 | + |
| 11 | +```bash |
| 12 | +git clone https://github.com/alchemyplatform/docs-openapi-specs |
9 | 13 | ```
|
10 |
| -npm install |
| 14 | + |
| 15 | +2. Install dev dependencies. |
| 16 | + |
| 17 | +```bash |
| 18 | +npm i |
11 | 19 | ```
|
12 | 20 |
|
13 |
| -Run `rdme` commands by prefixing commands with `npx` to use the installed version |
| 21 | +## Frens |
| 22 | + |
| 23 | +Feedback? Issues? Typos? |
| 24 | + |
| 25 | +We are continously trying to improve our docs - any help is very welcomed! 😀 |
| 26 | + |
| 27 | +You can: |
| 28 | + |
| 29 | +- suggest edits (top right of [Tutorials](https://docs.alchemy.com/docs) pages) |
| 30 | +- share feedback using 'Did this page help you? sections (bottom of [Tutorials](https://docs.alchemy.com/docs) / [API Reference](https://docs.alchemy.com/reference/api-overview) pages) |
| 31 | +- open issues [here](https://github.com/alchemyplatform/docs-openapi-specs/issues/new) |
| 32 | + |
| 33 | +If you're feeling adventurous, feel free to open a pull request [here](https://github.com/alchemyplatform/docs-openapi-specs/compare). |
| 34 | + |
| 35 | +> You currently can only modify API playgrounds. For pages or markdown edits in API Reference, please use one of the above options. |
| 36 | +
|
| 37 | +# WIP 👷♀️ |
| 38 | + |
| 39 | +> Below section is WIP. |
| 40 | +> Until we add ids to every spec, deploy specs as you normally would. |
| 41 | +
|
| 42 | +## Alchemists 👩🔬 |
| 43 | + |
| 44 | +To speed up your development, 2 commands are now available. |
| 45 | + |
| 46 | +- `npm run create spec.yaml` |
| 47 | +- `npm run update spec.yaml` |
| 48 | + |
| 49 | +You no longer need to run the `rdme` command line directly to push to staging. |
| 50 | +You also no longer need to pass an API key and readme id! 🎉 |
14 | 51 |
|
| 52 | +### First time? |
| 53 | + |
| 54 | +> Make sure you first ran through the steps [above](#getting-started). |
| 55 | +
|
| 56 | +1. Clone `.env.template` into `.env`. |
| 57 | + |
| 58 | +```bash |
| 59 | +cp .env.template .env |
15 | 60 | ```
|
16 |
| -npx rdme <command> |
| 61 | + |
| 62 | +2. Grab Readme API key. |
| 63 | + |
| 64 | +3. Update `RDME_API_KEY` in `.env`. |
| 65 | + |
| 66 | +### Creating new spec |
| 67 | + |
| 68 | +> Known issue: will remove comments and format spec when run. |
| 69 | +
|
| 70 | +1. Write your spec (e.g. `newspec.yaml`). |
| 71 | + |
| 72 | +2. Run `create` script passing the path to your spec. |
| 73 | + |
| 74 | +```bash |
| 75 | + npm run create transact/newspec.yaml |
17 | 76 | ```
|
| 77 | + |
| 78 | +This will: |
| 79 | + |
| 80 | +- deploy your spec to readme |
| 81 | +- create a page and id |
| 82 | +- associate page id with your spec |
| 83 | + |
| 84 | +3. Your spec will be updated with a `x-readme.id` field. This is super important to ensure updates work smoothly in the future! |
| 85 | + |
| 86 | +### Updating spec |
| 87 | + |
| 88 | +Run `update` script. Ensure `x-readme.id` is set. |
| 89 | + |
| 90 | +```bash |
| 91 | +npm run update spec.yml |
| 92 | +``` |
| 93 | + |
| 94 | +### Troubleshooting |
| 95 | + |
| 96 | +1. Check `RDME_API_KEY` is set in `.env`. |
| 97 | +2. Check you provided a valid path to a `.yaml` file when running the scripts. |
| 98 | + |
| 99 | +```bash |
| 100 | +npm run create spec.yaml |
| 101 | +npm run update spec.yaml |
| 102 | +``` |
| 103 | + |
| 104 | +3. Check the spec has a `x-readme.id` property. This id is used to match the spec on Readme's side. |
| 105 | +4. Reach out to Bastien if you have any issues running the scripts. |
| 106 | + |
| 107 | +## Linting |
| 108 | + |
| 109 | +Linting is ran automatically when using `npm run create` and `npm run update` (powered by [Spectral](https://github.com/stoplightio/spectral)). |
| 110 | + |
| 111 | +You can run it manually using |
| 112 | + |
| 113 | +```bash |
| 114 | +npx spectral lint spec.yaml |
| 115 | +``` |
| 116 | + |
| 117 | +Rules we currently adhere - [here](.spectral.yaml). |
| 118 | + |
| 119 | +You should also install the extension for your editor. |
| 120 | + |
| 121 | +- [JetBrains Plugin](https://plugins.jetbrains.com/plugin/18520-spectral) |
| 122 | +- [VS Code Spectral Extension](https://marketplace.visualstudio.com/items?itemName=stoplight.spectral) |
| 123 | + |
| 124 | +### Quirks |
| 125 | + |
| 126 | +We currently cannot use [`oas-normalize`](https://github.com/readmeio/oas-normalize) to resolve $refs in specs. |
| 127 | + |
| 128 | +It relies on [`@readme/openapi-parser`](https://github.com/readmeio/openapi-parser) which relies on [`@readme/json-schema-ref-parser`](https://github.com/readmeio/json-schema-ref-parser). |
| 129 | + |
| 130 | +`@readme/json-schema-ref-parser` is a fork of [`@apidevtools/json-schema-ref-parser`](https://github.com/APIDevTools/json-schema-ref-parser). |
| 131 | + |
| 132 | +This is a known issue of `json-schema-ref-parser` - see [here](https://github.com/APIDevTools/json-schema-ref-parser/issues/200#issuecomment-1157687009). |
| 133 | + |
| 134 | +Until the issue gets resolved and changes get merged upstream, solution is to dereference the spec using `@openapi-generator-plus/json-schema-ref-parser`(https://www.npmjs.com/package/@openapi-generator-plus/json-schema-ref-parser). |
| 135 | + |
| 136 | +This also means validation is done prior to running scripts via Spectral rather than with `oas-normalize`. |
| 137 | + |
| 138 | +## Future improvements |
| 139 | + |
| 140 | +- Refactoring (OAS Components / Schemas, break up `nfts.yaml`, `sdk.yaml`). |
| 141 | +- More linting rules |
| 142 | +- update multiple specs at once |
| 143 | +- `create` and `update` scripts share a lot of code (can be simplified) |
| 144 | +- `create` script remove comments |
| 145 | + |
| 146 | +## Resources |
| 147 | + |
| 148 | +- [OpenAPI Specification v3.1.0](https://spec.openapis.org/oas/latest.html) |
| 149 | + |
| 150 | +- [Readme - OpenAPI Compatibility Chart](https://docs.readme.com/main/docs/openapi-compatibility-chart) |
| 151 | +- [Readme - OpenAPI Extensions](https://docs.readme.com/main/docs/openapi-extensions) |
| 152 | + |
| 153 | +- [Swagger.io - OpenAPI Guide](https://swagger.io/docs/specification/about/) |
| 154 | +- [Documenting APIs - OpenAPI tutorial](https://idratherbewriting.com/learnapidoc/pubapis_openapi_step1_openapi_object.html) |
| 155 | + |
| 156 | +- [Stoplight.io - Spectral](https://docs.stoplight.io/docs/spectral/674b27b261c3c-overview) |
| 157 | +- [JSONPath](https://goessner.net/articles/JsonPath/index.html) |
0 commit comments