Beispiel #1
0
func (ep endpoint) Validate() error {
	if ep.Name == "" {
		return fmt.Errorf("missing name")
	}

	if ep.URI == "" && ep.Abstract == false {
		return fmt.Errorf("missing URI")
	}

	exclusiveLocations := gotility.NewStringSet("json", "postField")
	foundExclusiveLocations := gotility.StringSet{}

	for _, p := range ep.Parameters {
		err := p.Validate()
		if err != nil {
			return fmt.Errorf("invalid parameter %q: %s", p.Name, err)
		}

		if exclusiveLocations.Contains(p.Location) {
			if len(foundExclusiveLocations) > 0 && !foundExclusiveLocations.Contains(p.Location) {
				return fmt.Errorf("incompatible parameter locations: can not mix %q and %q parameters",
					foundExclusiveLocations.All()[0], p.Location)
			}

			foundExclusiveLocations.Set(p.Location)
		}
	}

	return nil
}
// Packages returns an alphabetically ordered list of unique package names that are referenced by this type configuration.
func (c *TypesConfiguration) Packages(additionalPackages ...string) []string {
	packages := additionalPackages
	seenPackages := gotility.StringSet{}
	for _, additionalPackage := range additionalPackages {
		seenPackages.Set(additionalPackage)
	}

	for _, typeDef := range c.Types {
		if seenPackages.Contains(typeDef.Package) {
			continue
		}

		seenPackages.Set(typeDef.Package)
		packages = append(packages, typeDef.Package)
	}

	sort.Strings(packages)
	return packages
}
Beispiel #3
0
package gotility_test

import (
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"github.com/fgrosse/gotility"
)

var _ = Describe("StringSet", func() {
	Describe("NewStringSet", func() {
		It("should initialize a new StringSet", func() {
			s := gotility.NewStringSet("foo", "bar", "baz")
			Expect(s.All()).To(Equal([]string{"foo", "bar", "baz"}))
		})
	})

	It("should have a simple method to check if a key is set", func() {
		s := gotility.StringSet{}
		key := "test"
		Expect(s.Contains(key)).To(BeFalse())
		s.Set(key)
		Expect(s.Contains(key)).To(BeTrue())
	})
})