prism
prism copied to clipboard
TypeError: Cannot set property $ref of #<Object> which has only a getter
When using the mock server with the attached openapi definition that validates just fine at https://validator.swagger.io/ I consistently get the following error when using prism mock ./openapi.yml
instead of starting the mock server:
TypeError: Cannot set property $ref of #<Object> which has only a getter
at Object.onProperty (/Users/user/.nvm/versions/node/v18.6.0/lib/node_modules/@stoplight/prism-cli/node_modules/@stoplight/json/index.cjs.js:1:4846)
at _traverse (/Users/user/.nvm/versions/node/v18.6.0/lib/node_modules/@stoplight/prism-cli/node_modules/@stoplight/json/index.cjs.js:1:3579)
at _traverse (/Users/user/.nvm/versions/node/v18.6.0/lib/node_modules/@stoplight/prism-cli/node_modules/@stoplight/json/index.cjs.js:1:3672)
at _traverse (/Users/user/.nvm/versions/node/v18.6.0/lib/node_modules/@stoplight/prism-cli/node_modules/@stoplight/json/index.cjs.js:1:3672)
at _traverse (/Users/user/.nvm/versions/node/v18.6.0/lib/node_modules/@stoplight/prism-cli/node_modules/@stoplight/json/index.cjs.js:1:3672)
at _traverse (/Users/user/.nvm/versions/node/v18.6.0/lib/node_modules/@stoplight/prism-cli/node_modules/@stoplight/json/index.cjs.js:1:3672)
at _traverse (/Users/user/.nvm/versions/node/v18.6.0/lib/node_modules/@stoplight/prism-cli/node_modules/@stoplight/json/index.cjs.js:1:3672)
at _traverse (/Users/user/.nvm/versions/node/v18.6.0/lib/node_modules/@stoplight/prism-cli/node_modules/@stoplight/json/index.cjs.js:1:3672)
at _traverse (/Users/user/.nvm/versions/node/v18.6.0/lib/node_modules/@stoplight/prism-cli/node_modules/@stoplight/json/index.cjs.js:1:3672)
at _traverse (/Users/user/.nvm/versions/node/v18.6.0/lib/node_modules/@stoplight/prism-cli/node_modules/@stoplight/json/index.cjs.js:1:3672)
Environment: MacOS 12.4, NodeJS 18.6.0 and 16.15.0 (tried both)
Hi @keyboardsamurai, thank you for reporting this! Could you provide a minimum reproducible example that illustrates this issue? That will help us pinpoint exactly what about a ref could cause this. At first look, it's not clear which ref in the spec you provided is causing this issue.
Hi @chohmann, thank you for taking the time to look into this issue. I'd be happy to provide a working setup but I'm not sure what I should gather besides the attached spec. Do you have something specific in mind, like a dockerized demo of the issue?
Hi @keyboardsamurai! I was thinking just a smaller spec with one ref that illustrates the issue. It's hard to tell from the spec you provided exactly which ref is causing the issue. So a very simple spec that still reproduces the issue would be greatly appreciated!
@chohmann I was able to narrow this particular issue down to the cyclic dependency for PydanticDocument described in this minimal openapi spec below. Hope this helps
openapi: 3.0.2
info:
title: My Jina Service
description: Desc
version: 3.6.13
paths:
"/update":
put:
summary: "/Update"
description: Post data requests to the Flow. Executors with `@requests(on="/update")`
will respond.
operationId: _update_update_put
requestBody:
content:
application/json:
schema:
"$ref": "#/components/schemas/JinaRequestModel"
required: true
components:
schemas:
JinaRequestModel:
title: JinaRequestModel
type: object
properties:
data:
anyOf:
- type: array
items:
"$ref": "#/components/schemas/PydanticDocument"
PydanticDocument:
title: PydanticDocument
type: object
properties:
chunks:
title: Chunks
type: array
items:
"$ref": "#/components/schemas/PydanticDocument"
A previous ticket regarding circular references: https://github.com/stoplightio/prism/issues/1456
I see same error when testing with docker image v4.10.1. It fails to start the mock:
[11:35:16 AM] › [CLI] … awaiting Starting Prism…
[11:35:18 AM] › [CLI] ✖ fatal Cannot set property $ref of #<Object> which has only a getter
But I am able to start Prism mock when using docker image v4.10.0.
So maybe there was a regression in v4.10.1?
I am able to start Prism mock when using v4.2.5.
I installed prism with yarn add @stoplight/[email protected]
.
I see same error when using v4.10.0 or v4.10.1.
I downloaded Stoplight Studio here: https://github.com/stoplightio/studio/releases
And with the assumption that Stoplight Studio "Mocks" feature is powered by Prism:
- Version "v2.8.1" also has this issue (toggle Dev Tools to see it)
- Whereas, version "2.8.1" doesn't (the difference is the letter "v" at the beginning)
Ps: I'm using Windows
I'm encountering the same issue on my end. After trying it out, it appears that my spec stopped successfully compiling on v4.9.x and above.
Hey team! Please add your planning poker estimate with ZenHub @brendarearden @daniel-white @EdVinyard @fcasad
thanks all. i'm starting to take a look to see what is going on
i'm not able to directly reproduce in my dev environment but running this spec under docker does cause problems (both node16 and node18)
hey @keyboardsamurai @steffidg @hieucd04 @theold190 - i just cut 4.10.3. i'm hoping this solves your use cases. if not please come back and open new issues with new examples. thanks!