Skip to content

Error resolving $ref pointer, Redocly Standalone #1506

Closed

Description

@nitram509

Hi,

I'm Using Redocly v2.0.0-rc.48 standalone in a custom portal, which in general works like a charm,
BUT some of my API specs are not rendered :/

I understand, that in the spec the reference is missing, but in my ideal world, redocly is robust and renders what's possible.
Just for reference, I did try editor.swagger.io and it still renders something.

Observed error

Error resolving $ref pointer "http://localhost:9090/doc.json#/definitions/string". Token "string" does not exist.
Stack trace
SyntaxError: Error resolving $ref pointer "http://localhost:9090/doc.json#/definitions/string". 
Token "string" does not exist.
    at Pointer.resolve (webpack:///./node_modules/json-schema-ref-parser/lib/pointer.js?:87:17)
    at $Ref.resolve (webpack:///./node_modules/json-schema-ref-parser/lib/ref.js?:83:18)
    at $Refs._resolve (webpack:///./node_modules/json-schema-ref-parser/lib/refs.js?:155:15)
    at inventory$Ref (webpack:///./node_modules/json-schema-ref-parser/lib/bundle.js?:98:23)
    at eval (webpack:///./node_modules/json-schema-ref-parser/lib/bundle.js?:73:11)
    at Array.forEach (<anonymous>)
    at crawl (webpack:///./node_modules/json-schema-ref-parser/lib/bundle.js?:67:12)
    at eval (webpack:///./node_modules/json-schema-ref-parser/lib/bundle.js?:76:11)
    at Array.forEach (<anonymous>)

Expected behavior

Redocly should be robust enough to skip missing references, print a warning, and renders what possible.
Alternatively, I might also find an optional error handler useful, which I could configure when I instantiate the standalone object. With this approach, I would be able to choose to fail fast and deny rendering or try the best approach to render it (robustness).

Problematic file

{
    "schemes": [],
    "swagger": "2.0",
    "info": {
        "description": "pdfgen service",
        "title": "PDFGen service",
        "version": "1.0"
    },
    "host": "www.example.com",
    "basePath": "/pdfgen/v1",
    "paths": {
        "/pdfgen/v1/templates/{template-name}": {
            "get": {
                "description": "The template version is taken from the parameter store.",
                "produces": [
                    "text/plain"
                ],
                "tags": [
                    "pdfgen"
                ],
                "summary": "Retrieve a template",
                "operationId": "get-template",
                "parameters": [
                    {
                        "type": "string",
                        "description": "name of the template to render with",
                        "name": "templateName",
                        "in": "query",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "zip file containing specified template",
                        "schema": {
                            "$ref": "#/definitions/string"
                        }
                    }
                }
            }
        }
    },
    "definitions": {
        "pkg.templateArray": {
            "type": "array",
            "items": {
                "type": "string"
            }
        }
    },
    "securityDefinitions": {
        "BasicAuth": {
            "type": "basic"
        }
    }
}

Activity

  1. Tory-JohnConnor commented on Jan 26, 2021

    @Tory-JohnConnor

    the definition of string is not defined in this file.

    "definitions": {
            "pkg.templateArray": {
                "type": "array",
                "items": {
                    "type": "string"
                }
            }
        },
    

    this section above is defining a pkg.templateArray as a definition. if you change it to

     "definitions": {
            "pkg.templateArray": {
                "type": "array",
                "items": {
                    "type": "string"
                }
            }, 
           "string": {
              "type": "string"
            }
        },
    
  2. nitram509 commented on Jan 27, 2021

    @nitram509
    Author

    @th3g3ntl3men thanks for pointing out the error in the document.
    I'm aware that there is one.

    That said, my naive expectation for this library is, that it will not throw an error by prompting a stack trace to the user.
    I'm not speaking about the developer console, but the React-based UI.
    As long as the documentation does not highlight known issues, I do expect the Redocly to render the correct parts.
    Ideally, there would be an error message show, which also states the line number of the error.
    Does this make sense?

    Is there a chance, some can have a look?
    I'm also willing to support but have no clue where to start. Some guidance would be helpful for me.

  3. RomanHotsiy commented on Jan 28, 2021

    @RomanHotsiy
    Member

    We may support it in one of the upcoming versions after we finish migrating to openapi-core: #1500

  4. Tory-JohnConnor commented on Jan 28, 2021

    @Tory-JohnConnor

    @nitram509 oh sorry i must of not understood. I do like your idea though.

  5. nitram509 commented on Jan 28, 2021

    @nitram509
    Author

    @RomanHotsiy Thank you for your engagement and work on this.
    Let me know, if I could help/support somehow, in testing or whatsoever.

  6. andriyl commented on Apr 9, 2021

    @andriyl
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions