func (g *Generator) Generate(req *common.Req, res *common.Res) error {
	context := req.Context
	if context == nil || context.Config == nil {
		return nil
	}
	if !common.IsIn("models", context.Config.Generators...) {
		return nil
	}
	if req.Schema == nil {
		if req.SchemaStr == "" {
			return errors.New("both schema and string schema is not set")
		}
		s := &schema.Schema{}
		if err := json.Unmarshal([]byte(req.SchemaStr), s); err != nil {
			return err
		}
		req.Schema = s.Resolve(nil)
	}
	settings, ok := req.Schema.Generators.Get("models")
	if !ok {
		settings = schema.Generator{}
	}
	settings.SetNX("rootPathPrefix", "models")
	rootPathPrefix := settings.Get("rootPathPrefix").(string)
	fullPathPrefix := req.Context.Config.Target + rootPathPrefix + "/"
	settings.Set("fullPathPrefix", fullPathPrefix)
	req.Context.Config.Target = fullPathPrefix
	var outputs []common.Output
	for _, def := range common.SortedObjectSchemas(req.Schema.Definitions) {
		f, err := GenerateModel(def)
		if err != nil {
			return err
		}
		path := fmt.Sprintf(
			"%s/%s.go",
			context.Config.Target,
			strings.ToLower(def.Title),
		)
		outputs = append(outputs, common.Output{
			Content: f,
			Path:    path,
		})
		for _, funcDef := range def.Functions {
			if incoming, ok := funcDef.Properties["incoming"]; ok {
				if incoming.Type == nil {
					return fmt.Errorf("Type should be set on %+v", incoming)
				}
				if incoming.Type.(string) == "object" {
					f, err := GenerateModel(incoming)
					if err != nil {
						return err
					}
					path := fmt.Sprintf(
						"%s/%s.go",
						context.Config.Target,
						strings.ToLower(incoming.Title),
					)
					outputs = append(outputs, common.Output{
						Content: f,
						Path:    path,
					})
				}
			}
			if outgoing, ok := funcDef.Properties["outgoing"]; ok {
				if outgoing.Type == nil {
					return fmt.Errorf("Type should be set on %+v", outgoing)
				}
				if outgoing.Type.(string) == "object" {
					f, err := GenerateModel(outgoing)
					if err != nil {
						return err
					}
					path := fmt.Sprintf(
						"%s/%s.go",
						context.Config.Target,
						strings.ToLower(outgoing.Title),
					)
					outputs = append(outputs, common.Output{
						Content: f,
						Path:    path,
					})
				}
			}
		}
	}
	res.Output = outputs
	return nil
}
Generate generates models for schema
package models
import (
	"bytes"
	"encoding/json"
	"errors"
	"fmt"
	"strings"
	"text/template"
	"github.com/cihangir/gene/generators/common"
	"github.com/cihangir/gene/generators/models/constants"
	"github.com/cihangir/gene/generators/models/constructors"
	"github.com/cihangir/gene/generators/models/validators"
	"github.com/cihangir/gene/utils"
	"github.com/cihangir/schema"
)
type Generator struct{}