scottie1984 / swagger-ui-express

Adds middleware to your express app to serve the Swagger UI bound to your Swagger document. This acts as living documentation for your API hosted from within your app.
MIT License
1.42k stars 225 forks source link

Textfield immediately clear when move out the focus #231

Closed saenyakorn closed 3 years ago

saenyakorn commented 3 years ago

This is my Swagger Configuration

config/swagger.ts

const swaggerOptions: Options = {
  swaggerDefinition: {
    openapi: "3.0.0",
    host: "localhost:8080",
    basePath: "/api",
    info: {
      title: "API documentation",
      description: "",
      version: "1.0.0",
    },
    components: {
      securitySchemes: {
        cookieAuth: {
          name: "TOKEN",
          type: "apiKey",
          in: "cookie",
        },
      },
    },
    security: [
      {
        bearerAuth: [],
      },
    ],
    servers: [
      {
        url: "/api",
        description: "Sandbox server (uses test data)",
      },
    ],
  },
  apis: ["**/*.yaml"],
}
const swaggerSpec = swaggerJSDoc(swaggerOptions)
export default swaggerSpec

index.ts

app.use("/api-docs",swaggerUI.serve,swaggerUI.setup(swaggerSpec, { explorer: true }))

Here is my sample API description docs/auth.yaml

paths:
  /auth/login:
    post: # POST /auth/login
      tags: [Authentication]
      summary: Login to the application
      produces: application/json
      security: []
      parameters:
        - name: id
          description: user's id
          required: true
          schema:
            type: string
        - name: password
          description: user's password
          required: true
          schema:
            type: string
      responses:
        "200": # Success
          description: Login successful
          headers:
            Set-Cookie:
              schema:
                type: string
                example: TOKEN=jwtToken;
                description: generate jwt, add to cookie then send back to client
          content:
            application/json:
              schema:
                type: object
                properties:
                  msg:
                    type: string
                    example: login successful
                    description: login successful
        "401": # Unauthorized
          description: Unauthorized user
          content:
            application/json:
              schema:
                type: object
                properties:
                  msg:
                    type: string
                    example: unauthorized user
                    description: unauthorized user
  /auth/refresh:
    get: # GET /auth/refresh
      tags: [Authentication]
      summary: Refresh user's token
      produces: application/json
      security:
        - cookieAuth: []
      parameters:
        - name: token
          in: cookie
          description: jwt token after logged in
          required: true
          schema:
            type: string
      responses:
        "200": # Success
          description: Refresh successful
          headers:
            Set-Cookie:
              schema:
                type: string
                example: TOKEN=jwtToken;
                description: add jwt token to cookie and send back to client
          content:
            application/json:
              schema:
                type: object
                properties:
                  msg:
                    type: string
                    example: refresh successful
                    description: refresh successful
        "401": # Unauthorized
          description: Unauthorized user
          content:
            application/json:
              schema:
                type: object
                properties:
                  msg:
                    type: string
                    example: unauthorized user
                    description: unauthorized user

package.json

  "dependencies": {
    "body-parser": "^1.19.0",
    "compression": "^1.7.4",
    "cookie-parser": "^1.4.5",
    "cors": "^2.8.5",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "express-validator": "^6.6.1",
    "helmet": "^4.1.0",
    "jest": "^26.6.1",
    "jsonwebtoken": "^8.5.1",
    "pg": "^8.5.1",
    "swagger-jsdoc": "^6.0.0-rc.4",
    "swagger-ui-express": "^4.1.5",
    "ts-jest": "^26.4.3",
    "typeorm": "^0.2.28"
  },
  "devDependencies": {
    "@types/body-parser": "^1.19.0",
    "@types/compression": "^1.7.0",
    "@types/cors": "^2.8.8",
    "@types/express": "^4.17.8",
    "@types/express-validator": "^3.0.0",
    "@types/helmet": "^4.0.0",
    "@types/jest": "^26.0.19",
    "@types/jsonwebtoken": "^8.5.0",
    "@types/mysql": "^2.15.15",
    "@types/supertest": "^2.0.10",
    "@types/swagger-jsdoc": "^3.0.2",
    "@types/swagger-ui-express": "^4.1.2",
    "husky": "^4.2.5",
    "nodemon": "^2.0.6",
    "prettier": "^2.0.5",
    "supertest": "^6.0.0",
    "ts-node": "^9.0.0",
    "typescript": "^4.0.5"
  },

I try to test my APIs using swagger-ui-express version 4.1.5, but when I lose focus on id or password text field, the input was immediately cleared. But there are no problems with another text field. Like this. swagger-ui-express-problem

By the way, I solve this problem by changing swagger-ui-express version from 4.1.5 to 3.0.10 but version 4.1.5 still has this miracle bug.

I hope someone can fix this bug. Thank you for reading.

scottie1984 commented 3 years ago

After 3.0.10 is when we moved to using swagger-ui-dist. Based on this and looking at the description the issue is most likely related to the swagger-ui project and you should raise it there.