whatsapp-api
whatsapp-api copied to clipboard
swagger.json "/client/getContacts/{sessionId}" response 200 fix
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