code: func (g *Generator) generateMediaTypes() (err error) {
  	var (
  		mtFile string
  		mtWr   *MediaTypesWriter
  	)
  	{
  		mtFile = filepath.Join(g.OutDir, "media_types.go")
  		mtWr, err = NewMediaTypesWriter(mtFile)
  		if err != nil {
  			return
  		}
  	}
  	defer func() {
  		mtWr.Close()
  		if err == nil {
  			err = mtWr.FormatCode()
  		}
  	}()
  	title := fmt.Sprintf("%s: Application Media Types", g.API.Context())
  	imports := []*codegen.ImportSpec{
  		codegen.SimpleImport("github.com/goadesign/goa"),
  		codegen.SimpleImport("fmt"),
  		codegen.SimpleImport("time"),
  		codegen.SimpleImport("unicode/utf8"),
  		codegen.NewImport("uuid", "github.com/gofrs/uuid"),
  	}
  	for _, v := range g.API.MediaTypes {
  		imports = codegen.AttributeImports(v.AttributeDefinition, imports, nil)
  	}
  	if err = mtWr.WriteHeader(title, g.Target, imports); err != nil {
  		return err
  	}
  	g.genfiles = append(g.genfiles, mtFile)
  	err = g.API.IterateMediaTypes(func(mt *design.MediaTypeDefinition) error {
  		if mt.IsError() {
  			return nil
  		}
  		if mt.Type.IsObject() || mt.Type.IsArray() {
  			return mtWr.Execute(mt)
  		}
  		return nil
  	})
  	return
  }
docs: // generateMediaTypes iterates through the media types and generate the data structures and
  // marshaling code.