コード例 #1
0
ファイル: helpers.go プロジェクト: babelrpc/babel
func parmsToSchema(pidl *idl.Idl, m *idl.Method) *swagger2.Schema {
	sc := new(swagger2.Schema)
	// sc.Title
	sc.Description = strings.Join(m.Comments, "\n")
	sc.Properties = make(map[string]swagger2.Schema)
	sc.Type = "object"
	if m.HasParameters() {
		for _, p := range m.Parameters {
			sc.Properties[p.Name] = *fieldToSchema(pidl, p)
		}
	}
	return sc
}
コード例 #2
0
ファイル: helpers.go プロジェクト: babelrpc/babel
func enumToSchema(pidl *idl.Idl, e *idl.Enum) *swagger2.Schema {
	sc := new(swagger2.Schema)
	// sc.Title = f.Name
	sc.Description = strings.Join(e.Comments, "\n")
	sc.Ref = ""
	sc.Type = "string"
	sc.Format = ""
	sc.Enum = make([]interface{}, 0)
	for _, x := range e.Values {
		sc.Enum = append(sc.Enum, x.Name)
	}
	return sc
}
コード例 #3
0
ファイル: helpers.go プロジェクト: babelrpc/babel
func fieldToSchema(pidl *idl.Idl, f *idl.Field) *swagger2.Schema {
	sc := new(swagger2.Schema)
	// sc.Title = f.Name
	sc.Description = strings.Join(f.Comments, "\n")
	it := typeToItems(pidl, f.Type)
	sc.Ref = it.Ref
	sc.Type = it.Type
	sc.Format = it.Format
	sc.ItemsDef.Items = it.Items
	sc.Enum = it.Enum
	sc.AdditionalProperties = it.AdditionalProperties
	return sc
}
コード例 #4
0
ファイル: helpers.go プロジェクト: babelrpc/babel
func returnsToSchema(pidl *idl.Idl, t *idl.Type) *swagger2.Schema {
	sc := new(swagger2.Schema)
	// sc.Title = f.Name
	if t.IsVoid() {
		// nil schema means the operation returns no content
		return nil
	} else {
		it := typeToItems(pidl, t)
		sc.Ref = it.Ref
		sc.Type = it.Type
		sc.Format = it.Format
		sc.ItemsDef.Items = it.Items
		sc.Enum = it.Enum
		sc.AdditionalProperties = it.AdditionalProperties
	}
	return sc
}
コード例 #5
0
ファイル: helpers.go プロジェクト: babelrpc/babel
func structToSchema(pidl *idl.Idl, st *idl.Struct) *swagger2.Schema {
	sc := new(swagger2.Schema)
	// sc.Title
	sc.Description = strings.Join(st.Comments, "\n")
	sc.Properties = make(map[string]swagger2.Schema)
	sc.Type = "object"
	for _, p := range st.Fields {
		sc.Properties[p.Name] = *fieldToSchema(pidl, p)
	}
	if st.Extends != "" {
		sc.AllOf = make([]swagger2.Schema, 0)

		// SWAGGER-BUG: swagger-js and swagger-ui don't support allOf. Alternate implementation below
		// see https://github.com/swagger-api/swagger-js/issues/188
		if !flatten {
			sc.AllOf = append(sc.AllOf, swagger2.Schema{ItemsDef: swagger2.ItemsDef{Ref: "#/definitions/" + st.Extends}})

			// Attach myself as second schema in AllOf
			sc2 := new(swagger2.Schema)
			sc2.Properties = sc.Properties
			sc2.Type = "object"
			sc.Type = ""
			sc.Properties = nil
			sc.AllOf = append(sc.AllOf, *sc2)
		} else {
			// Alternate implementation due to swagger bug
			bases, err := st.BaseClasses(pidl)
			if err != nil {
				panic("cannot get base classes")
			}
			// add base properties
			for _, b := range bases {
				for _, p := range b.Fields {
					sc.Properties[p.Name] = *fieldToSchema(pidl, p)
				}
			}
		}
	}

	return sc
}