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

swagger.json "/client/getContacts/{sessionId}" response 200 fix #247

Open
kaua-alves-queiros opened this issue Aug 4, 2024 · 1 comment

Comments

@kaua-alves-queiros
Copy link

I noticed that for the endpoint /client/getContacts/{sessionId}, the Swagger JSON is generating the following response for status 200:
I have no idea why the swagger.json is being generated incorrectly or if generating the client SDK with NSwag will create another functional endpoint

generated swagger.json

"200": {
  "description": "OK"
}

This prevents the correct SDK generation via NSwag.

The solution I found is quite crude (completely ChatGPT), but for now, it works.

fix swagger.json

{
  "/client/getContacts/{sessionId}": {
    "get": {
      "tags": [
        "Client"
      ],
      "description": "",
      "parameters": [
        {
          "name": "sessionId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Unique identifier for the session (alphanumeric and - allowed)",
          "example": "f8377d8d-a589-4242-9ba6-9486a04ef80c"
        }
      ],
      "responses": {
        "200": {
          "description": "OK",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "success": {
                    "type": "boolean"
                  },
                  "contacts": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "object",
                          "properties": {
                            "server": {
                              "type": "string"
                            },
                            "user": {
                              "type": "string"
                            },
                            "_serialized": {
                              "type": "string"
                            }
                          }
                        },
                        "number": {
                          "type": "string",
                          "nullable": true
                        },
                        "isBusiness": {
                          "type": "boolean"
                        },
                        "isEnterprise": {
                          "type": "boolean"
                        },
                        "name": {
                          "type": "string"
                        },
                        "pushname": {
                          "type": "string"
                        },
                        "shortName": {
                          "type": "string"
                        },
                        "type": {
                          "type": "string"
                        },
                        "isMe": {
                          "type": "boolean"
                        },
                        "isUser": {
                          "type": "boolean"
                        },
                        "isGroup": {
                          "type": "boolean"
                        },
                        "isWAContact": {
                          "type": "boolean"
                        },
                        "isMyContact": {
                          "type": "boolean"
                        },
                        "isBlocked": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              },
              "example": {
                "success": true,
                "contacts": [
                  {
                    "id": {
                      "server": "c.us",
                      "user": "123456789",
                      "_serialized": "[email protected]"
                    },
                    "number": "123456789",
                    "isBusiness": false,
                    "isEnterprise": false,
                    "name": "John Doe",
                    "pushname": "John",
                    "shortName": "John",
                    "type": "in",
                    "isMe": false,
                    "isUser": true,
                    "isGroup": false,
                    "isWAContact": true,
                    "isMyContact": true,
                    "isBlocked": false
                  },
                  {
                    "id": {
                      "server": "lid",
                      "user": "987654321",
                      "_serialized": "987654321@lid"
                    },
                    "number": "987654321",
                    "isBusiness": false,
                    "isEnterprise": false,
                    "name": "Jane Smith",
                    "pushname": "Jane",
                    "shortName": "Jane",
                    "type": "in",
                    "isMe": false,
                    "isUser": true,
                    "isGroup": false,
                    "isWAContact": true,
                    "isMyContact": true,
                    "isBlocked": false
                  }
                ]
              }
            }
          }
        },
        "403": {
          "description": "Forbidden.",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ForbiddenResponse"
              }
            }
          }
        },
        "404": {
          "description": "Not Found.",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NotFoundResponse"
              }
            }
          }
        },
        "422": {
          "description": "Unprocessable Entity.",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ErrorResponse"
              }
            }
          }
        }
      },
      "security": [
        {
          "apiKeyAuth": []
        }
      ]
    }
  }
}

bash command to build sdk

nswag openapi2csclient /input:.\swagger.json /output:WhatsappClient.cs /namespace:{YourNameSpace}.WhatsappClient /classname:WhatsappClient /OperationGenerationMode:SingleClientFromPathSegments
@kaua-alves-queiros
Copy link
Author

I noticed that the same thing happens with the /contact/getChat/{sessionId} endpoint.

In the 200 response, the same issue is present in the swagger.json

"200": { "description": "OK" }

If I change it to something similar to the issue, that is, manually map everything, the SDK is generated normally.

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