Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support JSON-schema assertion in configurable rules #1886

Open
RomanHotsiy opened this issue Feb 6, 2025 · 7 comments
Open

Support JSON-schema assertion in configurable rules #1886

RomanHotsiy opened this issue Feb 6, 2025 · 7 comments

Comments

@RomanHotsiy
Copy link
Member

RomanHotsiy commented Feb 6, 2025

Is your feature request related to a problem? Please describe.

Some people maintain JSON schemas to validate some parts of OpenAPI. We don't have a way to use them.

Describe the solution you'd like

I would like to add support for json schema assertion for our configurable rules. It may look like this:

rule/info-metadata-check:
  subject:
    type: Info
    property: x-metadata
  message: Metadata should match the schema.
  assertions:
    json-schema:
      $ref: ./metadata-schema.json

Describe alternatives you've considered

Right now it is possible to achieve using custom assertions/rules via plugin: https://redocly.com/docs/cli/rules/configurable-rules#custom-function-example

Additional context

Reported in Write the Docs slack: https://writethedocs.slack.com/archives/C4EPE8332/p1738793608940479

@tatomyr
Copy link
Contributor

tatomyr commented Feb 7, 2025

@RomanHotsiy from the context of the attached conversation I understand it's more about linting standalone JSON schemas themselves rather than linting OAS using JSON schemas, isn't it?

@hawkeyexl
Copy link

@tatomyr Yes, exactly. (Hi, I'm the original reporter in that thread.) I want to lint my standalone schemas that aren't associated with any API definitions. I can do this today in Spectral with their custom rules, but I can't in Redocly.

@tatomyr
Copy link
Contributor

tatomyr commented Feb 7, 2025

@hawkeyexl we first need to determine whether a document is a JSON schema. Additionally, identifying which draft it follows would be helpful. Would it be sufficient to assume a document is a JSON schema if it contains a $schema field with a link to the draft, what do you think?

@hawkeyexl
Copy link

hawkeyexl commented Feb 7, 2025 via email

@tatomyr
Copy link
Contributor

tatomyr commented Feb 7, 2025

Good.
@RomanHotsiy will you update the feature request, or would you prefer me to open a separate issue?

@jeremyfiel
Copy link
Contributor

be very careful with following anything VSC does with JSON Schema.. they are not the most compliant participant in the JSON Schema ecosystem, particularly around the $id and $schema keywords

@jeremyfiel
Copy link
Contributor

jeremyfiel commented Feb 9, 2025

This feature is nice in theory, but redocly needs an entry point which is one of openapi, arazzo, overlay, or asyncapi files. It doesn't enter into any JSON Schema definition directly.

Is this feature request going to add that behavior?

@RomanHotsiy regarding the assertion, $schema is not required by the JSON Schema spec, so some sort of default must be applied to a schema without the $schema declaration and some consideration should be given to the OAS/Async/Overlay/Arazzo entry point.

draft-04 (related to OAS 3.0.x)

It is RECOMMENDED that schema authors include this keyword in their schemas.


draft-07 (related to Async)

No explicit recommendation


draft-2020-12 (Overlay/Arazzo/OAS 3.1.x)

The "$schema" keyword SHOULD be used in the document root schema object, and MAY be used in the root schema objects of embedded schema resources. It MUST NOT appear in non-resource root schema objects. If absent from the document root schema, the resulting behavior is implementation-defined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants