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

Error resolving $ref pointer, Redocly Standalone #1506

Closed
nitram509 opened this issue Jan 26, 2021 · 6 comments
Closed

Error resolving $ref pointer, Redocly Standalone #1506

nitram509 opened this issue Jan 26, 2021 · 6 comments

Comments

@nitram509
Copy link

nitram509 commented Jan 26, 2021

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

@AgentGoldPaw
Copy link

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"
        }
    },

@nitram509
Copy link
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.

@RomanHotsiy
Copy link
Member

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

@AgentGoldPaw
Copy link

AgentGoldPaw commented Jan 28, 2021

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

@nitram509
Copy link
Author

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

@andriyl
Copy link
Contributor

andriyl commented Apr 9, 2021

@nitram509 fixed: #1500

@andriyl andriyl closed this as completed Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants