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

redoc-cli render TypeError: str.slice is not a function #870

Closed
abcfy2 opened this issue Mar 27, 2019 · 2 comments
Closed

redoc-cli render TypeError: str.slice is not a function #870

abcfy2 opened this issue Mar 27, 2019 · 2 comments

Comments

@abcfy2
Copy link

abcfy2 commented Mar 27, 2019

Here is my sample.yaml:

openapi: 3.0.2
info:
  title: 我的测试
  description: 获取当前项目的API
  version: '1.0'
servers:
  - url: 'https://localhost'
    description: 项目产品服务器地址
paths:
  /api/login:
    post:
      tags:
        - login
      summary: 登录
      description: 用户登录接口
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - username
                - password
              properties:
                username:
                  type: string
                password:
                  type: string
              example:
                username: '17711111111'
                password: '888888'
      responses:
        '200':
          description: 登录成功
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/loginSuccess'
        '401':
          description: 登录失败
  /oauth/access_token:
    post:
      tags:
        - login
      summary: 刷新JWT
      description: 刷新JWT的接口
      requestBody:
        content:
          'application/x-www-form-urlencoded':
            schema:
              type: object
              required:
                - grant_type
                - refresh_token
              properties:
                grant_type:
                  type: string
                  description: '必填(refresh_token)'
                refresh_token:
                  type: string
                  description: '之前登陆成功返回内容中的refresh_token字段'
            example:
              grant_type: refresh_token
              refresh_token: eyJlbmMiOiJBMTI4R0NNIiwiYWxnIjoiUlNBLU9BRVAifQ.xxxx.xxxx
      responses:
        '200':
          description: 刷新JWT成功
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/loginSuccess'
components:
  schemas:
    loginSuccess:
      type: object
      required:
        - username
        - roles
        - userId
        - displayName
        - token_type
        - access_token
        - expires_in
        - refresh_token
      properties:
        username:
          type: string
          description: 用户名
          example: '17711111111'
        roles:
          type: array
          description: 角色
          items:
            type: string
            enum:
              - ROLE_ADMIN
              - ROLE_KF
              - ROLE_BUYER
              - ROLE_SELLER
          example:
            - ROLE_BUYER
            - ROLE_KF
        userId:
          type: integer
          description: 用户id
          example: 1
        displayName:
          type: string
          description: 展示名
          example: 我的用户
        token_type:
          type: string
          default: Bearer
          description: JWT类型(默认Bearer)
          example: Bearer
        access_token:
          type: string
          description: JWT主体内容
          example: eyJlbmMiOiJBMTI4R0NNIiwiYWxnIjoiUlNBLU9BRVAifQ.xxxx.xxxx
        expires_in:
          type: integer
          default: 3600
          description: 过期时间
          example: 3600
        refresh_token:
          type: string
          description: 刷新token,用于访问refresh接口
          example: eyJlbmMiOiJBMTI4R0NNIiwiYWxnIjoiUlNBLU9BRVAifQ.xxxx.xxxx

But redoc-cli bundle sample.yaml gives me this error:

$ redoc-cli bundle sample.yaml
Prerendering docs
TypeError: str.slice is not a function
    at Object.matchGrammar (C:\Users\abcfy\AppData\Roaming\npm\node_modules\redoc-cli\node_modules\prismjs\prism.js:380:23)
    at Object.tokenize (C:\Users\abcfy\AppData\Roaming\npm\node_modules\redoc-cli\node_modules\prismjs\prism.js:424:5)
    at Object.highlight (C:\Users\abcfy\AppData\Roaming\npm\node_modules\redoc-cli\node_modules\prismjs\prism.js:280:18)
    at highlight (C:\Users\abcfy\AppData\Roaming\npm\node_modules\redoc-cli\node_modules\redoc\bundles\redoc.lib.js:7738:42)
    at SourceCode.render (C:\Users\abcfy\AppData\Roaming\npm\node_modules\redoc-cli\node_modules\redoc\bundles\redoc.lib.js:11870:25)
    at processChild (C:\Users\abcfy\AppData\Roaming\npm\node_modules\redoc-cli\node_modules\react-dom\cjs\react-dom-server.node.development.js:2942:18)
    at resolve (C:\Users\abcfy\AppData\Roaming\npm\node_modules\redoc-cli\node_modules\react-dom\cjs\react-dom-server.node.development.js:2795:5)
    at ReactDOMServerRenderer.render (C:\Users\abcfy\AppData\Roaming\npm\node_modules\redoc-cli\node_modules\react-dom\cjs\react-dom-server.node.development.js:3185:22)
    at ReactDOMServerRenderer.read (C:\Users\abcfy\AppData\Roaming\npm\node_modules\redoc-cli\node_modules\react-dom\cjs\react-dom-server.node.development.js:3144:29)
    at Object.renderToString (C:\Users\abcfy\AppData\Roaming\npm\node_modules\redoc-cli\node_modules\react-dom\cjs\react-dom-server.node.development.js:3629:27)
@RomanHotsiy
Copy link
Member

The issue was with x-www-form-urlencoded. It was not encoded properly.

Now it looks like bellow:
image

Will land in the upcoming release.

@abcfy2
Copy link
Author

abcfy2 commented Mar 28, 2019

Great!

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

2 participants