Bo0mer
Repos
62
Followers
20
Following
9

Generate logging, tracing and monitoring Go interface implementations

7
4

Concourse CI Slack/Mattermost Bot

1
0

Debug proxy - sniff HTTP communication

5
0

Pull metrics for Cloud Foundry applications and forward them to Riemann

9
2

This repo holds various resources that are related to Cloud Foundry Sofia meetups

2
1

Events

issue comment
Goa attribute validation "ExclusiveMinimum" is not exclusive

Here's a demo design file that I've used to reproduce the issue:

package design

import . "goa.design/goa/v3/dsl"

// API describes the global properties of the API server.
var _ = API("calc", func() {
	Title("Calculator Service")
	Description("HTTP service for multiplying numbers, a goa teaser")
	Server("calc", func() {
		Host("localhost", func() { URI("http://localhost:8088") })
	})
})

// Service describes a service
var _ = Service("calc", func() {
	Description("The calc service performs operations on numbers")
	Method("multiply", func() {
		Payload(func() {
			Attribute("a", Int, "Left operand", func() {
				ExclusiveMinimum(0)
			})
			Attribute("b", Int, "Right operand")

			Required("a", "b")
		})
		Result(Int)
		HTTP(func() {
			GET("/multiply/{a}/{b}")
			Response(StatusOK)
		})
	})
})

a should have validation that it is strictly >0. But here is the generated code from DecodeMultiplyRequest in server/encode_decode.go:

return func(r *http.Request) (interface{}, error) {
		var (
			a   int
			b   int
			err error

			params = mux.Vars(r)
		)
		{
			aRaw := params["a"]
			v, err2 := strconv.ParseInt(aRaw, 10, strconv.IntSize)
			if err2 != nil {
				err = goa.MergeErrors(err, goa.InvalidFieldTypeError("a", aRaw, "integer"))
			}
			a = int(v)
		}
		if a < 0 {
			err = goa.MergeErrors(err, goa.InvalidRangeError("a", a, 0, true))
		}
		{
			bRaw := params["b"]
			v, err2 := strconv.ParseInt(bRaw, 10, strconv.IntSize)
			if err2 != nil {
				err = goa.MergeErrors(err, goa.InvalidFieldTypeError("b", bRaw, "integer"))
			}
			b = int(v)
		}
		if err != nil {
			return nil, err
		}
		payload := NewMultiplyPayload(a, b)

		return payload, nil
	}

Namely

		if a < 0 {
			err = goa.MergeErrors(err, goa.InvalidRangeError("a", a, 0, true))
		}

So if a equals zero this won't return an error (but it should as zero should be excluded by ExclusiveMinimum.

Best, Ivan

Created at 1 month ago

Update README.md

Merge pull request #7 from ryanpatrickcook/patch-1

Add Outdoorsy

Created at 2 months ago
pull request closed
Add Outdoorsy
Created at 2 months ago