Comments (6)
An additional note - this the schema does have recursion and is structured as given in the example from the json-schema docs - https://json-schema.org/understanding-json-schema/structuring.html#recursion
from speccy.
A quick example test case -
the yaml spec, say temp.yaml
-
openapi: 3.0.2
info:
title: api
description: |
description!
contact:
name: 'team'
url: 'https://test.com/'
email: '[email protected]'
version: 0.0.1
servers:
- url: https://test.com
paths: {}
components:
responses:
Request:
description: request
content:
application/json:
schema:
$ref: temp.json#/definitions/person
tags: []
the schema in a file temp.json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"person": {
"type": "object",
"properties": {
"name": { "type": "string" },
"children": {
"type": "array",
"items": { "$ref": "#/definitions/person" },
"default": []
}
}
}
},
"type": "object",
"properties": {
"person": { "$ref": "#/definitions/person" }
}
}
The command to run is - speccy resolve ./temp.yaml -j -v -i
Error -
GET ./packages/common-spec/src/specifications/components/temp.yaml
GET /Users/mkothari/git/common-specs/packages/common-spec/src/specifications/components/temp.json #/definitions/person
RangeError: Maximum call stack size exceeded
at String.replace (<anonymous>)
at jpescape (/Users/mkothari/git/common-specs/node_modules/reftools/lib/jptr.js:9:14)
at recurse (/Users/mkothari/git/common-specs/node_modules/reftools/lib/recurse.js:34:60)
at recurse (/Users/mkothari/git/common-specs/node_modules/reftools/lib/recurse.js:53:13)
at recurse (/Users/mkothari/git/common-specs/node_modules/reftools/lib/recurse.js:53:13)
at recurse (/Users/mkothari/git/common-specs/node_modules/reftools/lib/recurse.js:53:13)
at recurse (/Users/mkothari/git/common-specs/node_modules/reftools/lib/recurse.js:53:13)
at recurse (/Users/mkothari/git/common-specs/node_modules/reftools/lib/recurse.js:53:13)
at recurse (/Users/mkothari/git/common-specs/node_modules/reftools/lib/recurse.js:53:13)
at recurse (/Users/mkothari/git/common-specs/node_modules/reftools/lib/recurse.js:53:13)
Maximum call stack size exceeded
from speccy.
What is your expected (non infinite) output if all internal references are to be replaced?
from speccy.
That's a good question. IMO resolving it to the top level would suffice with a reference back to the object itself further down the tree.
This would be the desired output -
openapi: 3.0.2
info:
title: api
description: |
description!
contact:
name: team
url: https://test.com/
email: [email protected]
version: 0.0.1
servers:
- url: https://test.com
paths: {}
components:
responses:
Request:
description: request
content:
application/json:
schema:
type: object
properties:
name:
type: string
children:
type: array
items:
$ref: "#/components/responses/Request/content/application~1json/schema"
default: []
tags: []
from speccy.
That is exactly the output if you don't specifiy resolveInternal: true
.
from speccy.
I think I simplified my test yaml too much without showcasing the actual use case I am looking to solve.
If you refer to the same schema multiple times in the spec (which is what we are doing), as shown in the example below -
openapi: 3.0.2
info:
title: api
description: |
description!
contact:
name: 'team'
url: 'https://test.com/'
email: '[email protected]'
version: 0.0.1
servers:
- url: https://test.com
paths: {}
components:
responses:
Request:
description: request
content:
application/json:
schema:
$ref: temp.json#/definitions/person
Request2:
description: request
content:
application/json:
schema:
$ref: temp.json#/definitions/person
tags: []
if I don't specify resolveInternal: true
then it results in this -
openapi: 3.0.2
info:
title: api
description: |
description!
contact:
name: team
url: https://test.com/
email: [email protected]
version: 0.0.1
servers:
- url: https://test.com
paths: {}
components:
responses:
Request:
description: request
content:
application/json:
schema:
type: object
properties:
name:
type: string
children:
type: array
items:
type: object
properties:
name:
type: string
children:
type: array
items:
$ref: "#/components/responses/Request/content/application~1json/schema/properti\
es/children/items"
default: []
default: []
Request2:
description: request
content:
application/json:
schema:
$ref: "#/components/responses/Request/content/application~1json/schema"
tags: []
It resolves it the first time, and then any future references point to the first place it was resolved.
Our goal was to have it resolve in all spots, which is why we added resovleInternal: true
, which then resulted in the RangeError.
from speccy.
Related Issues (20)
- False positive (lint and resolve) with referenced ($ref) examples HOT 1
- Rule path-keys-no-trailing-slash: throws lint error when path is a single slash HOT 2
- Hangs resolving external references with NodeJS >= 12.17.0 HOT 3
- Don't resolve internal reference HOT 1
- Multi $ref ? HOT 2
- Support for Async API HOT 1
- lint: Cannot read property 'failed' of undefined HOT 4
- resolve does not import tags HOT 1
- securitySchemes property "in" should be required HOT 1
- speccy serve redoc try HOT 1
- Access to every item on operation's parameters object HOT 1
- Implicit map keys need to be on a single line
- how to combine $ref and default? HOT 1
- The website is down (again)
- Adding SARIF result format support for speccy
- Is this project active? HOT 3
- Speccy lint whole project using gradle/maven build
- reused json schema is only converted once
- If an object just ref another object, the progress will be blocked
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 speccy.