Skip to content

Commit 1bee7be

Browse files
authored
Properly document Registry integrations (#494)
Signed-off-by: Juan Cruz Viotti <[email protected]>
1 parent 1d3abe8 commit 1bee7be

File tree

4 files changed

+144
-5
lines changed

4 files changed

+144
-5
lines changed

docs/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ hide:
33
- navigation
44
---
55

6-
# Configuration Reference
6+
# Configuration
77

88
The Sourcemeta Registry is designed around a GitOps workflow: all of its
99
behavior is determined by the configuration file documented here, and runtime

docs/getting-started.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,14 @@ Congratulations! You've just built your first Sourcemeta Registry in under two
123123
minutes (told you so!). Whilst our single-schema registry might seem modest,
124124
you've got the perfect foundation to experiment and expand.
125125

126-
Ready to take things further? We recommend exploring the full range of options
127-
in the Registry [configuration file](configuration.md), discovering how to
128-
import ready-made schema collections through our [built-in schema
129-
library](library.md), exploring the [HTTP API](api.md), and having a peek at
126+
Ready to take things further? Take a look at our
127+
[integrations](integrations.md) which cover ways on which you can pull and use
128+
the schemas in a growing amount of programming languages and applications.
129+
130+
We also recommend exploring the full range of options in the Registry
131+
[configuration file](configuration.md), discovering how to import ready-made
132+
schema collections through our [built-in schema library](library.md), exploring
133+
the [HTTP API](api.md), and having a peek at
130134
[schemas.sourcemeta.com](https://schemas.sourcemeta.com) to see what a
131135
fully-fledged public instance looks like in the wild.
132136

docs/integrations.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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

mkdocs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ nav:
2525
- index.md
2626
- getting-started.md
2727
- configuration.md
28+
- integrations.md
2829
- library.md
2930
- api.md
3031
- commercial.md
@@ -54,10 +55,12 @@ theme:
5455
icon:
5556
repo: fontawesome/brands/github
5657
features:
58+
- navigation.expand
5759
- navigation.tabs
5860
- navigation.path
5961
- navigation.top
6062
- navigation.footer
63+
- navigation.sections
6164
- search.share
6265
- content.action.edit
6366
- content.code.copy

0 commit comments

Comments
 (0)