prism icon indicating copy to clipboard operation
prism copied to clipboard

TypeError: Cannot set property $ref of #<Object> which has only a getter

Open keyboardsamurai opened this issue 2 years ago • 8 comments

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)

keyboardsamurai avatar Jul 17 '22 13:07 keyboardsamurai

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.

chohmann avatar Jul 22 '22 16:07 chohmann

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?

keyboardsamurai avatar Jul 23 '22 17:07 keyboardsamurai

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 avatar Jul 25 '22 13:07 chohmann

@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"

keyboardsamurai avatar Jul 26 '22 20:07 keyboardsamurai

A previous ticket regarding circular references: https://github.com/stoplightio/prism/issues/1456

ryotrellim avatar Jul 29 '22 16:07 ryotrellim

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?

theold190 avatar Aug 04 '22 12:08 theold190

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.

ghost avatar Aug 05 '22 05:08 ghost

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

hieucd04 avatar Aug 05 '22 14:08 hieucd04

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.

steffidg avatar Aug 11 '22 10:08 steffidg

Hey team! Please add your planning poker estimate with ZenHub @brendarearden @daniel-white @EdVinyard @fcasad

chohmann avatar Aug 11 '22 17:08 chohmann

thanks all. i'm starting to take a look to see what is going on

daniel-white avatar Aug 12 '22 13:08 daniel-white

i'm not able to directly reproduce in my dev environment but running this spec under docker does cause problems (both node16 and node18)

daniel-white avatar Aug 12 '22 14:08 daniel-white

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!

daniel-white avatar Aug 16 '22 15:08 daniel-white