Ejemplo n.º 1
0
// create a python class representations
func newPythonClass(name, description string, properties map[string]interface{}) pythonClass {
	pc := pythonClass{
		Name:        name,
		Description: commentBuilder(description),
		Fields:      map[string]pythonField{},
	}

	// generate fields
	for k, v := range properties {
		p := raml.ToProperty(k, v)
		field := pythonField{
			Name:     p.Name,
			Required: p.Required,
		}
		field.setType(p.Type)

		if field.Type == "" { // type is not supported, no need to generate the field
			continue
		}

		field.buildValidators(p)
		pc.Fields[p.Name] = field

	}
	return pc
}
Ejemplo n.º 2
0
// create new struct def
func newStructDef(name, packageName, description string, properties map[string]interface{}) structDef {
	// generate struct's fields from type properties
	fields := make(map[string]fieldDef)
	for k, v := range properties {
		prop := raml.ToProperty(k, v)
		fd := fieldDef{
			Name:      strings.Title(prop.Name),
			Type:      convertToGoType(prop.Type),
			IsOmitted: !prop.Required,
		}

		fd.buildValidators(prop)
		fields[prop.Name] = fd
	}
	return structDef{
		Name:        name,
		PackageName: packageName,
		Fields:      fields,
		Description: commons.ParseDescription(description),
	}
}
Ejemplo n.º 3
0
func newObject(name, description string, properties map[string]interface{}) (object, error) {
	// generate fields from type properties
	fields := make(map[string]field)

	for k, v := range properties {
		prop := raml.ToProperty(k, v)
		fd := field{
			Name: prop.Name,
			Type: toNimType(prop.Type),
		}
		if fd.Type == "" {
			return object{}, fmt.Errorf("unsupported type in nim:%v", prop.Type)
		}
		fields[prop.Name] = fd
	}

	return object{
		Name:        name,
		Fields:      fields,
		Description: commons.ParseDescription(description),
	}, nil
}
Ejemplo n.º 4
0
func NewStruct(t raml.Type, name, lang, pkg string) (Struct, error) {
	// generate fields from type properties
	fields := make(map[string]field)

	for k, v := range t.Properties {
		fd := newField(name, raml.ToProperty(k, v), lang, pkg)
		fields[fd.Name] = fd
	}

	s := Struct{
		ID:          getID(),
		Name:        name,
		Fields:      fields,
		Description: commons.ParseDescription(t.Description),
		T:           t,
		pkg:         pkg,
		lang:        lang,
	}
	if err := s.checkValidCapnp(); err != nil {
		return s, err
	}
	return s, s.orderFields()
}