当前位置: 首页>>代码示例>>Golang>>正文


Golang raml.ParseFile函数代码示例

本文整理汇总了Golang中github.com/Jumpscale/go-raml/raml.ParseFile函数的典型用法代码示例。如果您正苦于以下问题:Golang ParseFile函数的具体用法?Golang ParseFile怎么用?Golang ParseFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ParseFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestOauth2Middleware

func TestOauth2Middleware(t *testing.T) {
	Convey("oauth2 middleware", t, func() {

		targetdir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		Convey("middleware generation test", func() {
			apiDef := new(raml.APIDefinition)
			err := raml.ParseFile("../fixtures/security/dropbox.raml", apiDef)
			So(err, ShouldBeNil)

			err = generateSecurity(apiDef.SecuritySchemes, targetdir)
			So(err, ShouldBeNil)

			// oauth 2 in dropbox
			s, err := testLoadFile(filepath.Join(targetdir, "oauth2_Dropbox.py"))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile("../fixtures/security/oauth2_Dropbox.py")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

			// oauth 2 facebook
			s, err = testLoadFile(filepath.Join(targetdir, "oauth2_Facebook.py"))
			So(err, ShouldBeNil)

			tmpl, err = testLoadFile("../fixtures/security/oauth2_Facebook.py")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)
		})

		Convey("routes generation", func() {
			apiDef := new(raml.APIDefinition)
			err := raml.ParseFile("../fixtures/security/dropbox.raml", apiDef)
			So(err, ShouldBeNil)

			_, err = generateServerResources(apiDef, targetdir)
			So(err, ShouldBeNil)

			// check route
			s, err := testLoadFile(filepath.Join(targetdir, "deliveries.py"))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile("../fixtures/security/deliveries.py")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)
		})

		Reset(func() {
			os.RemoveAll(targetdir)
		})
	})
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:56,代码来源:security_test.go

示例2: TestGenerateClientFromRaml

func TestGenerateClientFromRaml(t *testing.T) {
	Convey("generate client from raml", t, func() {
		apiDef := new(raml.APIDefinition)
		err := raml.ParseFile("./fixtures/client_resources/client.raml", apiDef)
		So(err, ShouldBeNil)

		targetdir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		Convey("Simple client from raml", func() {
			err = GenerateClient(apiDef, targetdir, "theclient", "go", "client")
			So(err, ShouldBeNil)

			s, err := testLoadFile(filepath.Join(targetdir, "client_structapitest.go"))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile("./fixtures/client_resources/client_structapitest.txt")
			So(err, ShouldBeNil)

			So(tmpl, ShouldEqual, s)
		})

		Reset(func() {
			os.RemoveAll(targetdir)
		})
	})
}
开发者ID:robvanmieghem,项目名称:go-raml,代码行数:27,代码来源:client_test.go

示例3: TestPythonResource

