stoplightio / prism

Turn any OpenAPI2/3 and Postman Collection file into an API server with mocking, transformations and validations.

Home Page:https://stoplight.io/open-source/prism

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`prism --dynamic` returns 500's with `TypeError: Cannot read properties of null (reading 'value')`

rattrayalex opened this issue · comments

Context

Given this OAS:

paths:
  /responses/object_no_properties:
    post:
      description: |
        Endpoint with an empty response.
      responses:
        '200':
          description: No response content
          content:
            application/json:
              schema:
                type: object
                properties: {}
                additionalProperties: false

And running prism --dynamic --verboseLevel=debug on v5.3.2

Current Behavior

[1:30:33 PM] › [HTTP SERVER] post /responses/object_no_properties ✖  error     Request terminated with error: Error: TypeError: Cannot read properties of null (reading 'value')
    at traverse (/Users/ralex/code/stainless/node_modules/json-schema-faker/dist/main.cjs.js:2167:43)
    at run (/Users/ralex/code/stainless/node_modules/json-schema-faker/dist/main.cjs.js:2402:24)
    at Function.jsf.generateWithContext (/Users/ralex/code/stainless/node_modules/json-schema-faker/dist/main.cjs.js:6084:14)
    at Function.jsf.generate (/Users/ralex/code/stainless/node_modules/json-schema-faker/dist/main.cjs.js:6086:51)
    at /Users/ralex/code/stainless/node_modules/@stoplight/prism-http/dist/mocker/generator/JSONSchema.js:55:258
    at tryCatch (/Users/ralex/code/stainless/node_modules/fp-ts/lib/Either.js:1039:30)
    at /Users/ralex/code/stainless/node_modules/@stoplight/prism-http/dist/mocker/generator/JSONSchema.js:55:210
    at /Users/ralex/code/stainless/node_modules/fp-ts/lib/Either.js:333:38
    at pipe (/Users/ralex/code/stainless/node_modules/fp-ts/lib/function.js:288:20)
    at generate (/Users/ralex/code/stainless/node_modules/@stoplight/prism-http/dist/mocker/generator/JSONSchema.js:55:32) in /

Expected Behavior

Without --dynamic, there are no errors.

Possible Workaround/Solution

Steps to Reproduce

  1. Use above spec
  2. Run prism --dynamic

Environment

  • Version used: 5.3.2
  • Environment name and version (e.g. Chrome 39, node.js 5.4): Node v20.5.0
  • Operating System and version (desktop or mobile): MacOS
  • Link to your environment/workspace/project: private

cc @ilanashapiro – can you take a look at this? If it's an issue with json-schema-faker, would you mind filing an issue with them, and then tackling it there? (If it isn't solved with a simple version upgrade or different way of calling the library or something).

@rattrayalex I tried to repo this and for some reason I'm not getting this error. I'm using Prism v5.3.2 and Node v20.5.0, and I'm running the following spec

openapi: '3.0.2'
paths:
  /responses/object_no_properties:
    post:
      description: |
        Endpoint with an empty response.
      responses:
        '200':
          description: No response content
          content:
            application/json:
              schema:
                type: object
                properties: {}
                additionalProperties: false

with the following command: prism mock examples/dynamic.yaml --dynamic --verboseLevel=debug. I then run curl -i -X POST http://127.0.0.1:4010/responses/object_no_properties and I'm getting the following:
image
and
image

I'm not sure if there's a step here where I'm diverging from what you did? Thanks!

@RobertCraigie can you try to help Ilana repro this based on our sink?

@rattrayalex I also tried to reproduce this with the steps you provided, and received the same outcome as @ilanashapiro and could not reproduce the error. Going to close this ticket, but re-open with additional steps on how to reproduce if this continues to be a problem for you.