Skip to content

Commit 1207d7b

Browse files
authored
Merge branch 'main' into feat/respect-core-tree-shaking
2 parents fc95a7d + 1263840 commit 1207d7b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1439
-124
lines changed

.changeset/itchy-kiwis-notice.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@redocly/openapi-core": minor
3+
"@redocly/cli": minor
4+
---
5+
6+
Implemented basic support for OpenRPC specification.

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
README.md @Redocly/dark-side
55
README.md @Redocly/technical-writers
66
docs/ @Redocly/technical-writers
7+
packages/cli/src/utils/otel.ts @Redocly/hot-dogs
8+
packages/cli/src/utils/telemetry.ts @Redocly/hot-dogs

docs/@v2/commands/lint.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Introduction
44

5-
Redocly CLI can identify and report on problems found in OpenAPI, AsyncAPI, or Arazzo descriptions.
5+
Redocly CLI can identify and report on problems found in OpenAPI, AsyncAPI, Arazzo, or Open-RPC descriptions.
66
This helps you avoid bugs and make API or Arazzo descriptions more consistent.
77

88
The `lint` command reports on problems and executes preprocessors and rules.
@@ -50,7 +50,7 @@ The `lint` command behaves differently depending on how you pass the API(s) to i
5050
redocly lint openapi/openapi.yaml
5151
```
5252

53-
In this case, `lint` validates the API or Arazzo description(s) passed to the command.
53+
In this case, `lint` validates the API, Arazzo, or Open-RPC description(s) passed to the command.
5454
If you have no configuration file defined, the [recommended ruleset](../rules/recommended.md) is used.
5555
If you have `extends` or `rules` defined in `redocly.yaml`, those are used when linting.
5656

@@ -432,3 +432,10 @@ The `lint` command also validates [The Arazzo](https://spec.openapis.org/arazzo/
432432
You can pass the Arazzo description file to the `lint` command as shown below:
433433

434434
`redocly lint arazzo.yaml`
435+
436+
### Lint Open-RPC description file
437+
438+
The `lint` command also validates [Open-RPC](https://spec.open-rpc.org/) description files.
439+
You can pass the Open-RPC description file to the `lint` command as shown below:
440+
441+
`redocly lint open-rpc.json`

docs/@v2/guides/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ API governance for async and streaming API applications.
6161
Check the validity of Arazzo descriptions for workflows.
6262
{% /card %}
6363

64+
{% card title="Lint Open-RPC descriptions"
65+
to="./lint-openrpc"
66+
%}
67+
Check the validity of Open-RPC descriptions.
68+
{% /card %}
69+
6470
{% card title="Change the OAuth2 token URL"
6571
to="./change-token-url"
6672
%}

docs/@v2/guides/lint-openrpc.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
seo:
3+
title: Lint Open-RPC with Redocly CLI
4+
description: Use the Redocly CLI to enforce basic validation, configure rules, or even build custom plugins for Open-RPC.
5+
---
6+
7+
# Lint Open-RPC with Redocly CLI
8+
9+
{% admonition type="info" name="Experimental Open-RPC support" %}
10+
This feature is at an early stage, please use with caution and send us lots of feedback!
11+
{% /admonition %}
12+
13+
In addition to providing lint functionality for multiple OpenAPI formats, Redocly CLI also has support for Open-RPC.
14+
Redocly CLI supports the following linting approaches with Open-RPC documents:
15+
16+
- Open-RPC document validation.
17+
- Supported versions:
18+
- [Open-RPC 1.x](https://spec.open-rpc.org/)
19+
- Built-in rules for checking common standards requirements (see the [list of Open-RPC rules](#open-rpc-rules)).
20+
- [Configurable rules](../rules/configurable-rules.md) so that you can build your own rules following common patterns
21+
- [Custom plugins](../custom-plugins/index.md) for advanced users that need additional functionality
22+
23+
## Lint an existing Open-RPC file
24+
25+
Redocly CLI takes its settings from a `redocly.yaml` configuration file.
26+
Below is an example of a simple configuration file for validating an Open-RPC file is in the expected format:
27+
28+
```yaml
29+
rules:
30+
struct: error
31+
```
32+
33+
The empty `extends` element instructs Redocly CLI not to use any existing rulesets, but to display an error if the `struct` rule finds any problem.
34+
This rule checks that the document structure matches the Open-RPC specification.
35+
36+
With this configuration file, and your Open-RPC description file, run the linting command:
37+
38+
```sh
39+
redocly lint open-rpc.json
40+
```
41+
42+
The output describes any structural problems with the document, or reports that it is valid.
43+
44+
## Open-RPC rules
45+
46+
To expand the linting checks for an Open-RPC description, start by enabling some of the built-in rules.
47+
The currently supported rules are:
48+
49+
- `no-unresolved-refs`: Every `$ref` must exist.
50+
- `no-unused-components`: All components must be used.
51+
- `spec-no-duplicated-method-params`: The list of parameters must not include duplicated parameters.
52+
- `spec-no-required-params-after-optional`: Required parameters must be positioned before optional parameters.
53+
- `info-contact`: Contact section is defined under `info`.
54+
- `info-license`: License section is defined under `info`.
55+
56+
We expect the list to expand over time, so keep checking back - and let us know if you have any requests by [opening an issue on the GitHub repo](https://github.com/Redocly/redocly-cli/issues).
57+
58+
To use a rule in your own linting setup, add the rule name to the `rules` configuration section, and declare the severity level (either `error`, `warn` or `off`).
59+
Here's an example of a rules block where a missing contact section causes a warning, and a tag without a description triggers an error:
60+
61+
```yaml
62+
rules:
63+
info-contact: warn
64+
info-license: error
65+
```
66+
67+
Pick and mix the available rules until you have the setup that fits your situation.
68+
69+
## Configurable rule example
70+
71+
Redocly CLI also offers [configurable rules](../rules/configurable-rules.md) that allow you to set assertions about the API description being linted. This functionality works for Open-RPC too.
72+
The following example shows a configurable rule that displays a warning if the `title` field is not present in the `info` block:
73+
74+
```yaml
75+
rules:
76+
rule/info-title:
77+
subject:
78+
type: Info
79+
property: title
80+
assertions:
81+
defined: true
82+
severity: warn
83+
```
84+
85+
With the extensive configurable rules options available, there are many opportunities to make sure that your Open-RPC spec conforms with expectations. We'd also love to see what you're building - it helps us know how things are going!
86+
87+
{% admonition type="info" name="Custom plugins" %}
88+
To create your own plugins, see the [custom plugins documentation](../custom-plugins/index.md).
89+
90+
{% /admonition %}

docs/@v2/rules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Redocly uses rules to describe all the different aspects of API behavior that we
99

1010
- **Rulesets** are groups of rules that can be applied to any API. This is a good way to build up a ruleset that you can use locally or with your CI. Multiple rulesets can be used at once, so feel free to make smaller ones and compose the rulesets that fit each API.
1111
- **Built-in rules:** for the most common use cases, the rules are already made for you, all you need to do is choose if they should cause an `error`, simply `warn` of a problem, or be turned `off`. [See the built-in rules documentation](./rules/built-in-rules.md) for more information and examples.
12-
- **Configurable rules** allow powerful describing of API standards without needing to write code. Create a configurable rule, choose which parts of the OpenAPI description it applies to, and what the criteria for success are. The linting tool does the rest. With plenty of examples, the [configurable rules](./rules/configurable-rules.md) helps you to describe your API standards easily and well.
12+
- **Configurable rules** allow powerful describing of API standards without needing to write code. Create a configurable rule, choose which parts of the API description it applies to, and what the criteria for success are. The linting tool does the rest. With plenty of examples, the [configurable rules](./rules/configurable-rules.md) helps you to describe your API standards easily and well.
1313
- **Custom code rules** if none of the above exactly fits your needs, then a [custom code plugin](./custom-plugins/index.md) is an extensible way to bring some custom JavaScript to build on Redocly's existing features.
1414

1515
## Rulesets

docs/@v2/rules/built-in-rules.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Redocly CLI can lint multiple API description formats:
2020
- [OpenAPI](#openapi-rules)
2121
- [AsyncAPI](#asyncapi-rules)
2222
- [Arazzo](#arazzo-rules)
23+
- [Open-RPC](#open-rpc-rules)
2324
- Overlay
2425

2526
Visit each page for details of what the rule does, additional configuration options, and examples of it in use.
@@ -148,6 +149,18 @@ The below rules are being migrated to Respect:
148149
- [x-security-scheme-name-reference](./respect/x-security-scheme-name-reference.md): when multiple `sourceDescriptions` exist, `workflow.x-security.schemeName` must reference a source description (for example, `$sourceDescriptions.{name}.schemeName`)
149150
- [x-security-scheme-required-values](./respect/x-security-scheme-required-values.md) validate that `x-security` have all required `values` described according to the used `scheme`.
150151

152+
## Open-RPC rules
153+
154+
Use the rules in this section for Open-RPC specific linting.
155+
156+
- [struct](./common/struct.md): Conform to the declared Open-RPC specification version
157+
- [no-unresolved-refs](./common/no-unresolved-refs.md): Every `$ref` must exist
158+
- [no-unused-components](./oas/no-unused-components.md): All components must be used
159+
- `spec-no-duplicated-method-params`: The list of parameters must not include duplicated parameters
160+
- `spec-no-required-params-after-optional`: Required parameters must be positioned before optional parameters
161+
- [info-contact](./oas/info-contact.md): Contact section is defined under `info`
162+
- [info-license](./oas/info-license.md): License section is defined under `info`
163+
151164
## Resources
152165

153166
- Learn more about [API linting](../api-standards.md), or follow the [guide to configuring a ruleset](../guides/configure-rules.md).

packages/cli/src/__tests__/fixtures/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const configFixture: Config = {
2525
async3: {},
2626
arazzo1: {},
2727
overlay1: {},
28+
openrpc1: {},
2829
},
2930
preprocessors: {
3031
oas2: {},
@@ -35,6 +36,7 @@ export const configFixture: Config = {
3536
async3: {},
3637
arazzo1: {},
3738
overlay1: {},
39+
openrpc1: {},
3840
},
3941
plugins: [],
4042
doNotResolveExamples: false,
@@ -47,6 +49,7 @@ export const configFixture: Config = {
4749
async3: {},
4850
arazzo1: {},
4951
overlay1: {},
52+
openrpc1: {},
5053
},
5154
resolveIgnore: vi.fn(),
5255
addProblemToIgnore: vi.fn(),

packages/cli/src/__tests__/utils.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ describe('checkIfRulesetExist', () => {
546546
async3: {},
547547
arazzo1: {},
548548
overlay1: {},
549+
openrpc1: {},
549550
};
550551
expect(() => checkIfRulesetExist(rules)).toThrowError(
551552
'⚠️ No rules were configured. Learn how to configure rules: https://redocly.com/docs/cli/rules/'
@@ -562,6 +563,7 @@ describe('checkIfRulesetExist', () => {
562563
async3: {},
563564
arazzo1: {},
564565
overlay1: {},
566+
openrpc1: {},
565567
};
566568
checkIfRulesetExist(rules);
567569
});

0 commit comments

Comments
 (0)