Giter Site home page Giter Site logo

Comments (3)

tatomyr avatar tatomyr commented on May 27, 2024

Do you mean the spec-strict-refs rule? What is the error? What OpenAPI and Redocy CLI versions are?

from redocly-cli.

danielbecroft avatar danielbecroft commented on May 27, 2024

Sorry @tatomyr , yes I meant the spec-strict-refs rule. My openapi.yaml version is 3.1.0 (but also fails on 3.0.0), and my Redocly CLI version is 1.11.0.

A set of files that demonstrates the problem is below:

openapi.yaml

openapi: 3.0.0
info:
  version: v1
  title: Example

components:
  schemas:
    $ref: "./schemas.yaml"

paths:
  /foo:
    get:
      responses:
        "200": 
          description: The list of foo.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/FooModel"

schemas.yaml

FooModel:
  type: object
  properties:
`    Id:
      type: number
    Name:
      type: string
    DateOfBirth:
      type: string
      format: date

redocly.yaml

extends: []

rules:
  spec: error
  spec-strict-refs: error

Running redocly bundle openapi.yaml, correctly expands the $ref under the components/schemas:

> redocly bundle openapi.yaml
(node:38808) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
bundling .\openapi.yaml...
openapi: 3.0.0
info:
  version: v1
  title: Example
paths:
  /foo:
    get:
      responses:
        '200':
          description: The list of foo.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/FooModel'
components:
  schemas:
    FooModel:
      type: object
      properties:
        Id:
          type: number
        Name:
          type: string
        DateOfBirth:
          type: string
          format: date

Running redocly lint throws the error on the spec-strict-refs rule:

(node:71364) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
validating .\openapi.yaml...
[1] openapi.yaml:8:5 at #/components/schemas/$ref

Field $ref is not expected here.

 6 | components:
 7 |   schemas:
 8 |     $ref: "./schemas.yaml"
 9 |
10 | paths:

Error was generated by the spec-strict-refs rule.


.\openapi.yaml: validated in 11ms

❌ Validation failed with 1 error.
run `redocly lint --generate-ignore-file` to add all problems to the ignore file.

from redocly-cli.

tatomyr avatar tatomyr commented on May 27, 2024

According to the OAS 3/3.1 specification, the schemas property inside the components must be a map of schema objects (not a $ref): https://spec.openapis.org/oas/v3.1.0#components-object. Although Redocly CLI correctly resolves the $refs in that case, your example is not compliant to the spec (see more about this here). That's what the spec-strict-refs rule is about.

You have several options here. First, you can go along with the spec and use $refs in other places, e.g.:

openapi: 3.0.0
info:
  version: v1
  title: Example

components:
  schemas:
    FooModel:
      $ref: "./schemas.yaml#/FooModel"

Second, you can bypass the components section and refer to the schemas.yaml file directly (I'd expect this to be the best option), e.g.:

paths:
  /foo:
    get:
      responses:
        '200':
          description: The list of foo.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: 'schemas.yaml#/FooModel'

Then, you can turn off this rule or make its severity warning instead of error.
And finally, you can suppress this rule for this particular case by generating the ignore file as the linter suggests:

run `redocly lint --generate-ignore-file` to add all problems to the ignore file.

from redocly-cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.