Comments (3)
Do you mean the spec-strict-refs rule? What is the error? What OpenAPI and Redocy CLI versions are?
from redocly-cli.
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.
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)
- Support internalFlagProperty as a list for remove-x-internal decorator HOT 2
- Update syntax for decorators to support markdown as well as file paths
- Support for operations that respond with `1xx` status codes HOT 5
- Incorrect command to preview local docs changes in contributing.md HOT 3
- Review guide for replacing servers list HOT 1
- redocly lint format html or markdown HOT 5
- better error handling when $ref references an external file in asyncapi HOT 7
- asyncapi lint support custom rules HOT 8
- Can't resolve remote $ref with query parameter HOT 3
- OAS 3.1 - arbitrary schema keywords are classified as lint errors HOT 3
- Missing const typing support HOT 2
- bug: inconsistent types for OAS3_1 schemas HOT 1
- Add some type of plugin to allow dynamic definition of extensions or config files HOT 2
- Support better means to set environment variables HOT 2
- dependentRequired is valid json schema but does not pass linting and prevents component from being available in UI. HOT 3
- Api HOT 2
- Add the `--ext` parameter to the `split` command HOT 1
- Running out of CPU inside of containers HOT 2
- join fails on commonly referenced components
- Redocly removing string for enums if there's non-numbers mixed in HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redocly-cli.