goadesign / goadesign/goa

Using Param() to map path parameters to attributes results in a runtime error

Open
#3,462 5 comments 1 reaction 0 assignees View on GitHub
Dominant language
Go
Stars
6.1k
Forks
583
Avg merge
2d 10h
Merged PRs (30d)
15

Description

Hi, I'm new to goa and I want to map a path param e.g. _product_id_ to a payload attribute _id_.

My design:

Service:
```
var _ = Service("products", func() {
Description("The product service provides an API for managing products.")
HTTP(func() {
Path("/products")
})

// update product by id
Method("update by id", func() {
Payload(UpdateProductPayload)
Result(UpdateProductPayload, func() {
View("default")
})
Error("no_criteria", String, "Missing criteria")
Error("no_match", String, "No product found with specified id")
HTTP(func() {
POST("/{product_id}")
Param("product_id:id")
Response(StatusOK)
Response("no_criteria", StatusBadRequest)
Response("no_match", StatusNotFound)
})
})
})
```

Payload Model:
```
var UpdateProductPayload = Type("UpdateProductPayload", func() {
Attribute("id", String, "Product ID", func() {
Example("83d83ec2-d2ca-49ff-bbea-b92b5c3be202")
})
Attribute("name", String, "Product Name", func() {
Example("Apple")
})
})
```

Generating the code results in:
```
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x60 pc=0x1023a3028]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.