Esempio n. 1
0
// generate Server's Go representation of RAML resources
func generateServerResources(apiDef *raml.APIDefinition, directory string) ([]resource.ResourceInterface, error) {
	var rds []resource.ResourceInterface

	rs := apiDef.Resources

	// sort the keys, so we have resource sorted by keys.
	// the generated code actually don't need it to be sorted.
	// but test fixture need it
	var keys []string
	for k := range rs {
		keys = append(keys, k)
	}
	sort.Strings(keys)

	// create resource def
	var err error
	for _, k := range keys {
		r := rs[k]
		rd := resource.New(apiDef, k, "")
		rd.IsServer = true
		pr := pythonResource{Resource: &rd}
		err = pr.generate(&r, k, directory)
		if err != nil {
			return rds, err
		}
		rds = append(rds, rd)
	}
	return rds, nil
}
Esempio n. 2
0
// NewClient creates a new Golang client
func NewClient(apiDef *raml.APIDefinition, packageName, rootImportPath string) (Client, error) {
	// rootImportPath only needed if we use libraries
	if rootImportPath == "" && len(apiDef.Libraries) > 0 {
		return Client{}, fmt.Errorf("--import-path can't be empty when we use libraries")
	}

	globRootImportPath = rootImportPath
	globAPIDef = apiDef

	services := map[string]*ClientService{}
	for k, v := range apiDef.Resources {
		rd := resource.New(apiDef, commons.NormalizeURITitle(apiDef.Title), packageName)
		rd.GenerateMethods(&v, langGo, newServerMethod, newGoClientMethod)
		services[k] = &ClientService{
			rootEndpoint: k,
			PackageName:  packageName,
			Methods:      rd.Methods,
		}
	}
	client := Client{
		apiDef:         apiDef,
		Name:           commons.NormalizeURI(apiDef.Title),
		BaseURI:        apiDef.BaseURI,
		libraries:      apiDef.Libraries,
		PackageName:    packageName,
		RootImportPath: rootImportPath,
		Services:       services,
	}

	if strings.Index(client.BaseURI, "{version}") > 0 {
		client.BaseURI = strings.Replace(client.BaseURI, "{version}", apiDef.Version, -1)
	}
	return client, nil
}
Esempio n. 3
0
func newResource(name string, apiDef *raml.APIDefinition, isServer bool) resource {
	rd := cr.New(apiDef, name, "")
	rd.IsServer = isServer
	r := resource{
		Resource: rd,
	}
	res := apiDef.Resources[name]
	r.GenerateMethods(&res, "nim", newServerMethod, newMethod)
	return r
}
Esempio n. 4
0
func newResource(name string, apiDef *raml.APIDefinition, isServer bool) pythonResource {
	rd := resource.New(apiDef, name, "")
	rd.IsServer = isServer
	r := pythonResource{
		Resource: &rd,
	}
	res := apiDef.Resources[name]
	r.GenerateMethods(&res, "python", newServerMethod, newClientMethod)
	return r
}
Esempio n. 5
0
// NewClient creates a python Client
func NewClient(apiDef *raml.APIDefinition) Client {
	services := map[string]*service{}
	for k, v := range apiDef.Resources {
		rd := resource.New(apiDef, commons.NormalizeURITitle(apiDef.Title), "")
		rd.GenerateMethods(&v, "python", newServerMethod, newClientMethod)
		services[k] = &service{
			rootEndpoint: k,
			Methods:      rd.Methods,
		}
	}
	c := Client{
		Name:     commons.NormalizeURI(apiDef.Title),
		APIDef:   apiDef,
		BaseURI:  apiDef.BaseURI,
		Services: services,
	}
	if strings.Index(c.BaseURI, "{version}") > 0 {
		c.BaseURI = strings.Replace(c.BaseURI, "{version}", apiDef.Version, -1)
	}
	return c
}