Wrong type detect for Example of a String field in YAML
- Dominant language
- Go
- Stars
- 6.1k
- Forks
- 583
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 15
Description
Hello! I'm trying to generate API spec for a design like this:
```go
package design
import (
. "goa.design/goa/v3/dsl"
)
var _ = API("APITest", func() {
})
var _ = Service("ServiceTest", func() {
Method("Main", func() {
Payload(func() {
Attribute("field1", String, func() {
Example("0xffff")
})
Attribute("field2", String, func() {
Example(`"0xffff"`)
})
Attribute("field3", String, func() {
Example("0xf47261b0000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498")
})
Attribute("field4", String, func() {
Example(`"0xf47261b0000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498"`)
})
})
HTTP(func() {
GET("/")
})
})
})
```
The problem is that the generated Swagger spec looks like this:
```yaml
ServiceTestMainRequestBody:
title: ServiceTestMainRequestBody
type: object
properties:
field1:
type: string
example: "0xffff"
field2:
type: string
example: '"0xffff"'
field3:
type: string
example: 0xf47261b0000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498
field4:
type: string
example: '"0xf47261b0000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498"'
example:
field1: "0xffff"
field2: '"0xffff"'
field3: 0xf47261b0000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498
field4: '"0xf47261b0000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498"'
```
As you can see, for some reason `field3` is treated as a number! Which will affect the generated documentation later. And for some reason `field1` is treated correctly.
So that's clearly a bug, I'm not sure why Goa tries to dynamically detect type if it is declared as `String` already in the spec. @raphael I need your help at this point :)
Contributor guide
Assessment
This issue has not been assessed yet.