|
| 1 | +--- |
| 2 | +hide: |
| 3 | + - navigation |
| 4 | +--- |
| 5 | + |
| 6 | +# Integrations |
| 7 | + |
| 8 | +We aim for the Sourcemeta Registry to seamlessly integrate with as many |
| 9 | +applications and ecosystems as possible. Its [HTTP API](api.md) provides a |
| 10 | +robust foundation for custom integrations, and we are always eager to hear more |
| 11 | +about use cases that demand a more direct integration. If you have any ideas, |
| 12 | +please reach out on [GitHub |
| 13 | +Discussions](https://github.com/sourcemeta/registry/discussions)! |
| 14 | + |
| 15 | +## Languages |
| 16 | + |
| 17 | +### Deno |
| 18 | + |
| 19 | +The Sourcemeta Registry supports [Deno HTTPS |
| 20 | +imports](https://docs.deno.com/runtime/fundamentals/modules/#https-imports), |
| 21 | +allowing you to directly import schema definitions (along with their |
| 22 | +dependencies, if any) into your programs. |
| 23 | + |
| 24 | +!!! success "Zero-Config Dependency Resolution" |
| 25 | + |
| 26 | + Forget about manually managing schema dependencies! The Registry |
| 27 | + intelligently detects Deno `import` requests and automatically serves |
| 28 | + [bundled |
| 29 | + schemas](https://json-schema.org/blog/posts/bundling-json-schema-compound-documents) |
| 30 | + with all `$ref` dependencies pre-resolved. What used to require complex |
| 31 | + dependency management now happens seamlessly behind the scenes. |
| 32 | + |
| 33 | +To pull a JSON Schema into a Deno program, using a JSON `import` pointing to |
| 34 | +the schema URL. In this case, replace `registry.example.com` with your Registry |
| 35 | +URL and `my/schema.json` with the path to the schema you want to import. |
| 36 | + |
| 37 | +```javascript title="main.js" |
| 38 | +import schema from "https://registry.example.com/my/schema.json" with { type: "json" }; |
| 39 | +console.log(schema); |
| 40 | +``` |
| 41 | + |
| 42 | +Then, run the program using the |
| 43 | +[`--allow-import`](https://docs.deno.com/runtime/fundamentals/security/#importing-from-the-web) |
| 44 | +permission. |
| 45 | + |
| 46 | +```sh |
| 47 | +deno run --allow-import main.js |
| 48 | +``` |
| 49 | + |
| 50 | +Deno will download and cache the schema on the first run. To force Deno to |
| 51 | +query the Registry again, use the |
| 52 | +[`--reload`](https://docs.deno.com/runtime/fundamentals/modules/#reloading-modules) |
| 53 | +option: |
| 54 | + |
| 55 | +```sh |
| 56 | +deno run --allow-import --reload main.js |
| 57 | +``` |
| 58 | + |
| 59 | +## Specifications |
| 60 | + |
| 61 | +### OpenAPI |
| 62 | + |
| 63 | +OpenAPI specifications may directly reference schemas from the Registry using |
| 64 | +the `$ref` keyword. For example: |
| 65 | + |
| 66 | +```yaml title="openapi.yaml" hl_lines="12 19" |
| 67 | +openapi: 3.1.0 |
| 68 | +info: |
| 69 | + title: My API |
| 70 | + version: 1.0.0 |
| 71 | +paths: |
| 72 | + /users: |
| 73 | + post: |
| 74 | + requestBody: |
| 75 | + content: |
| 76 | + application/json: |
| 77 | + schema: |
| 78 | + $ref: "https://registry.example.com/schemas/user.json" |
| 79 | + responses: |
| 80 | + '201': |
| 81 | + description: User created |
| 82 | + content: |
| 83 | + application/json: |
| 84 | + schema: |
| 85 | + $ref: "https://registry.example.com/schemas/user.json" |
| 86 | +``` |
| 87 | +
|
| 88 | +On distribution, you should bundle the OpenAPI specification to automatically |
| 89 | +fetch and embed external schema references. This is how you can do it using the |
| 90 | +popular [Redocly CLI](https://redocly.com/docs/cli/commands/bundle): |
| 91 | +
|
| 92 | +```sh |
| 93 | +redocly bundle path/to/openapi.yaml |
| 94 | +``` |
| 95 | + |
| 96 | +!!! tip |
| 97 | + |
| 98 | + This is a powerful strategy to have a growing amount of APIs defined using |
| 99 | + a single source of truth of data definitions. Bundling allows you get a |
| 100 | + self-contained OpenAPI specification for distribution that won't require |
| 101 | + further network requests to resolve, whilst allowing you to maintain clean |
| 102 | + separation between your API definitions and reusable schemas during |
| 103 | + development. |
| 104 | + |
| 105 | +## Editors |
| 106 | + |
| 107 | +### Visual Studio Code |
| 108 | + |
| 109 | +The Sourcemeta Registry offers improved Visual Studio Code schema |
| 110 | +auto-completion support. It does this by automatically serving the editor with |
| 111 | +transformed schemas (without loss of semantics) that aim to workaround its |
| 112 | +[significant compliance |
| 113 | +issues](https://bowtie.report/#/implementations/ts-vscode-json-languageservice) |
| 114 | +that prevent many schemas from working correctly. |
| 115 | + |
| 116 | +The key limitations that the Registry aims to workaround include: |
| 117 | + |
| 118 | +- Missing support for `$id` (and its older `id` counter-part). This affects |
| 119 | + auto-completion of bundled or complex schemas. See |
| 120 | + [`microsoft/vscode-json-languageservice#224`](https://github.com/microsoft/vscode-json-languageservice/issues/224) |
| 121 | + |
| 122 | +- Missing support for `$dynamicRef`. This affects meta-schema auto-completion. |
| 123 | + See |
| 124 | + [`microsoft/vscode-json-languageservice#149`](https://github.com/microsoft/vscode-json-languageservice/issues/149) |
| 125 | + |
| 126 | +!!! note |
| 127 | + |
| 128 | + Whilst this compatibility layer significantly improves Visual Studio Code |
| 129 | + auto-completion support, some advanced schema features may still not work |
| 130 | + due to fundamental limitations in their implementation. The ultimate |
| 131 | + solution is fixing the editor's compliance, which is of course outside of |
| 132 | + our control |
0 commit comments