jdrouet / catapulte

Rust implementation of catapulte email sender
GNU Affero General Public License v3.0
139 stars 6 forks source link

Endpoint fails with (Failed to deserialize) when building the source #702

Closed PepperPlatypus closed 5 months ago

PepperPlatypus commented 5 months ago

Compiled docker image from main:

Then ran the image with this command

docker run -d \
  --name catapulte \
  -e SMTP_HOSTNAME=smtp.ethereal.email \
  -e SMTP_PORT=587 \
  -e SMTP_USERNAME=donnell.konopelski65@ethereal.email \
  -e SMTP_PASSWORD=nYSncuFYzZ7mMwWRHa \
  -e SMTP_TLS_ENABLED=false \
  -e SWAGGER_ENABLED=true \
  -e TEMPLATE_PROVIDER=local \
  -e TEMPLATE_ROOT=/templates \
  -p 3000:3000 \
  -v ./template:/templates:ro \
  catapulte:latest

I attached the existing template (not templates) folder

Then when i try curl, i get an error Failed to deserialize the JSON body into the target type: missing fieldfromat line 18 column 1%

user-login/metadata.json looks like this. please note there is no from field in the json file

{
  "name": "user-login",
  "description": "Template for login with magic link",
  "template": {
    "path": "user-login/template.mjml"
  },
  "attributes": {
    "type": "object",
    "properties": {
      "token": {
        "type": "string"
      }
    },
    "required": [
      "token"
    ]
  }
}
curl -X POST -v \
  -H "Content-Type: application/json" \
  --data '{
  "name": "user-login",
  "description": "Template for login with magic link",
  "template": {
    "path": "user-login/template.mjml"
  },
  "attributes": {
    "type": "object",
    "properties": {
      "token": {
        "type": "string"
      }
    },
    "required": [
      "token"
    ]
  }
}' \  
  http://localhost:3000/templates/user-login/json
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying [::1]:3000...
* Connected to localhost (::1) port 3000
> POST /templates/user-login/json HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/8.4.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 301
> 
< HTTP/1.1 422 Unprocessable Entity
< content-type: text/plain; charset=utf-8
< content-length: 98
< date: Thu, 02 May 2024 17:00:47 GMT
< 
* Connection #0 to host localhost left intact
Failed to deserialize the JSON body into the target type: missing field `from` at line 18 column 1%                                                                                   
PepperPlatypus commented 5 months ago

My bad, missing to and from parameters in the request body!