Giter Site home page Giter Site logo

Comments (6)

mihirkothari25 avatar mihirkothari25 commented on August 18, 2024

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.

mihirkothari25 avatar mihirkothari25 commented on August 18, 2024

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.

MikeRalphson avatar MikeRalphson commented on August 18, 2024

What is your expected (non infinite) output if all internal references are to be replaced?

from speccy.

mihirkothari25 avatar mihirkothari25 commented on August 18, 2024

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.

MikeRalphson avatar MikeRalphson commented on August 18, 2024

That is exactly the output if you don't specifiy resolveInternal: true.

from speccy.

mihirkothari25 avatar mihirkothari25 commented on August 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.