示例#1
0
func (s *SpecValidator) validateSchemaPropertyNames(nm string, sch spec.Schema, knowns map[string]struct{}) []dupProp {
	var dups []dupProp

	schn := nm
	schc := &sch
	if sch.Ref.GetURL() != nil {
		// gather property names
		reso, err := spec.ResolveRef(s.spec.Spec(), &sch.Ref)
		if err != nil {
			panic(err)
		}
		schc = reso
		schn = sch.Ref.String()
	}

	if len(schc.AllOf) > 0 {
		for _, chld := range schc.AllOf {
			dups = append(dups, s.validateSchemaPropertyNames(schn, chld, knowns)...)
		}
		return dups
	}

	for k := range schc.Properties {
		_, ok := knowns[k]
		if ok {
			dups = append(dups, dupProp{Name: k, Definition: schn})
		} else {
			knowns[k] = struct{}{}
		}
	}

	return dups
}
示例#2
0
func (s *SpecValidator) validateCircularAncestry(nm string, sch spec.Schema, knowns map[string]struct{}) []string {
	var ancs []string

	schn := nm
	schc := &sch
	if sch.Ref.GetURL() != nil {
		reso, err := spec.ResolveRef(s.spec.Spec(), &sch.Ref)
		if err != nil {
			panic(err)
		}
		schc = reso
		schn = sch.Ref.String()
		knowns[schn] = struct{}{}
	}

	if _, ok := knowns[schn]; ok {
		ancs = append(ancs, schn)
	}
	if len(ancs) > 0 {
		return ancs
	}

	if len(schc.AllOf) > 0 {
		for _, chld := range schc.AllOf {
			ancs = append(ancs, s.validateCircularAncestry(schn, chld, knowns)...)
			if len(ancs) > 0 {
				return ancs
			}
		}
	}

	return ancs
}
示例#3
0
func (t *typeResolver) resolveSchemaRef(schema *spec.Schema) (returns bool, result resolvedType, err error) {
	if schema.Ref.GetURL() != nil {
		returns = true
		ref, er := spec.ResolveRef(t.Doc.Spec(), &schema.Ref)
		if er != nil {
			err = er
			return
		}
		var nm = filepath.Base(schema.Ref.GetURL().Fragment)
		var tn string
		if gn, ok := ref.Extensions["x-go-name"]; ok {
			tn = gn.(string)
		} else {
			tn = swag.ToGoName(nm)
		}

		res, er := t.ResolveSchema(ref, false)
		if er != nil {
			err = er
			return
		}
		result = res
		result.GoType = tn
		if t.ModelsPackage != "" {
			result.GoType = t.ModelsPackage + "." + tn
		}
		return

	}
	return
}