redocly-cli icon indicating copy to clipboard operation
redocly-cli copied to clipboard

Support jsonschema vocabularies

Open lucianojs opened this issue 2 years ago • 7 comments

Describe the bug Show error on valid jsonschema with vocabularies.

https://json-schema.org/understanding-json-schema/reference/schema.html#vocabularies

To Reproduce Steps to reproduce the behavior:

openapi: 3.1.0
info:
  title: example
  version: 1.0.0
  description: example
  contact:
    email: [email protected]
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
servers:
  - url: https://google.com
tags:
  - name: user
    description: user
paths:
  /users:
    post:
      tags:
        - user
      operationId: dteDetalhe
      description: example
      summary: example
      requestBody:
        content:
          application/json:
            schema:
              type: integer
              units: kg
              isEven: true

Running this command

redocly lint test.yaml --format=stylish

Show this message:

No configurations were defined in extends -- using built in recommended configuration by default.
Warning! This default behavior is going to be deprecated soon.

validating test.yaml...
test.yaml:
  29:15  error    spec  Property `units` is not expected here.
  30:15  error    spec  Property `isEven` is not expected here.

test.yaml: validated in 25ms

❌ Validation failed with 2 errors.
run `openapi lint --generate-ignore-file` to add all problems to the ignore file.

Expected behavior Woohoo! Your OpenAPI definition is valid. 🎉

Redocly Version(s) 1.0.0-beta.100

Node.js Version(s) v14.15.1

lucianojs avatar Jun 09 '22 00:06 lucianojs

There are two things here:

  1. lint should not error for unknown keys in json schema as random keys are actually allowed in JSON Schema. I would not make this a default though as most people use default json schema vocab so they will benefit from these errors.

  2. actual support for meta-schema, this is a bigger scope. We are still considering it. So far it looks like not many people actually use it. If we see more demand we'll probably implement it.

RomanHotsiy avatar Jun 09 '22 04:06 RomanHotsiy

Adding an option somewhere to configure whether to report should help with 1.

tatomyr avatar Jun 14 '22 09:06 tatomyr

We can consider support for "Meta-data keywords" because:

Meta-data keywords are the most interoperable because they don’t affect validation. For example, you could add a units keyword. This will always work as expecting with an compliant validator.

adamaltman avatar Jun 28 '22 23:06 adamaltman

You can bypass this to run lint. But when I try to use the view of the same specification in the VSCode extension, I see the following messages:

We found structural problems in your definition, please check the files below before running the preview.

File: /home/user/test.yaml
Problem: Property `units` is not expected here.

File: /home/user/test.yaml
Problem: Property `isEven` is not expected here.

lucianojs avatar Jun 29 '22 22:06 lucianojs

It could be linked to an older version. Does it still have this issue with the latest VS Code extension @lucianojs ?

adamaltman avatar Jul 25 '22 21:07 adamaltman

@adamaltman

Yes, still have this issue on VSCode.

Release 0.2.11 (2022-07-04) of plugin.

Captura de tela de 2022-08-02 09-22-52

lucianojs avatar Aug 02 '22 12:08 lucianojs

We didn't fix it yet. We should get it done soon.

RomanHotsiy avatar Aug 02 '22 18:08 RomanHotsiy