func TestPythonResource(t *testing.T) {
	Convey("resource generator", t, func() {
		targetdir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		Convey("resource with request body", func() {
			apiDef := new(raml.APIDefinition)
			err := raml.ParseFile("../fixtures/server_resources/deliveries.raml", apiDef)
			So(err, ShouldBeNil)

			_, err = generateServerResources(apiDef, targetdir)
			So(err, ShouldBeNil)

			// check  api implementation
			s, err := testLoadFile(filepath.Join(targetdir, "deliveries.py"))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile("../fixtures/server_resources/deliveries.py")
			So(err, ShouldBeNil)
			So(s, ShouldEqual, tmpl)
		})

		Reset(func() {
			os.RemoveAll(targetdir)
		})
	})
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:27,代码来源:resources_test.go

示例4: TestGenerateClassFromBody

func TestGenerateClassFromBody(t *testing.T) {
	Convey("generate struct body from raml", t, func() {
		apiDef := new(raml.APIDefinition)
		err := raml.ParseFile("../fixtures/struct/struct.raml", apiDef)
		So(err, ShouldBeNil)

		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		Convey("python class from request/response bodies", func() {
			rs := getAllResources(apiDef, true)
			err = generateClassesFromBodies(rs, targetDir)
			So(err, ShouldBeNil)

			// req body
			s, err := testLoadFile(filepath.Join(targetDir, "UsersPostReqBody.py"))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile("../fixtures/struct/UsersPostReqBody.py")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

		})

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:30,代码来源:body_test.go

示例5: TestGenerateClientFromRaml

func TestGenerateClientFromRaml(t *testing.T) {
	Convey("generate client from raml", t, func() {
		apiDef := new(raml.APIDefinition)
		err := raml.ParseFile("./fixtures/client_resources/client.raml", apiDef)
		So(err, ShouldBeNil)

		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		err = GenerateClient(apiDef, targetDir, "theclient", "go", "client")
		So(err, ShouldBeNil)
		rootFixture := "./fixtures/client_resources"
		checks := []struct {
			Result   string
			Expected string
		}{
			{"client_structapitest.go", "client_structapitest.txt"},
			{"users_service.go", "users_service.txt"},
		}

		for _, check := range checks {
			s, err := testLoadFile(filepath.Join(targetDir, check.Result))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile(filepath.Join(rootFixture, check.Expected))
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)
		}

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:35,代码来源:client_test.go

示例6: Execute

//Execute generates a client from a RAML specification
func (command *ClientCommand) Execute() error {
	log.Debug("Generating a rest client for ", command.Language)
	apiDef := new(raml.APIDefinition)
	err := raml.ParseFile(command.RamlFile, apiDef)
	if err != nil {
		return err
	}
	return codegen.GenerateClient(apiDef, command.Dir, command.PackageName, command.Language, command.ImportPath)
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:10,代码来源:client.go

示例7: TestGenerateStructBodyFromRaml

func TestGenerateStructBodyFromRaml(t *testing.T) {
	Convey("generate struct body from raml", t, func() {
		apiDef := new(raml.APIDefinition)
		err := raml.ParseFile("./fixtures/struct/struct.raml", apiDef)
		So(err, ShouldBeNil)

		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		Convey("simple body", func() {
			err := generateBodyStructs(apiDef, targetDir, "main", langGo)
			So(err, ShouldBeNil)

			//load and compare UsersIdGetRespBody
			s, err := testLoadFile(filepath.Join(targetDir, "UsersIdGetRespBody.go"))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile("./fixtures/struct/UsersIdGetRespBody.txt")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

			//load and compare usersgetreqbody
			s, err = testLoadFile(filepath.Join(targetDir, "UsersPostReqBody.go"))
			So(err, ShouldBeNil)

			tmpl, err = testLoadFile("./fixtures/struct/UsersPostReqBody.txt")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)
		})

		Convey("python class from request/response bodies", func() {
			err = generateBodyStructs(apiDef, targetDir, "", langPython)
			So(err, ShouldBeNil)

			// req body
			s, err := testLoadFile(filepath.Join(targetDir, "UsersPostReqBody.py"))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile("./fixtures/struct/UsersPostReqBody.py")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

		})

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})
}
开发者ID:robvanmieghem,项目名称:go-raml,代码行数:52,代码来源:body_test.go

示例8: TestGeneratePythonClass

func TestGeneratePythonClass(t *testing.T) {
	Convey("generate python class from raml", t, func() {
		apiDef := new(raml.APIDefinition)
		err := raml.ParseFile("./fixtures/struct/struct.raml", apiDef)
		So(err, ShouldBeNil)
		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		Convey("python class from raml Types", func() {
			err = generatePythonClasses(apiDef.Types, targetDir)
			So(err, ShouldBeNil)

			// strings validator
			s, err := testLoadFile(filepath.Join(targetDir, "ValidationString.py"))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile("./fixtures/struct/ValidationString.py")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

			// with form field
			s, err = testLoadFile(filepath.Join(targetDir, "Cage.py"))
			So(err, ShouldBeNil)

			tmpl, err = testLoadFile("./fixtures/struct/Cage.py")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

			// FieldList of FormField
			s, err = testLoadFile(filepath.Join(targetDir, "animal.py"))
			So(err, ShouldBeNil)

			tmpl, err = testLoadFile("./fixtures/struct/animal.py")
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)

			// another test could be seen at body_test.go
		})

		Reset(func() {
			os.RemoveAll(targetDir)
		})

	})
}
开发者ID:robvanmieghem,项目名称:go-raml,代码行数:48,代码来源:class_python_test.go

示例9: Execute

//Execute generates a client from a RAML specification
func (command *CapnpCommand) Execute() error {
	var apiDef raml.APIDefinition

	command.Language = strings.ToLower(command.Language)
	if command.Language != "go" && command.Language != "plain" {
		return fmt.Errorf("canpnp generator only support plain & Go-compatible schema")
	}

	log.Debug("Generating capnp models")

	err := raml.ParseFile(command.RAMLFile, &apiDef)
	if err != nil {
		return err
	}
	return codegen.GenerateCapnp(&apiDef, command.Dir, command.Language, command.Package)
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:17,代码来源:capnp.go

示例10: TestGenerateObjectFromRaml

func TestGenerateObjectFromRaml(t *testing.T) {
	Convey("generate object from raml", t, func() {
		var apiDef raml.APIDefinition
		err := raml.ParseFile("../fixtures/struct/struct.raml", &apiDef)
		So(err, ShouldBeNil)

		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		Convey("Simple struct from raml", func() {
			err = generateObjects(apiDef.Types, targetDir)
			So(err, ShouldBeNil)

			rootFixture := "./fixtures/object/"
			checks := []struct {
				Result   string
				Expected string
			}{
				{"EnumCity.nim", "EnumCity.nim"},
				{"animal.nim", "animal.nim"},
				{"Cage.nim", "Cage.nim"},
				{"Cat.nim", "Cat.nim"},
				{"ArrayOfCats.nim", "ArrayOfCats.nim"},
				{"BidimensionalArrayOfCats.nim", "BidimensionalArrayOfCats.nim"},
			}

			for _, check := range checks {
				s, err := testLoadFile(filepath.Join(targetDir, check.Result))
				So(err, ShouldBeNil)

				tmpl, err := testLoadFile(filepath.Join(rootFixture, check.Expected))
				So(err, ShouldBeNil)

				So(s, ShouldEqual, tmpl)
			}

		})

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:43,代码来源:object_test.go

示例11: TestGeneratePythonClientFromRaml

func TestGeneratePythonClientFromRaml(t *testing.T) {
	Convey("generate python client", t, func() {
		apiDef := new(raml.APIDefinition)
		err := raml.ParseFile("./fixtures/client/client.raml", apiDef)
		So(err, ShouldBeNil)

		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		Convey("Simple client", func() {
			client := NewClient(apiDef)
			err = client.Generate(targetDir)
			So(err, ShouldBeNil)

			rootFixture := "./fixtures/client"
			// cek with generated with fixtures
			checks := []struct {
				Result   string
				Expected string
			}{
				{"client.py", "client.py"},
				{"__init__.py", "__init__.py"},
				{"client_utils.py", "client_utils.py"},
				{"users_service.py", "users_service.py"},
			}

			for _, check := range checks {
				s, err := testLoadFile(filepath.Join(targetDir, check.Result))
				So(err, ShouldBeNil)

				tmpl, err := testLoadFile(filepath.Join(rootFixture, check.Expected))
				So(err, ShouldBeNil)

				So(s, ShouldEqual, tmpl)
			}
		})

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:42,代码来源:client_test.go

示例12: TestGenerateServer

func TestGenerateServer(t *testing.T) {
	Convey("generate server from raml", t, func() {
		var apiDef raml.APIDefinition
		err := raml.ParseFile("../fixtures/server_resources/deliveries.raml", &apiDef)
		So(err, ShouldBeNil)

		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		ns := Server{
			Title:      apiDef.Title,
			APIDef:     &apiDef,
			APIDocsDir: "apidocs",
			Dir:        targetDir,
		}
		err = ns.Generate()
		So(err, ShouldBeNil)

		rootFixture := "./fixtures/server/delivery"
		checks := []struct {
			Result   string
			Expected string
		}{
			{"main.nim", "main.nim"},
			{"deliveries_api.nim", "deliveries_api.nim"},
		}

		for _, check := range checks {
			s, err := testLoadFile(filepath.Join(targetDir, check.Result))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile(filepath.Join(rootFixture, check.Expected))
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)
		}

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:42,代码来源:server_test.go

示例13: TestGenerateClient

func TestGenerateClient(t *testing.T) {
	Convey("generate client from raml", t, func() {
		var apiDef raml.APIDefinition
		err := raml.ParseFile("../fixtures/client_resources/client.raml", &apiDef)
		So(err, ShouldBeNil)

		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		client := Client{
			APIDef: &apiDef,
			Dir:    targetDir,
		}
		err = client.Generate()
		So(err, ShouldBeNil)

		rootFixture := "./fixtures/resource/client"
		checks := []struct {
			Result   string
			Expected string
		}{
			{"client.nim", "client.nim"},
			{"Users_service.nim", "Users_service.nim"},
		}

		for _, check := range checks {
			s, err := testLoadFile(filepath.Join(targetDir, check.Result))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile(filepath.Join(rootFixture, check.Expected))
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)
		}

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:40,代码来源:client_test.go

示例14: TestGenerateResourceAPI

func TestGenerateResourceAPI(t *testing.T) {
	Convey("generate object from raml", t, func() {
		var apiDef raml.APIDefinition
		err := raml.ParseFile("../fixtures/server_resources/deliveries.raml", &apiDef)
		So(err, ShouldBeNil)

		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		Convey("deliveries API", func() {
			err = generateResourceAPIs(getAllResources(&apiDef, true), targetDir)
			So(err, ShouldBeNil)

			rootFixture := "./fixtures/resource/"
			checks := []struct {
				Result   string
				Expected string
			}{
				{"deliveries_api.nim", "deliveries_api.nim"},
			}

			for _, check := range checks {
				s, err := testLoadFile(filepath.Join(targetDir, check.Result))
				So(err, ShouldBeNil)

				tmpl, err := testLoadFile(filepath.Join(rootFixture, check.Expected))
				So(err, ShouldBeNil)

				So(s, ShouldEqual, tmpl)
			}

		})

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})
}
开发者ID:Jumpscale,项目名称:go-raml,代码行数:38,代码来源:resource_test.go

示例15: TestGoLibrary

func TestGoLibrary(t *testing.T) {
	Convey("Library usage in server", t, func() {
		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		err = GenerateServer("./fixtures/libraries/api.raml", targetDir, "main", "go", "apidocs", "examples.com/ramlcode", true)
		So(err, ShouldBeNil)

		rootFixture := "./fixtures/libraries/go_server"
		checks := []struct {
			Result   string
			Expected string
		}{
			{"Place.go", "Place.txt"},
			{"dirs_api.go", "dirs_api.txt"},
			{"configs_api.go", "configs_api.txt"},
		}

		for _, check := range checks {
			s, err := testLoadFile(filepath.Join(targetDir, check.Result))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile(filepath.Join(rootFixture, check.Expected))
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)
		}

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})
	Convey("Library usage in client", t, func() {
		targetDir, err := ioutil.TempDir("", "")
		So(err, ShouldBeNil)

		apiDef := new(raml.APIDefinition)
		err = raml.ParseFile("./fixtures/libraries/api.raml", apiDef)
		So(err, ShouldBeNil)

		err = GenerateClient(apiDef, targetDir, "theclient", langGo, "examples.com/client")
		So(err, ShouldBeNil)

		rootFixture := "./fixtures/libraries/go_client"
		checks := []struct {
			Result   string
			Expected string
		}{
			{"Place.go", "Place.txt"},
			{"client_exampleapi.go", "client_exampleapi.txt"},
			{"client_utils.go", "client_utils.txt"},
		}

		for _, check := range checks {
			s, err := testLoadFile(filepath.Join(targetDir, check.Result))
			So(err, ShouldBeNil)

			tmpl, err := testLoadFile(filepath.Join(rootFixture, check.Expected))
			So(err, ShouldBeNil)

			So(s, ShouldEqual, tmpl)
		}

		Reset(func() {
			os.RemoveAll(targetDir)
		})
	})

}
开发者ID:robvanmieghem,项目名称:go-raml,代码行数:69,代码来源:libraries_go_test.go


注:本文中的github.com/Jumpscale/go-raml/raml.ParseFile函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。