Esempio n. 1
0
// ParseDSL will run the DSL engine and analyze any imported `design`
// package, creating your `design.APIDefinition` along the way.
func ParseDSL() {
	// Catch any init-time errors
	dslengine.FailOnError(dslengine.Errors)

	// Catch any runtime errors, when analyzing the DSL
	dslengine.FailOnError(dslengine.Run())
}
Esempio n. 2
0
func init() {
	dslengine.Run()

	var _ = Describe("DSL execution", func() {
		Context("with global DSL definitions", func() {
			It("runs the DSL", func() {
				Ω(dslengine.Errors).Should(BeEmpty())

				Ω(Design).ShouldNot(BeNil())
				Ω(Design.Name).Should(Equal(apiName))
				Ω(Design.Description).Should(Equal(apiDescription))

				Ω(Design.Resources).Should(HaveKey(resourceName))
				Ω(Design.Resources[resourceName]).ShouldNot(BeNil())
				Ω(Design.Resources[resourceName].Name).Should(Equal(resourceName))
				Ω(Design.Resources[resourceName].Description).Should(Equal(resourceDescription))

				Ω(Design.Types).Should(HaveKey(typeName))
				Ω(Design.Types[typeName]).ShouldNot(BeNil())
				Ω(Design.Types[typeName].TypeName).Should(Equal(typeName))
				Ω(Design.Types[typeName].Description).Should(Equal(typeDescription))

				Ω(Design.MediaTypes).Should(HaveKey(mediaTypeIdentifier))
				Ω(Design.MediaTypes[mediaTypeIdentifier]).ShouldNot(BeNil())
				Ω(Design.MediaTypes[mediaTypeIdentifier].Identifier).Should(Equal(mediaTypeIdentifier))
				Ω(Design.MediaTypes[mediaTypeIdentifier].Description).Should(Equal(mediaTypeDescription))
			})
		})
	})
}
Esempio n. 3
0
			InitDesign()

			API("foo", func() {})

			var type1, type2 *UserTypeDefinition

			type1 = Type(type1Name, func() {
				Attribute(att1Name, type2)
			})
			type2 = Type(type2Name, func() {
				Attribute(att2Name, type1)
			})
		})

		JustBeforeEach(func() {
			dslengine.Run()
		})

		It("still produces the correct metadata", func() {
			Ω(dslengine.Errors).Should(BeEmpty())
			Ω(Design.Types).Should(HaveLen(2))
			t1 := Design.Types[type1Name]
			t2 := Design.Types[type2Name]
			Ω(t1).ShouldNot(BeNil())
			Ω(t2).ShouldNot(BeNil())
			Ω(t1.Type).Should(BeAssignableToTypeOf(Object{}))
			Ω(t2.Type).Should(BeAssignableToTypeOf(Object{}))
			o1 := t1.Type.(Object)
			o2 := t2.Type.(Object)
			Ω(o1).Should(HaveKey(att1Name))
			Ω(o2).Should(HaveKey(att2Name))
Esempio n. 4
0
		})

	})
})

var _ = Describe("GoTypeTransform", func() {
	var source, target *UserTypeDefinition
	var targetPkg, funcName string

	var transform string

	BeforeEach(func() {
		dslengine.Reset()
	})
	JustBeforeEach(func() {
		err := dslengine.Run()
		Ω(err).ShouldNot(HaveOccurred())
		transform, _ = codegen.GoTypeTransform(source, target, targetPkg, funcName)
	})

	Context("transforming simple objects", func() {
		const attName = "att"
		BeforeEach(func() {
			source = Type("Source", func() {
				Attribute(attName)
			})
			target = Type("Target", func() {
				Attribute(attName)
			})
			funcName = "Transform"
		})
Esempio n. 5
0
var _ = Describe("MediaType", func() {
	var name string
	var dslFunc func()

	var mt *MediaTypeDefinition

	BeforeEach(func() {
		InitDesign()
		dslengine.Errors = nil
		name = ""
		dslFunc = nil
	})

	JustBeforeEach(func() {
		mt = MediaType(name, dslFunc)
		dslengine.Run()
		Ω(dslengine.Errors).ShouldNot(HaveOccurred())
	})

	Context("with no dsl and no identifier", func() {
		It("produces an error", func() {
			Ω(mt).ShouldNot(BeNil())
			Ω(mt.Validate()).Should(HaveOccurred())
		})
	})

	Context("with no dsl", func() {
		BeforeEach(func() {
			name = "application/foo"
		})
Esempio n. 6
0
				TypeName("Mt2")
				Attributes(func() {
					Attribute("att2", mt)
				})
				Links(func() {
					Link("att2", "default")
				})
				View("default", func() {
					Attribute("att2")
					Attribute("links")
				})
				View("tiny", func() {
					Attribute("links")
				})
			})
			err := dslengine.Run()
			Ω(err).ShouldNot(HaveOccurred())
			Ω(dslengine.Errors).ShouldNot(HaveOccurred())
		})

		Context("using the default view", func() {
			BeforeEach(func() {
				view = "default"
			})

			It("returns the projected media type with links", func() {
				Ω(prErr).ShouldNot(HaveOccurred())
				Ω(projected).ShouldNot(BeNil())
				Ω(projected.Type).Should(BeAssignableToTypeOf(Object{}))
				Ω(projected.Type.ToObject()).Should(HaveKey("att"))
				l := projected.Type.ToObject()["links"]
Esempio n. 7
0
	JustBeforeEach(func() {
		s = genschema.TypeSchema(design.Design, typ)
	})

	Context("with a media type", func() {
		BeforeEach(func() {
			MediaType("application/foo.bar", func() {
				Attributes(func() {
					Attribute("bar")
				})
				View("default", func() {
					Attribute("bar")
				})
			})

			Ω(dslengine.Run()).ShouldNot(HaveOccurred())
			typ = design.Design.MediaTypes["application/foo.bar"]
		})

		It("returns a proper JSON schema type", func() {
			Ω(s).ShouldNot(BeNil())
			Ω(s.Ref).Should(Equal("#/definitions/FooBar"))
		})
	})

	Context("with a media type with self-referencing attributes", func() {
		BeforeEach(func() {
			MediaType("application/vnd.menu+json", func() {
				Attributes(func() {
					Attribute("name", design.String, "The name of an application")
					Attribute("children", CollectionOf("application/vnd.menu+json"), func() {