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

Invalid reference token and decoding #148

Open
HonzaMac opened this issue Feb 1, 2023 · 0 comments
Open

Invalid reference token and decoding #148

HonzaMac opened this issue Feb 1, 2023 · 0 comments

Comments

@HonzaMac
Copy link

HonzaMac commented Feb 1, 2023

We are receiving error below, when trying to generate documentation via redoc-cli tool.
redoc-cli calls openapi-sampler and does not work properly with keys in swagger.

Example of swagger file.

``` components: schemas: Required__%5BkeyinDeliverableWithWriterAlias%5D%3Aboolean--__: properties: system-administration: type: boolean system-use: type: boolean required: - system-administration - system-use type: object description: 'Make all properties in T required' ReleaseNotificationsBody: properties: commentsAll: type: boolean comments: $ref: '#/components/schemas/Required__%5BkeyinDeliverableWithWriterAlias%5D%3Aboolean--__' required: - commentsAll - comments type: object additionalProperties: false info: title: 'API v1' version: 3.18.0 openapi: 3.0.0 paths: '/releases/{releaseVersionId}/notifications': put: operationId: updateNotifications responses: '200': description: 'Release notifications updated' content: application/json: schema: $ref: '#/components/schemas/ReleaseNotificationsBody' summary: 'Update Release Notifications for current user' parameters: - in: path name: releaseVersionId required: true schema: $ref: '#/components/schemas/ReleaseVersionId' requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/ReleaseNotificationsBody' get: operationId: getNotifications responses: '200': description: 'Get release notifications' content: application/json: schema: $ref: '#/components/schemas/ReleaseNotificationsBody' summary: 'Get Release Notifications for current user' parameters: - in: path name: releaseVersionId required: true schema: $ref: '#/components/schemas/ReleaseVersionId' ```

Error: Invalid reference token: Required__[keyinDeliverableWithWriterAlias]:boolean--__
at Function.get (/sr/app/node modules/openapi-sampler/dist/openapi-sampler.js:79:19)
at traverse (/usr/app/node_modules/openapi-sampler/dist/openapi-sampler.js:947:43)
at /usr/app/node_modules/openapi-sampler/dist/openapi-sampler.is:646:43
at Arrav.forEach(<anonvmous>)
at sample0biect (/us/app/node modules/openapi-sampler/dist/openapi-sampler.is:640:36
at traverse (/usr/app/node_modules/openapi-sampler/dist/openapi-sampler.js:1033:17)
at traverse (/usr/app/node_modules/openapi-sampler/dist/openapi-sampler.is:953:16)
at Object.sample (/usr/app/node_modules/openapi-sampler/dist/openapi-sampler.js:426:33)
at Hn.generateExample (/usr/app/node modules/redoc/bundles/redoc.lib.is:41:73780)
at new Hn (/usr/app/node modules/redoc/bundles/redoc. lib.js:41:73198)

What helped us is this patch:

diff --git a/node_modules/openapi-sampler/dist/openapi-sampler.js b/node_modules/openapi-sampler/dist/openapi-sampler.js
index 55fc164..4431786 100644
--- a/node_modules/openapi-sampler/dist/openapi-sampler.js
+++ b/node_modules/openapi-sampler/dist/openapi-sampler.js
@@ -938,7 +938,7 @@ function traverse(schema, options, spec, context) {
       throw new Error('Your schema contains $ref. You must provide full specification in the third parameter.');
     }

-    var ref = decodeURIComponent(schema.$ref);
+    var ref = schema.$ref; // Fixes: "Error: Invalid reference token: Required__[keyinDeliverableWithWriterAlias]:boolean--__"

     if (ref.startsWith('#')) {
       ref = ref.substring(1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant