// ContentType validates the content type of a request func validateContentType(allowed []string, actual string) error { if len(allowed) == 0 { return nil } mt, _, err := mime.ParseMediaType(actual) if err != nil { return errors.InvalidContentType(actual, allowed) } if swag.ContainsStringsCI(allowed, mt) { return nil } return errors.InvalidContentType(actual, allowed) }
func expandSchema(target Schema, parentRefs []string, resolver *schemaLoader) (*Schema, error) { if target.Ref.String() == "" && target.Ref.IsRoot() { debugLog("skipping expand schema for no ref and root: %v", resolver.root) return resolver.root.(*Schema), nil } // t is the new expanded schema var t *Schema for target.Ref.String() != "" { if swag.ContainsStringsCI(parentRefs, target.Ref.String()) { return &target, nil } if err := resolver.Resolve(&target.Ref, &t); err != nil { return &target, err } parentRefs = append(parentRefs, target.Ref.String()) target = *t } t, err := expandItems(target, parentRefs, resolver) if err != nil { return &target, err } target = *t for i := range target.AllOf { t, err := expandSchema(target.AllOf[i], parentRefs, resolver) if err != nil { return &target, err } target.AllOf[i] = *t } for i := range target.AnyOf { t, err := expandSchema(target.AnyOf[i], parentRefs, resolver) if err != nil { return &target, err } target.AnyOf[i] = *t } for i := range target.OneOf { t, err := expandSchema(target.OneOf[i], parentRefs, resolver) if err != nil { return &target, err } target.OneOf[i] = *t } if target.Not != nil { t, err := expandSchema(*target.Not, parentRefs, resolver) if err != nil { return &target, err } *target.Not = *t } for k := range target.Properties { t, err := expandSchema(target.Properties[k], parentRefs, resolver) if err != nil { return &target, err } target.Properties[k] = *t } if target.AdditionalProperties != nil && target.AdditionalProperties.Schema != nil { t, err := expandSchema(*target.AdditionalProperties.Schema, parentRefs, resolver) if err != nil { return &target, err } *target.AdditionalProperties.Schema = *t } for k := range target.PatternProperties { t, err := expandSchema(target.PatternProperties[k], parentRefs, resolver) if err != nil { return &target, err } target.PatternProperties[k] = *t } for k := range target.Dependencies { if target.Dependencies[k].Schema != nil { t, err := expandSchema(*target.Dependencies[k].Schema, parentRefs, resolver) if err != nil { return &target, err } *target.Dependencies[k].Schema = *t } } if target.AdditionalItems != nil && target.AdditionalItems.Schema != nil { t, err := expandSchema(*target.AdditionalItems.Schema, parentRefs, resolver) if err != nil { return &target, err } *target.AdditionalItems.Schema = *t } for k := range target.Definitions { t, err := expandSchema(target.Definitions[k], parentRefs, resolver) if err != nil { return &target, err } target.Definitions[k] = *t } return &target, nil }
func isEnabled(nm string) bool { return swag.ContainsStringsCI(enabled, nm) }
"varname": swag.ToVarName, "humanize": swag.ToHumanNameLower, "snakize": swag.ToFileName, "dasherize": swag.ToCommandName, "pluralizeFirstWord": func(arg string) string { sentence := strings.Split(arg, " ") if len(sentence) == 1 { return inflect.Pluralize(arg) } return inflect.Pluralize(sentence[0]) + " " + strings.Join(sentence[1:], " ") }, "json": asJSON, "prettyjson": asPrettyJSON, "hasInsecure": func(arg []string) bool { return swag.ContainsStringsCI(arg, "http") || swag.ContainsStringsCI(arg, "ws") }, "hasSecure": func(arg []string) bool { return swag.ContainsStringsCI(arg, "https") || swag.ContainsStringsCI(arg, "wss") }, "stripPackage": func(str, pkg string) string { parts := strings.Split(str, ".") strlen := len(parts) if strlen > 0 { return parts[strlen-1] } return str }, "dropPackage": func(str string) string { parts := strings.Split(str, ".") strlen := len(parts)