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

Providing integer Default for Number gives compilation error #1342

Closed
klauspost opened this issue Aug 8, 2017 · 1 comment
Closed

Providing integer Default for Number gives compilation error #1342

klauspost opened this issue Aug 8, 2017 · 1 comment

Comments

@klauspost
Copy link

Probably a regression caused by fixing integer numbers:

package design

import (
	. "github.com/goadesign/goa/design"
	. "github.com/goadesign/goa/design/apidsl"
)

var _ = Resource("lists", func() {
	Action("get", func() {
		Routing(
			GET(""),
		)
		Params(func() {
			Param("num", Number, func() {
				Default(50)
			})
		})
		Response(NoContent)
	})
}) 
>goagen bootstrap -d goatest/design
exit status 1
goatest\app\contexts.go:44:14: expected operand, found '%!'(MISSING)
goatest\app\contexts.go:47:3: expected ';', found 'if'

[...]
        if len(paramNum) == 0 {
                rctx.Num = %!!(MISSING)f(int=50)
        } else {

%f should maybe be %v. Sending 50.0 as default value works around the issue.

@klauspost klauspost changed the title Providing integer Default value gives compilation error Providing integer Default for Number gives compilation error Aug 8, 2017
@raphael
Copy link
Member

raphael commented Aug 8, 2017

This is actually a different issue, the type is declared as Number and not Integer so the runtime value is a float64 but 50 is an int value. Using 50.0 is the correct thing to do. That being said the data types in the DSL are modeled after JSON - not after the Go type system. So it would probably be good if one could use 50 to specific a Number value. I'll take this as a enhancement request :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants