func()

in internal/azure/index.go [111:164]


func (o *Schema) UnmarshalJSON(body []byte) error {
	var m IndexRaw
	err := json.Unmarshal(body, &m)
	if err != nil {
		return err
	}
	if m.Resources == nil {
		return fmt.Errorf("resources block is nil")
	}
	if m.Functions == nil {
		return fmt.Errorf("functions block is nil")
	}
	o.Resources = make(map[string]*Resource)
	o.Functions = make(map[string]*Function)
	for k, v := range m.Resources {
		index := strings.Index(k, "@")
		if index == -1 {
			return fmt.Errorf("api-version is not specified, type: %s", k)
		}
		resourceType := k[0:index]
		resource := o.Resources[resourceType]
		if resource == nil {
			o.Resources[resourceType] = &Resource{
				Definitions: make([]*ResourceDefinition, 0),
			}
			resource = o.Resources[resourceType]
		}
		resource.Definitions = append(resource.Definitions, &ResourceDefinition{
			Definition: nil,
			Location:   v,
			ApiVersion: k[index+1:],
		})
	}
	for k, v := range m.Functions {
		for apiVersion, arr := range v {
			function := o.Functions[k]
			if function == nil {
				o.Functions[k] = &Function{
					Definitions: make([]*FunctionDefinition, 0),
				}
				function = o.Functions[k]
			}
			for _, item := range arr {
				function.Definitions = append(function.Definitions, &FunctionDefinition{
					Definition: nil,
					Location:   item,
					ApiVersion: apiVersion,
				})
			}
		}
	}

	return nil
}