Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Range error when using nested $ref in schema.json #1500

Closed
htc36 opened this issue Jul 3, 2024 · 2 comments · Fixed by #1510
Closed

Range error when using nested $ref in schema.json #1500

htc36 opened this issue Jul 3, 2024 · 2 comments · Fixed by #1510
Labels
bug Something isn't working mock Related to mock generation
Milestone

Comments

@htc36
Copy link

htc36 commented Jul 3, 2024

What are the steps to reproduce this issue?

  1. Use this schema.json with orval
  2. Make sure "mock": true is set in orval.config

What happens?

RangeError: Maximum call stack size exceeded

This schema works fine up until version 6.21.0 so something has happened in there to break it:

Something to do with not handling the recursion properly and causing call stack error,

What were you expecting to happen?

Generate as normal

Any logs, error output, etc?

Start orval v6.30.0 - A swagger client generator for typescript
🛑 test - RangeError: Maximum call stack size exceeded
at Object.isReference (@orval/core/dist/index.js:43526:16)
at Object.get [as isReference] (@orval/core/dist/index.js:22:45)
at getMockObject (@orval/mock/dist/index.js:111:23)
at getMockScalar (@orval/mock/dist/index.js:428:14)
at resolveMockValue (@orval/mock/dist/index.js:497:21)
at getMockScalar (@orval/mock/dist/index.js:344:11)
at resolveMockValue (@orval/mock/dist/index.js:538:18)
at @orval/mock/dist/index.js:172:29
at Array.map ()
at getMockObject (@orval/mock/dist/index.js:164:8)

What versions are you using?

Operating System: Ubuntu 20.04.2
Package Version: 6.30.0

@melloware melloware added mock Related to mock generation bug Something isn't working labels Jul 3, 2024
@MatthijsRademaker
Copy link

To add on this issue. What I've encountered is that the schema definition also influences the possible outcome.
For example, there is a circular reference within the schema "pet". Running orval against this spec.yml will result in the error described above.

openapi: 3.0.0
info:
  title: Petstore API
  version: 1.0.0
paths:
  /pets:
    get:
      summary: List all pets
      responses:
        '200':
          description: A list of pets
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/pet'
components:
  schemas:
    pet:
      type: object
      properties:
        pet:
          $ref: '#/components/schemas/pet'

However, when you uppercase the schema object definition to "Pet" it will work fine:

openapi: 3.0.0
info:
  title: Petstore API
  version: 1.0.0
paths:
  /pets:
    get:
      summary: List all pets
      responses:
        '200':
          description: A list of pets
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Pet' # Note the uppercase
components:
  schemas:
    Pet: # Note the uppercase
      type: object
      properties:
        pet:
          $ref: '#/components/schemas/Pet' # Note the uppercase

I don't know if this is the only reason this is caused but hopefully it helps with finding the solution :)

GMusk pushed a commit to GMusk/orval that referenced this issue Jul 9, 2024
…f resolution

use original name of referenced schema in ref resolution

fix orval-labs#1500
@melloware melloware added this to the 6.32.0 milestone Jul 9, 2024
@GMusk
Copy link
Contributor

GMusk commented Jul 9, 2024

Thanks @MatthijsRademaker, that was really helpful in finding the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mock Related to mock generation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants