gen/goav2gen/definition.go
func (a *APIAnalyzer) guessType(ec EvalCtx, d *Definition, refID string) string {
	// First get the type name and and view from the swagger reference definition
	// name -- are a few cases where that's the only place that has the view
	if t, ok := a.TypeOverrides[refID]; ok {
		return t
	}
	var name, view string
	if strings.Contains(refID, "RequestBody") {
		bits := strings.Split(refID, "RequestBody")
		name = bits[0]
		if len(bits) > 1 {
			view = strings.ToLower(bits[1])
		}
	} else if strings.Contains(refID, "ResponseBody") {
		bits := strings.Split(refID, "ResponseBody")
		name = bits[0]
		if len(bits) > 1 {
			view = strings.ToLower(bits[1])
		}
	} else {
		name = refID
	}

	// Now try and get it from the media type -- this is preferred if its set.
	if mt := mediaType(d.Title); mt != "" {
		if strings.Contains(mt, "application") {
			bits := strings.Split(mt, ".")
			name := bits[len(bits)-1]
			attrs := mediaTypeAttrs(d.Title)
			if attrs["type"] != "" {
				name += "_" + attrs["type"]
			}
			if attrs["view"] != "" && attrs["view"] != "default" {
				name += "_" + attrs["view"]
			} else if view != "" {
				name += "_" + view
			}
			dbg("DEBUG media type refID:%#v title:%#v name:%#v view:%#v -> type:%#v\n", refID, d.Title, name, view, name)
			return toTypeName(name)
		} else if strings.Contains(mt, "text/") {
			return "string"
		} else {
			fail("Don't know how to handle media type %s", mt)
		}
	}
	if view != "" {
		return name + "_" + view
	}

	return name
}
func (a *APIAnalyzer) guessType(ec EvalCtx, d *Definition, refID string) string {
	// First get the type name and and view from the swagger reference definition
	// name -- are a few cases where that's the only place that has the view
	if t, ok := a.TypeOverrides[refID]; ok {
		return t
	}
	var name, view string
	if strings.Contains(refID, "RequestBody") {
		bits := strings.Split(refID, "RequestBody")
		name = bits[0]
		if len(bits) > 1 {
			view = strings.ToLower(bits[1])
		}
	} else if strings.Contains(refID, "ResponseBody") {
		bits := strings.Split(refID, "ResponseBody")
		name = bits[0]
		if len(bits) > 1 {
			view = strings.ToLower(bits[1])
		}
	} else {
		name = refID
	}

	// Now try and get it from the media type -- this is preferred if its set.
	if mt := mediaType(d.Title); mt != "" {
		if strings.Contains(mt, "application") {
			bits := strings.Split(mt, ".")
			name := bits[len(bits)-1]
			attrs := mediaTypeAttrs(d.Title)
			if attrs["type"] != "" {
				name += "_" + attrs["type"]
			}
			if attrs["view"] != "" && attrs["view"] != "default" {
				name += "_" + attrs["view"]
			} else if view != "" {
				name += "_" + view
			}
			dbg("DEBUG media type refID:%#v title:%#v name:%#v view:%#v -> type:%#v\n", refID, d.Title, name, view, name)
			return toTypeName(name)
		} else if strings.Contains(mt, "text/") {
			return "string"
		} else {
			fail("Don't know how to handle media type %s", mt)
		}
	}
	if view != "" {
		return name + "_" + view
	}

	return name
}
// guessType tries to guess the resource name based on the definition and service.
// This info is not stored in the swagger. TBD manual overrides if needed.