id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens listlengths 21 1.41k | docstring stringlengths 6 2.61k | docstring_tokens listlengths 3 215 | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
125,100 | Jumpscale/go-raml | codegen/golang/struct.go | newStructDef | func newStructDef(apiDef *raml.APIDefinition, name, packageName, description string, properties map[string]interface{}) structDef {
// generate struct's fields from type properties
fields := make(map[string]fieldDef)
for k, v := range properties {
prop := raml.ToProperty(k, v)
fields[prop.Name] = newFieldDef(api... | go | func newStructDef(apiDef *raml.APIDefinition, name, packageName, description string, properties map[string]interface{}) structDef {
// generate struct's fields from type properties
fields := make(map[string]fieldDef)
for k, v := range properties {
prop := raml.ToProperty(k, v)
fields[prop.Name] = newFieldDef(api... | [
"func",
"newStructDef",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"name",
",",
"packageName",
",",
"description",
"string",
",",
"properties",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"structDef",
"{",
"// generate struct's fields from... | // create new struct definition | [
"create",
"new",
"struct",
"definition"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/struct.go#L37-L50 |
125,101 | Jumpscale/go-raml | codegen/golang/struct.go | newStructDefFromType | func newStructDefFromType(apiDef *raml.APIDefinition, t raml.Type, sName, packageName string) structDef {
sd := newStructDef(apiDef, sName, packageName, t.Description, t.Properties)
sd.T = t
// handle advanced type on raml1.0
sd.handleAdvancedType(apiDef)
return sd
} | go | func newStructDefFromType(apiDef *raml.APIDefinition, t raml.Type, sName, packageName string) structDef {
sd := newStructDef(apiDef, sName, packageName, t.Description, t.Properties)
sd.T = t
// handle advanced type on raml1.0
sd.handleAdvancedType(apiDef)
return sd
} | [
"func",
"newStructDefFromType",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"t",
"raml",
".",
"Type",
",",
"sName",
",",
"packageName",
"string",
")",
"structDef",
"{",
"sd",
":=",
"newStructDef",
"(",
"apiDef",
",",
"sName",
",",
"packageName",
... | // create struct definition from RAML Type node | [
"create",
"struct",
"definition",
"from",
"RAML",
"Type",
"node"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/struct.go#L53-L61 |
125,102 | Jumpscale/go-raml | codegen/golang/struct.go | generate | func (sd structDef) generate(dir string) error {
// generate enums
for _, f := range sd.Fields {
if f.Enum != nil {
if err := f.Enum.generate(dir); err != nil {
return err
}
}
}
if sd.Enum != nil {
return sd.Enum.generate(dir)
}
fileName := filepath.Join(dir, sd.Name+".go")
return commons.Generat... | go | func (sd structDef) generate(dir string) error {
// generate enums
for _, f := range sd.Fields {
if f.Enum != nil {
if err := f.Enum.generate(dir); err != nil {
return err
}
}
}
if sd.Enum != nil {
return sd.Enum.generate(dir)
}
fileName := filepath.Join(dir, sd.Name+".go")
return commons.Generat... | [
"func",
"(",
"sd",
"structDef",
")",
"generate",
"(",
"dir",
"string",
")",
"error",
"{",
"// generate enums",
"for",
"_",
",",
"f",
":=",
"range",
"sd",
".",
"Fields",
"{",
"if",
"f",
".",
"Enum",
"!=",
"nil",
"{",
"if",
"err",
":=",
"f",
".",
"... | // generate Go struct | [
"generate",
"Go",
"struct"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/struct.go#L64-L78 |
125,103 | Jumpscale/go-raml | codegen/golang/struct.go | Imports | func (sd structDef) Imports() []string {
ip := map[string]struct{}{}
if sd.needFmt() {
ip[`"fmt"`] = struct{}{}
}
if sd.OneLineDef == "" {
ip[`"gopkg.in/validator.v2"`] = struct{}{}
}
// libraries
for _, fd := range sd.Fields {
if fd.fieldType == "json.RawMessage" {
ip[`"encoding/json"`] = struct{}{}
... | go | func (sd structDef) Imports() []string {
ip := map[string]struct{}{}
if sd.needFmt() {
ip[`"fmt"`] = struct{}{}
}
if sd.OneLineDef == "" {
ip[`"gopkg.in/validator.v2"`] = struct{}{}
}
// libraries
for _, fd := range sd.Fields {
if fd.fieldType == "json.RawMessage" {
ip[`"encoding/json"`] = struct{}{}
... | [
"func",
"(",
"sd",
"structDef",
")",
"Imports",
"(",
")",
"[",
"]",
"string",
"{",
"ip",
":=",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
"{",
"}",
"\n\n",
"if",
"sd",
".",
"needFmt",
"(",
")",
"{",
"ip",
"[",
"`\"fmt\"`",
"]",
"=",
"struct... | // Imports returns all packages that
// need to be imported by this struct | [
"Imports",
"returns",
"all",
"packages",
"that",
"need",
"to",
"be",
"imported",
"by",
"this",
"struct"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/struct.go#L122-L141 |
125,104 | Jumpscale/go-raml | codegen/golang/struct.go | generateInputValidator | func generateInputValidator(packageName, dir string) error {
var ctx = struct {
PackageName string
}{
PackageName: packageName,
}
fileName := filepath.Join(dir, inputValidatorFileResult)
return commons.GenerateFile(ctx, inputValidatorTemplateLocation, "struct_input_validator_template", fileName, true)
} | go | func generateInputValidator(packageName, dir string) error {
var ctx = struct {
PackageName string
}{
PackageName: packageName,
}
fileName := filepath.Join(dir, inputValidatorFileResult)
return commons.GenerateFile(ctx, inputValidatorTemplateLocation, "struct_input_validator_template", fileName, true)
} | [
"func",
"generateInputValidator",
"(",
"packageName",
",",
"dir",
"string",
")",
"error",
"{",
"var",
"ctx",
"=",
"struct",
"{",
"PackageName",
"string",
"\n",
"}",
"{",
"PackageName",
":",
"packageName",
",",
"}",
"\n",
"fileName",
":=",
"filepath",
".",
... | // generate input validator helper file | [
"generate",
"input",
"validator",
"helper",
"file"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/struct.go#L254-L262 |
125,105 | Jumpscale/go-raml | codegen/golang/struct.go | needFmt | func (sd structDef) needFmt() bool {
// array type min items and max items
if sd.T.MinItems > 0 || sd.T.MaxItems > 0 {
return true
}
// unique items
for _, f := range sd.Fields {
if f.UniqueItems {
return true
}
}
return false
} | go | func (sd structDef) needFmt() bool {
// array type min items and max items
if sd.T.MinItems > 0 || sd.T.MaxItems > 0 {
return true
}
// unique items
for _, f := range sd.Fields {
if f.UniqueItems {
return true
}
}
return false
} | [
"func",
"(",
"sd",
"structDef",
")",
"needFmt",
"(",
")",
"bool",
"{",
"// array type min items and max items",
"if",
"sd",
".",
"T",
".",
"MinItems",
">",
"0",
"||",
"sd",
".",
"T",
".",
"MaxItems",
">",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
... | // true if this struct need to import 'fmt' package
// It is required by validation code,
// because validation error will need `fmt` to build error message | [
"true",
"if",
"this",
"struct",
"need",
"to",
"import",
"fmt",
"package",
"It",
"is",
"required",
"by",
"validation",
"code",
"because",
"validation",
"error",
"will",
"need",
"fmt",
"to",
"build",
"error",
"message"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/struct.go#L267-L280 |
125,106 | Jumpscale/go-raml | codegen/server.go | Generate | func (s *Server) Generate() error {
apiDef := new(raml.APIDefinition)
// parse the raml file
dir, fileName := filepath.Split(s.RAMLFile)
ramlBytes, err := raml.ParseReadFile(dir, fileName, apiDef)
if err != nil {
return err
}
var generator generator.Server
switch s.Lang {
case langGo:
generator = golang.... | go | func (s *Server) Generate() error {
apiDef := new(raml.APIDefinition)
// parse the raml file
dir, fileName := filepath.Split(s.RAMLFile)
ramlBytes, err := raml.ParseReadFile(dir, fileName, apiDef)
if err != nil {
return err
}
var generator generator.Server
switch s.Lang {
case langGo:
generator = golang.... | [
"func",
"(",
"s",
"*",
"Server",
")",
"Generate",
"(",
")",
"error",
"{",
"apiDef",
":=",
"new",
"(",
"raml",
".",
"APIDefinition",
")",
"\n",
"// parse the raml file",
"dir",
",",
"fileName",
":=",
"filepath",
".",
"Split",
"(",
"s",
".",
"RAMLFile",
... | // Generate generates API server files | [
"Generate",
"generates",
"API",
"server",
"files"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/server.go#L37-L77 |
125,107 | Jumpscale/go-raml | raml/method.go | postProcess | func (m *Method) postProcess(r *Resource, name string, traitsMap map[string]Trait, apiDef *APIDefinition) {
m.Name = name
m.inheritFromTraits(r, append(r.Is, m.Is...), traitsMap, apiDef)
r.Methods = append(r.Methods, m)
// post process the responses
resps := make(map[HTTPCode]Response)
for code, resp := range m.... | go | func (m *Method) postProcess(r *Resource, name string, traitsMap map[string]Trait, apiDef *APIDefinition) {
m.Name = name
m.inheritFromTraits(r, append(r.Is, m.Is...), traitsMap, apiDef)
r.Methods = append(r.Methods, m)
// post process the responses
resps := make(map[HTTPCode]Response)
for code, resp := range m.... | [
"func",
"(",
"m",
"*",
"Method",
")",
"postProcess",
"(",
"r",
"*",
"Resource",
",",
"name",
"string",
",",
"traitsMap",
"map",
"[",
"string",
"]",
"Trait",
",",
"apiDef",
"*",
"APIDefinition",
")",
"{",
"m",
".",
"Name",
"=",
"name",
"\n",
"m",
".... | // doing post processing that can't be done by YAML parser | [
"doing",
"post",
"processing",
"that",
"can",
"t",
"be",
"done",
"by",
"YAML",
"parser"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/method.go#L68-L83 |
125,108 | Jumpscale/go-raml | raml/method.go | inheritFromATrait | func (m *Method) inheritFromATrait(r *Resource, t *Trait, dicts map[string]interface{},
apiDef *APIDefinition) error {
dicts = initTraitDicts(r, m, dicts)
m.Description = substituteParams(m.Description, t.Description, dicts)
m.Bodies.inherit(t.Bodies, dicts, m.resourceTypeName, apiDef)
m.inheritHeaders(t.Header... | go | func (m *Method) inheritFromATrait(r *Resource, t *Trait, dicts map[string]interface{},
apiDef *APIDefinition) error {
dicts = initTraitDicts(r, m, dicts)
m.Description = substituteParams(m.Description, t.Description, dicts)
m.Bodies.inherit(t.Bodies, dicts, m.resourceTypeName, apiDef)
m.inheritHeaders(t.Header... | [
"func",
"(",
"m",
"*",
"Method",
")",
"inheritFromATrait",
"(",
"r",
"*",
"Resource",
",",
"t",
"*",
"Trait",
",",
"dicts",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"apiDef",
"*",
"APIDefinition",
")",
"error",
"{",
"dicts",
"=",
"initT... | // inherit from a trait
// dicts is map of trait parameters values | [
"inherit",
"from",
"a",
"trait",
"dicts",
"is",
"map",
"of",
"trait",
"parameters",
"values"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/method.go#L138-L159 |
125,109 | Jumpscale/go-raml | raml/method.go | inheritHeaders | func (m *Method) inheritHeaders(parents map[HTTPHeader]Header, dicts map[string]interface{}) {
m.Headers = inheritHeaders(m.Headers, parents, dicts)
} | go | func (m *Method) inheritHeaders(parents map[HTTPHeader]Header, dicts map[string]interface{}) {
m.Headers = inheritHeaders(m.Headers, parents, dicts)
} | [
"func",
"(",
"m",
"*",
"Method",
")",
"inheritHeaders",
"(",
"parents",
"map",
"[",
"HTTPHeader",
"]",
"Header",
",",
"dicts",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"m",
".",
"Headers",
"=",
"inheritHeaders",
"(",
"m",
".",
"Hea... | // inheritHeaders inherit method's headers from parent headers.
// parent headers could be from resource type or a trait | [
"inheritHeaders",
"inherit",
"method",
"s",
"headers",
"from",
"parent",
"headers",
".",
"parent",
"headers",
"could",
"be",
"from",
"resource",
"type",
"or",
"a",
"trait"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/method.go#L163-L165 |
125,110 | Jumpscale/go-raml | raml/method.go | inheritHeaders | func inheritHeaders(childs, parents map[HTTPHeader]Header, dicts map[string]interface{}) map[HTTPHeader]Header {
if len(childs) == 0 {
childs = map[HTTPHeader]Header{}
}
for name, parent := range parents {
h, ok := childs[name]
if !ok {
if optionalTraitProperty(string(name)) { // don't inherit optional pro... | go | func inheritHeaders(childs, parents map[HTTPHeader]Header, dicts map[string]interface{}) map[HTTPHeader]Header {
if len(childs) == 0 {
childs = map[HTTPHeader]Header{}
}
for name, parent := range parents {
h, ok := childs[name]
if !ok {
if optionalTraitProperty(string(name)) { // don't inherit optional pro... | [
"func",
"inheritHeaders",
"(",
"childs",
",",
"parents",
"map",
"[",
"HTTPHeader",
"]",
"Header",
",",
"dicts",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"map",
"[",
"HTTPHeader",
"]",
"Header",
"{",
"if",
"len",
"(",
"childs",
")",
"==",
... | // inheritHeaders inherits headers from parents to childs | [
"inheritHeaders",
"inherits",
"headers",
"from",
"parents",
"to",
"childs"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/method.go#L168-L187 |
125,111 | Jumpscale/go-raml | raml/method.go | inheritQueryParams | func (m *Method) inheritQueryParams(parents map[string]NamedParameter, dicts map[string]interface{}) {
if len(m.QueryParameters) == 0 {
m.QueryParameters = map[string]NamedParameter{}
}
for name, parent := range parents {
qp, ok := m.QueryParameters[name]
if !ok {
if optionalTraitProperty(string(name)) { //... | go | func (m *Method) inheritQueryParams(parents map[string]NamedParameter, dicts map[string]interface{}) {
if len(m.QueryParameters) == 0 {
m.QueryParameters = map[string]NamedParameter{}
}
for name, parent := range parents {
qp, ok := m.QueryParameters[name]
if !ok {
if optionalTraitProperty(string(name)) { //... | [
"func",
"(",
"m",
"*",
"Method",
")",
"inheritQueryParams",
"(",
"parents",
"map",
"[",
"string",
"]",
"NamedParameter",
",",
"dicts",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"if",
"len",
"(",
"m",
".",
"QueryParameters",
")",
"==",... | // inheritQueryParams inherit method's query params from parent query params.
// parent query params could be from resource type or a trait | [
"inheritQueryParams",
"inherit",
"method",
"s",
"query",
"params",
"from",
"parent",
"query",
"params",
".",
"parent",
"query",
"params",
"could",
"be",
"from",
"resource",
"type",
"or",
"a",
"trait"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/method.go#L191-L208 |
125,112 | Jumpscale/go-raml | raml/method.go | inheritProtocols | func (m *Method) inheritProtocols(parent []string) {
for _, p := range parent {
m.Protocols = appendStrNotExist(p, m.Protocols)
}
} | go | func (m *Method) inheritProtocols(parent []string) {
for _, p := range parent {
m.Protocols = appendStrNotExist(p, m.Protocols)
}
} | [
"func",
"(",
"m",
"*",
"Method",
")",
"inheritProtocols",
"(",
"parent",
"[",
"]",
"string",
")",
"{",
"for",
"_",
",",
"p",
":=",
"range",
"parent",
"{",
"m",
".",
"Protocols",
"=",
"appendStrNotExist",
"(",
"p",
",",
"m",
".",
"Protocols",
")",
"... | // inheritProtocols inherit method's protocols from parent protocols
// parent protocols could be from resource type or a trait | [
"inheritProtocols",
"inherit",
"method",
"s",
"protocols",
"from",
"parent",
"protocols",
"parent",
"protocols",
"could",
"be",
"from",
"resource",
"type",
"or",
"a",
"trait"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/method.go#L212-L216 |
125,113 | Jumpscale/go-raml | raml/method.go | inheritResponses | func (m *Method) inheritResponses(parent map[HTTPCode]Response, dicts map[string]interface{},
apiDef *APIDefinition) {
if len(m.Responses) == 0 { // allocate if needed
m.Responses = map[HTTPCode]Response{}
}
for code, rParent := range parent {
resp, ok := m.Responses[code]
if !ok {
if optionalTraitProperty... | go | func (m *Method) inheritResponses(parent map[HTTPCode]Response, dicts map[string]interface{},
apiDef *APIDefinition) {
if len(m.Responses) == 0 { // allocate if needed
m.Responses = map[HTTPCode]Response{}
}
for code, rParent := range parent {
resp, ok := m.Responses[code]
if !ok {
if optionalTraitProperty... | [
"func",
"(",
"m",
"*",
"Method",
")",
"inheritResponses",
"(",
"parent",
"map",
"[",
"HTTPCode",
"]",
"Response",
",",
"dicts",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"apiDef",
"*",
"APIDefinition",
")",
"{",
"if",
"len",
"(",
"m",
".... | // inheritResponses inherit method's responses from parent responses
// parent responses could be from resource type or a trait | [
"inheritResponses",
"inherit",
"method",
"s",
"responses",
"from",
"parent",
"responses",
"parent",
"responses",
"could",
"be",
"from",
"resource",
"type",
"or",
"a",
"trait"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/method.go#L220-L237 |
125,114 | Jumpscale/go-raml | raml/method.go | inherit | func (resp *Response) inherit(parent Response, dicts map[string]interface{}, rtName string,
apiDef *APIDefinition) {
resp.Description = substituteParams(resp.Description, parent.Description, dicts)
resp.Bodies.inherit(parent.Bodies, dicts, rtName, apiDef)
resp.Headers = inheritHeaders(resp.Headers, parent.Headers, ... | go | func (resp *Response) inherit(parent Response, dicts map[string]interface{}, rtName string,
apiDef *APIDefinition) {
resp.Description = substituteParams(resp.Description, parent.Description, dicts)
resp.Bodies.inherit(parent.Bodies, dicts, rtName, apiDef)
resp.Headers = inheritHeaders(resp.Headers, parent.Headers, ... | [
"func",
"(",
"resp",
"*",
"Response",
")",
"inherit",
"(",
"parent",
"Response",
",",
"dicts",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"rtName",
"string",
",",
"apiDef",
"*",
"APIDefinition",
")",
"{",
"resp",
".",
"Description",
"=",
"s... | // inherit from parent response | [
"inherit",
"from",
"parent",
"response"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/method.go#L270-L275 |
125,115 | Jumpscale/go-raml | raml/method.go | inherit | func (b *Bodies) inherit(parent Bodies, dicts map[string]interface{}, rtName string, apiDef *APIDefinition) {
b.Schema = substituteParams(b.Schema, parent.Schema, dicts)
b.Description = substituteParams(b.Description, parent.Description, dicts)
b.Example = substituteParams(b.Example, parent.Example, dicts)
b.Type ... | go | func (b *Bodies) inherit(parent Bodies, dicts map[string]interface{}, rtName string, apiDef *APIDefinition) {
b.Schema = substituteParams(b.Schema, parent.Schema, dicts)
b.Description = substituteParams(b.Description, parent.Description, dicts)
b.Example = substituteParams(b.Example, parent.Example, dicts)
b.Type ... | [
"func",
"(",
"b",
"*",
"Bodies",
")",
"inherit",
"(",
"parent",
"Bodies",
",",
"dicts",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"rtName",
"string",
",",
"apiDef",
"*",
"APIDefinition",
")",
"{",
"b",
".",
"Schema",
"=",
"substituteParams... | // inherit inherits bodies properties from a parent bodies
// parent object could be from trait or response type | [
"inherit",
"inherits",
"bodies",
"properties",
"from",
"a",
"parent",
"bodies",
"parent",
"object",
"could",
"be",
"from",
"trait",
"or",
"response",
"type"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/method.go#L363-L404 |
125,116 | Jumpscale/go-raml | codegen/resource/url.go | HasCatchAllInRootRoute | func HasCatchAllInRootRoute(apiDef *raml.APIDefinition) bool {
rootCatchAllRoute := "/" + CatchAllRoute
for endpoint := range apiDef.Resources {
if endpoint == rootCatchAllRoute {
return true
}
}
return false
} | go | func HasCatchAllInRootRoute(apiDef *raml.APIDefinition) bool {
rootCatchAllRoute := "/" + CatchAllRoute
for endpoint := range apiDef.Resources {
if endpoint == rootCatchAllRoute {
return true
}
}
return false
} | [
"func",
"HasCatchAllInRootRoute",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
")",
"bool",
"{",
"rootCatchAllRoute",
":=",
"\"",
"\"",
"+",
"CatchAllRoute",
"\n",
"for",
"endpoint",
":=",
"range",
"apiDef",
".",
"Resources",
"{",
"if",
"endpoint",
"==",
... | // HasCatchAllInRootRoute returns true if the given
// raml api definition has catch all route as root endpoint | [
"HasCatchAllInRootRoute",
"returns",
"true",
"if",
"the",
"given",
"raml",
"api",
"definition",
"has",
"catch",
"all",
"route",
"as",
"root",
"endpoint"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/resource/url.go#L18-L26 |
125,117 | Jumpscale/go-raml | docs/tutorial/go/client/goramldir/client_utils.go | doReqWithBody | func (c goramldir) doReqWithBody(method, urlStr string, data interface{}, headers, queryParams map[string]interface{}) (*http.Response, error) {
body, err := encodeBody(data)
if err != nil {
return nil, err
}
return c.doReq(method, urlStr, body, headers, queryParams)
} | go | func (c goramldir) doReqWithBody(method, urlStr string, data interface{}, headers, queryParams map[string]interface{}) (*http.Response, error) {
body, err := encodeBody(data)
if err != nil {
return nil, err
}
return c.doReq(method, urlStr, body, headers, queryParams)
} | [
"func",
"(",
"c",
"goramldir",
")",
"doReqWithBody",
"(",
"method",
",",
"urlStr",
"string",
",",
"data",
"interface",
"{",
"}",
",",
"headers",
",",
"queryParams",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"*",
"http",
".",
"Response... | // do HTTP request with request body | [
"do",
"HTTP",
"request",
"with",
"request",
"body"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/docs/tutorial/go/client/goramldir/client_utils.go#L22-L28 |
125,118 | Jumpscale/go-raml | docs/tutorial/go/client/goramldir/client_utils.go | doReqNoBody | func (c goramldir) doReqNoBody(method, urlStr string, headers, queryParams map[string]interface{}) (*http.Response, error) {
return c.doReq(method, urlStr, nil, headers, queryParams)
} | go | func (c goramldir) doReqNoBody(method, urlStr string, headers, queryParams map[string]interface{}) (*http.Response, error) {
return c.doReq(method, urlStr, nil, headers, queryParams)
} | [
"func",
"(",
"c",
"goramldir",
")",
"doReqNoBody",
"(",
"method",
",",
"urlStr",
"string",
",",
"headers",
",",
"queryParams",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"return",
... | // do http request without request body | [
"do",
"http",
"request",
"without",
"request",
"body"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/docs/tutorial/go/client/goramldir/client_utils.go#L31-L33 |
125,119 | Jumpscale/go-raml | codegen/docs.go | GenerateDocs | func GenerateDocs(apiDef *raml.APIDefinition, format, output string) error {
switch format {
case formatMarkdown:
md := &markdownDocs{
api: apiDef,
output: output,
}
return md.generate()
default:
return fmt.Errorf("unknown format '%s'", format)
}
} | go | func GenerateDocs(apiDef *raml.APIDefinition, format, output string) error {
switch format {
case formatMarkdown:
md := &markdownDocs{
api: apiDef,
output: output,
}
return md.generate()
default:
return fmt.Errorf("unknown format '%s'", format)
}
} | [
"func",
"GenerateDocs",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"format",
",",
"output",
"string",
")",
"error",
"{",
"switch",
"format",
"{",
"case",
"formatMarkdown",
":",
"md",
":=",
"&",
"markdownDocs",
"{",
"api",
":",
"apiDef",
",",
... | // GenerateDocs generate markdown docs from RAML specs | [
"GenerateDocs",
"generate",
"markdown",
"docs",
"from",
"RAML",
"specs"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/docs.go#L13-L24 |
125,120 | Jumpscale/go-raml | codegen/resource/method.go | VerbTitle | func (m Method) VerbTitle() string {
return strings.Title(strings.ToLower(m.verb))
} | go | func (m Method) VerbTitle() string {
return strings.Title(strings.ToLower(m.verb))
} | [
"func",
"(",
"m",
"Method",
")",
"VerbTitle",
"(",
")",
"string",
"{",
"return",
"strings",
".",
"Title",
"(",
"strings",
".",
"ToLower",
"(",
"m",
".",
"verb",
")",
")",
"\n",
"}"
] | // VerbTitle returns HTTP Verb of this method in title format | [
"VerbTitle",
"returns",
"HTTP",
"Verb",
"of",
"this",
"method",
"in",
"title",
"format"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/resource/method.go#L27-L29 |
125,121 | Jumpscale/go-raml | codegen/capnp/struct.go | Generate | func (s *Struct) Generate(dir string) error {
if s.Enum != nil {
return s.Enum.generate(dir)
}
if err := s.generateEnums(dir); err != nil {
return err
}
filename := filepath.Join(dir, s.Name+".capnp")
return commons.GenerateFile(s, "./templates/capnp/struct_capnp.tmpl", "struct_capnp", filename, true)
} | go | func (s *Struct) Generate(dir string) error {
if s.Enum != nil {
return s.Enum.generate(dir)
}
if err := s.generateEnums(dir); err != nil {
return err
}
filename := filepath.Join(dir, s.Name+".capnp")
return commons.GenerateFile(s, "./templates/capnp/struct_capnp.tmpl", "struct_capnp", filename, true)
} | [
"func",
"(",
"s",
"*",
"Struct",
")",
"Generate",
"(",
"dir",
"string",
")",
"error",
"{",
"if",
"s",
".",
"Enum",
"!=",
"nil",
"{",
"return",
"s",
".",
"Enum",
".",
"generate",
"(",
"dir",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"s",
".",
... | // Generate generates struct code | [
"Generate",
"generates",
"struct",
"code"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/capnp/struct.go#L61-L71 |
125,122 | Jumpscale/go-raml | codegen/capnp/struct.go | generateEnums | func (s *Struct) generateEnums(dir string) error {
for _, f := range s.Fields {
if f.Enum == nil {
continue
}
if err := f.Enum.generate(dir); err != nil {
return err
}
}
return nil
} | go | func (s *Struct) generateEnums(dir string) error {
for _, f := range s.Fields {
if f.Enum == nil {
continue
}
if err := f.Enum.generate(dir); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"Struct",
")",
"generateEnums",
"(",
"dir",
"string",
")",
"error",
"{",
"for",
"_",
",",
"f",
":=",
"range",
"s",
".",
"Fields",
"{",
"if",
"f",
".",
"Enum",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"err",
":... | // generate all enums contained in this struct | [
"generate",
"all",
"enums",
"contained",
"in",
"this",
"struct"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/capnp/struct.go#L74-L84 |
125,123 | Jumpscale/go-raml | raml/jsonschema.go | NewJSONSchema | func NewJSONSchema(t Type, name string) JSONSchema {
typ := t.TypeString()
if typ == "" || t.Type == nil {
typ = "object"
}
return NewJSONSchemaFromProps(&t, t.Properties, typ, name)
} | go | func NewJSONSchema(t Type, name string) JSONSchema {
typ := t.TypeString()
if typ == "" || t.Type == nil {
typ = "object"
}
return NewJSONSchemaFromProps(&t, t.Properties, typ, name)
} | [
"func",
"NewJSONSchema",
"(",
"t",
"Type",
",",
"name",
"string",
")",
"JSONSchema",
"{",
"typ",
":=",
"t",
".",
"TypeString",
"(",
")",
"\n",
"if",
"typ",
"==",
"\"",
"\"",
"||",
"t",
".",
"Type",
"==",
"nil",
"{",
"typ",
"=",
"\"",
"\"",
"\n",
... | // NewJSONSchema creates JSON schema from an raml type | [
"NewJSONSchema",
"creates",
"JSON",
"schema",
"from",
"an",
"raml",
"type"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/jsonschema.go#L32-L39 |
125,124 | Jumpscale/go-raml | raml/jsonschema.go | NewJSONSchemaFromProps | func NewJSONSchemaFromProps(t *Type, properties map[string]interface{}, typ, name string) JSONSchema {
var required []string
if isTypeArray(typ) {
return newArraySchema(t, typ, name)
}
props := make(map[string]property, len(properties))
for name := range properties {
rp := t.GetProperty(name)
if !isPropTyp... | go | func NewJSONSchemaFromProps(t *Type, properties map[string]interface{}, typ, name string) JSONSchema {
var required []string
if isTypeArray(typ) {
return newArraySchema(t, typ, name)
}
props := make(map[string]property, len(properties))
for name := range properties {
rp := t.GetProperty(name)
if !isPropTyp... | [
"func",
"NewJSONSchemaFromProps",
"(",
"t",
"*",
"Type",
",",
"properties",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"typ",
",",
"name",
"string",
")",
"JSONSchema",
"{",
"var",
"required",
"[",
"]",
"string",
"\n\n",
"if",
"isTypeArray",
"... | // NewJSONSchemaFromProps creates json schmema
// from a map of properties | [
"NewJSONSchemaFromProps",
"creates",
"json",
"schmema",
"from",
"a",
"map",
"of",
"properties"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/jsonschema.go#L43-L81 |
125,125 | Jumpscale/go-raml | raml/jsonschema.go | Inherit | func (js *JSONSchema) Inherit(parents []JSONSchema) {
// inherit `properties` and `required`
// only inherit if the property name not exist in
// child properties
oriProps := map[string]interface{}{}
for name, prop := range js.Properties {
oriProps[name] = prop
}
for _, parent := range parents {
for name, p... | go | func (js *JSONSchema) Inherit(parents []JSONSchema) {
// inherit `properties` and `required`
// only inherit if the property name not exist in
// child properties
oriProps := map[string]interface{}{}
for name, prop := range js.Properties {
oriProps[name] = prop
}
for _, parent := range parents {
for name, p... | [
"func",
"(",
"js",
"*",
"JSONSchema",
")",
"Inherit",
"(",
"parents",
"[",
"]",
"JSONSchema",
")",
"{",
"// inherit `properties` and `required`",
"// only inherit if the property name not exist in",
"// child properties",
"oriProps",
":=",
"map",
"[",
"string",
"]",
"in... | // Inherit inherits JSON schema from the parents | [
"Inherit",
"inherits",
"JSON",
"schema",
"from",
"the",
"parents"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/jsonschema.go#L84-L108 |
125,126 | Jumpscale/go-raml | raml/jsonschema.go | RAMLProperties | func (js *JSONSchema) RAMLProperties() map[string]interface{} {
js.PostUnmarshal()
props := map[string]interface{}{}
for name, prop := range js.Properties {
props[name] = prop.toRAMLProperty()
}
return props
} | go | func (js *JSONSchema) RAMLProperties() map[string]interface{} {
js.PostUnmarshal()
props := map[string]interface{}{}
for name, prop := range js.Properties {
props[name] = prop.toRAMLProperty()
}
return props
} | [
"func",
"(",
"js",
"*",
"JSONSchema",
")",
"RAMLProperties",
"(",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"js",
".",
"PostUnmarshal",
"(",
")",
"\n",
"props",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n... | // RAMLProperties returns all raml property
// of this JSON schema | [
"RAMLProperties",
"returns",
"all",
"raml",
"property",
"of",
"this",
"JSON",
"schema"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/jsonschema.go#L129-L136 |
125,127 | Jumpscale/go-raml | codegen/python/sanic_server.go | NewSanicServer | func NewSanicServer(apiDef *raml.APIDefinition, apiDocsDir, targetDir string, withMain bool,
libRootURLs []string) *SanicServer {
var prs []pythonResource
for _, rd := range getServerResourcesDefs(apiDef) {
pr := newResource(rd, apiDef, serverKindSanic)
prs = append(prs, pr)
}
// TODO : get rid of this global... | go | func NewSanicServer(apiDef *raml.APIDefinition, apiDocsDir, targetDir string, withMain bool,
libRootURLs []string) *SanicServer {
var prs []pythonResource
for _, rd := range getServerResourcesDefs(apiDef) {
pr := newResource(rd, apiDef, serverKindSanic)
prs = append(prs, pr)
}
// TODO : get rid of this global... | [
"func",
"NewSanicServer",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"apiDocsDir",
",",
"targetDir",
"string",
",",
"withMain",
"bool",
",",
"libRootURLs",
"[",
"]",
"string",
")",
"*",
"SanicServer",
"{",
"var",
"prs",
"[",
"]",
"pythonResource"... | // NewSanicServer creates new sanic server from an RAML file | [
"NewSanicServer",
"creates",
"new",
"sanic",
"server",
"from",
"an",
"RAML",
"file"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/python/sanic_server.go#L23-L46 |
125,128 | Jumpscale/go-raml | codegen/nim/object.go | newObjectFromType | func newObjectFromType(t raml.Type, name string) object {
obj := newObject(name, t.Description, t.Properties)
obj.T = t
obj.handleAdvancedType()
return obj
} | go | func newObjectFromType(t raml.Type, name string) object {
obj := newObject(name, t.Description, t.Properties)
obj.T = t
obj.handleAdvancedType()
return obj
} | [
"func",
"newObjectFromType",
"(",
"t",
"raml",
".",
"Type",
",",
"name",
"string",
")",
"object",
"{",
"obj",
":=",
"newObject",
"(",
"name",
",",
"t",
".",
"Description",
",",
"t",
".",
"Properties",
")",
"\n",
"obj",
".",
"T",
"=",
"t",
"\n",
"ob... | // create new object from an RAML type | [
"create",
"new",
"object",
"from",
"an",
"RAML",
"type"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/nim/object.go#L122-L127 |
125,129 | Jumpscale/go-raml | codegen/nim/object.go | generate | func (o *object) generate(dir string) error {
o.handleAdvancedType()
// generate enums
for _, f := range o.Fields {
if f.Enum != nil {
if err := f.Enum.generate(dir); err != nil {
return err
}
}
}
if o.Enum != nil {
return o.Enum.generate(dir)
}
filename := filepath.Join(dir, o.Name()+".nim")
... | go | func (o *object) generate(dir string) error {
o.handleAdvancedType()
// generate enums
for _, f := range o.Fields {
if f.Enum != nil {
if err := f.Enum.generate(dir); err != nil {
return err
}
}
}
if o.Enum != nil {
return o.Enum.generate(dir)
}
filename := filepath.Join(dir, o.Name()+".nim")
... | [
"func",
"(",
"o",
"*",
"object",
")",
"generate",
"(",
"dir",
"string",
")",
"error",
"{",
"o",
".",
"handleAdvancedType",
"(",
")",
"\n\n",
"// generate enums",
"for",
"_",
",",
"f",
":=",
"range",
"o",
".",
"Fields",
"{",
"if",
"f",
".",
"Enum",
... | // generate nim object representation | [
"generate",
"nim",
"object",
"representation"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/nim/object.go#L147-L167 |
125,130 | Jumpscale/go-raml | codegen/nim/object.go | handleAdvancedType | func (o *object) handleAdvancedType() {
strType := o.T.TypeString()
parents, isMultipleInheritance := o.T.MultipleInheritance()
switch {
case isMultipleInheritance: //multiple inheritance
o.inherit(parents)
case o.T.IsEnum():
o.makeEnum()
case strType == "object" || strType == "": // plain type
case o.T.IsA... | go | func (o *object) handleAdvancedType() {
strType := o.T.TypeString()
parents, isMultipleInheritance := o.T.MultipleInheritance()
switch {
case isMultipleInheritance: //multiple inheritance
o.inherit(parents)
case o.T.IsEnum():
o.makeEnum()
case strType == "object" || strType == "": // plain type
case o.T.IsA... | [
"func",
"(",
"o",
"*",
"object",
")",
"handleAdvancedType",
"(",
")",
"{",
"strType",
":=",
"o",
".",
"T",
".",
"TypeString",
"(",
")",
"\n\n",
"parents",
",",
"isMultipleInheritance",
":=",
"o",
".",
"T",
".",
"MultipleInheritance",
"(",
")",
"\n",
"s... | // handle RAML advanced data type | [
"handle",
"RAML",
"advanced",
"data",
"type"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/nim/object.go#L198-L211 |
125,131 | Jumpscale/go-raml | codegen/nim/object.go | objectRegistered | func objectRegistered(objName string) (string, bool) {
objName = extractTypeName(objName)
_, ok := objectsRegister[objName]
return objName, ok
} | go | func objectRegistered(objName string) (string, bool) {
objName = extractTypeName(objName)
_, ok := objectsRegister[objName]
return objName, ok
} | [
"func",
"objectRegistered",
"(",
"objName",
"string",
")",
"(",
"string",
",",
"bool",
")",
"{",
"objName",
"=",
"extractTypeName",
"(",
"objName",
")",
"\n",
"_",
",",
"ok",
":=",
"objectsRegister",
"[",
"objName",
"]",
"\n",
"return",
"objName",
",",
"... | // check if an object named `objName` has been generated | [
"check",
"if",
"an",
"object",
"named",
"objName",
"has",
"been",
"generated"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/nim/object.go#L262-L266 |
125,132 | Jumpscale/go-raml | codegen/nim/object.go | extractTypeName | func extractTypeName(tip string) string {
// trim all spaces
tip = strings.TrimSpace(tip)
// detect array
if strings.Index(tip, "]") < 0 {
return tip
}
// find type inside square bracket
inBracket := reSquareBracket.FindString(tip)
if inBracket == "" {
return tip
}
last := strings.LastIndex(inBracket, "... | go | func extractTypeName(tip string) string {
// trim all spaces
tip = strings.TrimSpace(tip)
// detect array
if strings.Index(tip, "]") < 0 {
return tip
}
// find type inside square bracket
inBracket := reSquareBracket.FindString(tip)
if inBracket == "" {
return tip
}
last := strings.LastIndex(inBracket, "... | [
"func",
"extractTypeName",
"(",
"tip",
"string",
")",
"string",
"{",
"// trim all spaces",
"tip",
"=",
"strings",
".",
"TrimSpace",
"(",
"tip",
")",
"\n\n",
"// detect array",
"if",
"strings",
".",
"Index",
"(",
"tip",
",",
"\"",
"\"",
")",
"<",
"0",
"{"... | // extract type name from potentially complex type declaration | [
"extract",
"type",
"name",
"from",
"potentially",
"complex",
"type",
"declaration"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/nim/object.go#L269-L286 |
125,133 | Jumpscale/go-raml | codegen/golang/client_service.go | libImportPaths | func (cs ClientService) libImportPaths() map[string]struct{} {
ip := map[string]struct{}{}
var needImportGoraml bool
// methods
for _, gm := range cs.Methods {
for lib := range gm.libImported(globRootImportPath) {
ip[lib] = struct{}{}
}
if !needImportGoraml {
needImportGoraml = gm.needImportGoraml()
... | go | func (cs ClientService) libImportPaths() map[string]struct{} {
ip := map[string]struct{}{}
var needImportGoraml bool
// methods
for _, gm := range cs.Methods {
for lib := range gm.libImported(globRootImportPath) {
ip[lib] = struct{}{}
}
if !needImportGoraml {
needImportGoraml = gm.needImportGoraml()
... | [
"func",
"(",
"cs",
"ClientService",
")",
"libImportPaths",
"(",
")",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
"{",
"ip",
":=",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
"{",
"}",
"\n\n",
"var",
"needImportGoraml",
"bool",
"\n",
"// methods",... | // LibImportPaths returns all imported lib | [
"LibImportPaths",
"returns",
"all",
"imported",
"lib"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/client_service.go#L52-L69 |
125,134 | Jumpscale/go-raml | codegen/golang/libraries.go | newGoLibrary | func newGoLibrary(name string, lib *raml.Library, parentDir, rootTargetDir string,
libRootURLs []string) *goLibrary {
gl := &goLibrary{
Library: lib,
PackageName: commons.NormalizePkgName(name),
parentDir: parentDir,
rootTargetDir: rootTargetDir,
libRootURLs: libRootURLs,
name: name... | go | func newGoLibrary(name string, lib *raml.Library, parentDir, rootTargetDir string,
libRootURLs []string) *goLibrary {
gl := &goLibrary{
Library: lib,
PackageName: commons.NormalizePkgName(name),
parentDir: parentDir,
rootTargetDir: rootTargetDir,
libRootURLs: libRootURLs,
name: name... | [
"func",
"newGoLibrary",
"(",
"name",
"string",
",",
"lib",
"*",
"raml",
".",
"Library",
",",
"parentDir",
",",
"rootTargetDir",
"string",
",",
"libRootURLs",
"[",
"]",
"string",
")",
"*",
"goLibrary",
"{",
"gl",
":=",
"&",
"goLibrary",
"{",
"Library",
":... | // create new library instance | [
"create",
"new",
"library",
"instance"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/libraries.go#L34-L45 |
125,135 | Jumpscale/go-raml | codegen/golang/libraries.go | targetDir | func (gl *goLibrary) targetDir() string {
baseDir := gl.parentDir
if libraries.IsRemote(gl.Filename) {
baseDir = gl.rootTargetDir
}
fileDir := goLibPackageDir(gl.name, libraries.StripLibRootURL(gl.Filename, gl.libRootURLs))
return filepath.Join(baseDir, fileDir)
} | go | func (gl *goLibrary) targetDir() string {
baseDir := gl.parentDir
if libraries.IsRemote(gl.Filename) {
baseDir = gl.rootTargetDir
}
fileDir := goLibPackageDir(gl.name, libraries.StripLibRootURL(gl.Filename, gl.libRootURLs))
return filepath.Join(baseDir, fileDir)
} | [
"func",
"(",
"gl",
"*",
"goLibrary",
")",
"targetDir",
"(",
")",
"string",
"{",
"baseDir",
":=",
"gl",
".",
"parentDir",
"\n",
"if",
"libraries",
".",
"IsRemote",
"(",
"gl",
".",
"Filename",
")",
"{",
"baseDir",
"=",
"gl",
".",
"rootTargetDir",
"\n",
... | // target dir of this go library | [
"target",
"dir",
"of",
"this",
"go",
"library"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/libraries.go#L48-L57 |
125,136 | Jumpscale/go-raml | codegen/golang/libraries.go | libImportPath | func libImportPath(rootImportPath, typ string, libRootURLs []string) string {
// all library use '.',
// return nothing if it is not a library
if strings.Index(typ, ".") < 0 {
return ""
}
if strings.Index(typ, "json.RawMessage") >= 0 {
return `"encoding/json"`
}
// library name in the current document
lib... | go | func libImportPath(rootImportPath, typ string, libRootURLs []string) string {
// all library use '.',
// return nothing if it is not a library
if strings.Index(typ, ".") < 0 {
return ""
}
if strings.Index(typ, "json.RawMessage") >= 0 {
return `"encoding/json"`
}
// library name in the current document
lib... | [
"func",
"libImportPath",
"(",
"rootImportPath",
",",
"typ",
"string",
",",
"libRootURLs",
"[",
"]",
"string",
")",
"string",
"{",
"// all library use '.',",
"// return nothing if it is not a library",
"if",
"strings",
".",
"Index",
"(",
"typ",
",",
"\"",
"\"",
")"... | // get library import path from a type | [
"get",
"library",
"import",
"path",
"from",
"a",
"type"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/libraries.go#L94-L123 |
125,137 | Jumpscale/go-raml | codegen/golang/libraries.go | goLibPackageDir | func goLibPackageDir(name, filename string) string {
dir := filepath.Join(filepath.Dir(filename), name)
// escape last dir element
elems := strings.Split(dir, "/")
elems[len(elems)-1] = commons.NormalizeIdentifier(elems[len(elems)-1])
return strings.Join(elems, "/")
} | go | func goLibPackageDir(name, filename string) string {
dir := filepath.Join(filepath.Dir(filename), name)
// escape last dir element
elems := strings.Split(dir, "/")
elems[len(elems)-1] = commons.NormalizeIdentifier(elems[len(elems)-1])
return strings.Join(elems, "/")
} | [
"func",
"goLibPackageDir",
"(",
"name",
",",
"filename",
"string",
")",
"string",
"{",
"dir",
":=",
"filepath",
".",
"Join",
"(",
"filepath",
".",
"Dir",
"(",
"filename",
")",
",",
"name",
")",
"\n\n",
"// escape last dir element",
"elems",
":=",
"strings",
... | // returns Go package directory of a library
// name is library name. filename is library file name.
// for the rule, see comment of `type goLibrary struct` | [
"returns",
"Go",
"package",
"directory",
"of",
"a",
"library",
"name",
"is",
"library",
"name",
".",
"filename",
"is",
"library",
"file",
"name",
".",
"for",
"the",
"rule",
"see",
"comment",
"of",
"type",
"goLibrary",
"struct"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/libraries.go#L142-L149 |
125,138 | Jumpscale/go-raml | codegen/golang/client_method.go | ReturnTypes | func (gcm clientMethod) ReturnTypes() string {
var types []string
for _, resp := range gcm.SuccessRespBodyTypes() {
types = append(types, resp.Type())
}
types = append(types, []string{"*http.Response", "error"}...)
return fmt.Sprintf("(%v)", strings.Join(types, ","))
} | go | func (gcm clientMethod) ReturnTypes() string {
var types []string
for _, resp := range gcm.SuccessRespBodyTypes() {
types = append(types, resp.Type())
}
types = append(types, []string{"*http.Response", "error"}...)
return fmt.Sprintf("(%v)", strings.Join(types, ","))
} | [
"func",
"(",
"gcm",
"clientMethod",
")",
"ReturnTypes",
"(",
")",
"string",
"{",
"var",
"types",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"resp",
":=",
"range",
"gcm",
".",
"SuccessRespBodyTypes",
"(",
")",
"{",
"types",
"=",
"append",
"(",
"types",
... | // ReturnTypes returns all types returned by this method | [
"ReturnTypes",
"returns",
"all",
"types",
"returned",
"by",
"this",
"method"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/client_method.go#L83-L91 |
125,139 | Jumpscale/go-raml | codegen/nim/client.go | NewClient | func NewClient(apiDef *raml.APIDefinition, dir string) Client {
return Client{
APIDef: apiDef,
Dir: dir,
}
} | go | func NewClient(apiDef *raml.APIDefinition, dir string) Client {
return Client{
APIDef: apiDef,
Dir: dir,
}
} | [
"func",
"NewClient",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"dir",
"string",
")",
"Client",
"{",
"return",
"Client",
"{",
"APIDef",
":",
"apiDef",
",",
"Dir",
":",
"dir",
",",
"}",
"\n",
"}"
] | // NewClient creates a new Nim client | [
"NewClient",
"creates",
"a",
"new",
"Nim",
"client"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/nim/client.go#L19-L24 |
125,140 | Jumpscale/go-raml | codegen/nim/client.go | Generate | func (c *Client) Generate() error {
rs := getAllResources(c.APIDef, false)
if err := generateAllObjects(c.APIDef, c.Dir); err != nil {
return err
}
// services files
if err := c.generateServices(rs); err != nil {
return err
}
if err := c.generateSecurity(); err != nil {
return err
}
// main client file... | go | func (c *Client) Generate() error {
rs := getAllResources(c.APIDef, false)
if err := generateAllObjects(c.APIDef, c.Dir); err != nil {
return err
}
// services files
if err := c.generateServices(rs); err != nil {
return err
}
if err := c.generateSecurity(); err != nil {
return err
}
// main client file... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Generate",
"(",
")",
"error",
"{",
"rs",
":=",
"getAllResources",
"(",
"c",
".",
"APIDef",
",",
"false",
")",
"\n\n",
"if",
"err",
":=",
"generateAllObjects",
"(",
"c",
".",
"APIDef",
",",
"c",
".",
"Dir",
")"... | // Generate generates all Nim client files | [
"Generate",
"generates",
"all",
"Nim",
"client",
"files"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/nim/client.go#L27-L46 |
125,141 | Jumpscale/go-raml | codegen/nim/client.go | clientName | func clientName(apiDef *raml.APIDefinition) string {
splt := strings.Split(apiDef.Title, " ")
return "client_" + strings.ToLower(splt[0])
} | go | func clientName(apiDef *raml.APIDefinition) string {
splt := strings.Split(apiDef.Title, " ")
return "client_" + strings.ToLower(splt[0])
} | [
"func",
"clientName",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
")",
"string",
"{",
"splt",
":=",
"strings",
".",
"Split",
"(",
"apiDef",
".",
"Title",
",",
"\"",
"\"",
")",
"\n",
"return",
"\"",
"\"",
"+",
"strings",
".",
"ToLower",
"(",
"sp... | // returns client name of an API definition | [
"returns",
"client",
"name",
"of",
"an",
"API",
"definition"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/nim/client.go#L82-L85 |
125,142 | Jumpscale/go-raml | codegen/golang/resources.go | generateInterfaceFile | func (gr *goResource) generateInterfaceFile(directory string) error {
filename := directory + "/" + strings.ToLower(gr.Name) + "_if.go"
return commons.GenerateFile(gr, resourceIfTemplate, "resource_if_template", filename, true)
} | go | func (gr *goResource) generateInterfaceFile(directory string) error {
filename := directory + "/" + strings.ToLower(gr.Name) + "_if.go"
return commons.GenerateFile(gr, resourceIfTemplate, "resource_if_template", filename, true)
} | [
"func",
"(",
"gr",
"*",
"goResource",
")",
"generateInterfaceFile",
"(",
"directory",
"string",
")",
"error",
"{",
"filename",
":=",
"directory",
"+",
"\"",
"\"",
"+",
"strings",
".",
"ToLower",
"(",
"gr",
".",
"Name",
")",
"+",
"\"",
"\"",
"\n",
"retu... | // generate interface file of a resource | [
"generate",
"interface",
"file",
"of",
"a",
"resource"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/resources.go#L40-L43 |
125,143 | Jumpscale/go-raml | codegen/golang/resources.go | generateAPIImplementations | func (gr *goResource) generateAPIImplementations(dir string) error {
// generate the main API impl file, which only contains struct
mainCtx := map[string]interface{}{
"PackageName": gr.PackageName,
"Name": gr.Name,
"Endpoint": gr.Endpoint,
}
mainFile := filepath.Join(dir, strings.ToLower(gr.Name)+"... | go | func (gr *goResource) generateAPIImplementations(dir string) error {
// generate the main API impl file, which only contains struct
mainCtx := map[string]interface{}{
"PackageName": gr.PackageName,
"Name": gr.Name,
"Endpoint": gr.Endpoint,
}
mainFile := filepath.Join(dir, strings.ToLower(gr.Name)+"... | [
"func",
"(",
"gr",
"*",
"goResource",
")",
"generateAPIImplementations",
"(",
"dir",
"string",
")",
"error",
"{",
"// generate the main API impl file, which only contains struct",
"mainCtx",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
... | // generate API implementation in one file per method mode | [
"generate",
"API",
"implementation",
"in",
"one",
"file",
"per",
"method",
"mode"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/resources.go#L46-L74 |
125,144 | Jumpscale/go-raml | codegen/golang/resources.go | InterfaceImportPaths | func (gr goResource) InterfaceImportPaths() []string {
ip := map[string]struct{}{
"net/http": struct{}{},
"github.com/gorilla/mux": struct{}{},
}
for _, gm := range gr.Methods {
// if has middleware, we need to import middleware helper library
if len(gm.Middlewares) > 0 {
ip["github.com/jus... | go | func (gr goResource) InterfaceImportPaths() []string {
ip := map[string]struct{}{
"net/http": struct{}{},
"github.com/gorilla/mux": struct{}{},
}
for _, gm := range gr.Methods {
// if has middleware, we need to import middleware helper library
if len(gm.Middlewares) > 0 {
ip["github.com/jus... | [
"func",
"(",
"gr",
"goResource",
")",
"InterfaceImportPaths",
"(",
")",
"[",
"]",
"string",
"{",
"ip",
":=",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
"{",
"\"",
"\"",
":",
"struct",
"{",
"}",
"{",
"}",
",",
"\"",
"\"",
":",
"struct",
"{",
... | // InterfaceImportPaths returns all packages imported by
// this resource interface file | [
"InterfaceImportPaths",
"returns",
"all",
"packages",
"imported",
"by",
"this",
"resource",
"interface",
"file"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/resources.go#L95-L115 |
125,145 | Jumpscale/go-raml | codegen/golang/resources.go | APILibImportPaths | func (gr goResource) APILibImportPaths() []string {
ip := map[string]struct{}{}
// methods
for _, gm := range gr.Methods {
for _, v := range gm.Imports() {
ip[v] = struct{}{}
}
}
// return sorted array for predictable order
// we need it for unit test to always return same order
return commons.MapToSort... | go | func (gr goResource) APILibImportPaths() []string {
ip := map[string]struct{}{}
// methods
for _, gm := range gr.Methods {
for _, v := range gm.Imports() {
ip[v] = struct{}{}
}
}
// return sorted array for predictable order
// we need it for unit test to always return same order
return commons.MapToSort... | [
"func",
"(",
"gr",
"goResource",
")",
"APILibImportPaths",
"(",
")",
"[",
"]",
"string",
"{",
"ip",
":=",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
"{",
"}",
"\n\n",
"// methods",
"for",
"_",
",",
"gm",
":=",
"range",
"gr",
".",
"Methods",
"{"... | // APIImportPaths returns all packages that need to be imported
// by the API implementation | [
"APIImportPaths",
"returns",
"all",
"packages",
"that",
"need",
"to",
"be",
"imported",
"by",
"the",
"API",
"implementation"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/resources.go#L119-L132 |
125,146 | Jumpscale/go-raml | codegen/python/server.go | NewServer | func NewServer(kind string, apiDef *raml.APIDefinition, apiDocsDir, targetDir string,
withMain bool, libRootURLs []string) generator.Server {
switch kind {
case "", serverKindFlask:
return NewFlaskServer(apiDef, apiDocsDir, targetDir, withMain, libRootURLs, false)
case serverKindGeventFlask:
return NewFlaskServ... | go | func NewServer(kind string, apiDef *raml.APIDefinition, apiDocsDir, targetDir string,
withMain bool, libRootURLs []string) generator.Server {
switch kind {
case "", serverKindFlask:
return NewFlaskServer(apiDef, apiDocsDir, targetDir, withMain, libRootURLs, false)
case serverKindGeventFlask:
return NewFlaskServ... | [
"func",
"NewServer",
"(",
"kind",
"string",
",",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"apiDocsDir",
",",
"targetDir",
"string",
",",
"withMain",
"bool",
",",
"libRootURLs",
"[",
"]",
"string",
")",
"generator",
".",
"Server",
"{",
"switch",
"k... | // NewServer creates a new python server | [
"NewServer",
"creates",
"a",
"new",
"python",
"server"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/python/server.go#L23-L37 |
125,147 | Jumpscale/go-raml | codegen/python/client.go | NewClient | func NewClient(apiDef *raml.APIDefinition, kind string, unmarshallResponse bool) Client {
services := map[string]*service{}
for uri, res := range apiDef.Resources {
rd := resource.New(apiDef, &res, commons.NormalizeURITitle(apiDef.Title), false)
services[uri] = newService(uri, &rd, unmarshallResponse)
}
switch ... | go | func NewClient(apiDef *raml.APIDefinition, kind string, unmarshallResponse bool) Client {
services := map[string]*service{}
for uri, res := range apiDef.Resources {
rd := resource.New(apiDef, &res, commons.NormalizeURITitle(apiDef.Title), false)
services[uri] = newService(uri, &rd, unmarshallResponse)
}
switch ... | [
"func",
"NewClient",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"kind",
"string",
",",
"unmarshallResponse",
"bool",
")",
"Client",
"{",
"services",
":=",
"map",
"[",
"string",
"]",
"*",
"service",
"{",
"}",
"\n",
"for",
"uri",
",",
"res",
... | // NewClient creates a python Client | [
"NewClient",
"creates",
"a",
"python",
"Client"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/python/client.go#L39-L68 |
125,148 | Jumpscale/go-raml | codegen/python/client.go | Generate | func (c Client) Generate(dir string) error {
globAPIDef = c.APIDef
// generate helper
if err := commons.GenerateFile(nil, "./templates/python/client_utils_python.tmpl", "client_utils_python", filepath.Join(dir, "client_utils.py"), true); err != nil {
return err
}
// generate http client
if err := commons.Gene... | go | func (c Client) Generate(dir string) error {
globAPIDef = c.APIDef
// generate helper
if err := commons.GenerateFile(nil, "./templates/python/client_utils_python.tmpl", "client_utils_python", filepath.Join(dir, "client_utils.py"), true); err != nil {
return err
}
// generate http client
if err := commons.Gene... | [
"func",
"(",
"c",
"Client",
")",
"Generate",
"(",
"dir",
"string",
")",
"error",
"{",
"globAPIDef",
"=",
"c",
".",
"APIDef",
"\n\n",
"// generate helper",
"if",
"err",
":=",
"commons",
".",
"GenerateFile",
"(",
"nil",
",",
"\"",
"\"",
",",
"\"",
"\"",
... | // Generate generates python client library files | [
"Generate",
"generates",
"python",
"client",
"library",
"files"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/python/client.go#L80-L127 |
125,149 | Jumpscale/go-raml | codegen/golang/server_resources.go | generateServerResources | func (s *Server) generateServerResources(dir string) ([]*goResource, error) {
var serverResources []*goResource
resources := s.apiDef.Resources
// sort the keys, so we have resource sorted by keys.
// the generated code actually don't need it to be sorted.
// but test fixture need it
var keys []string
for k :=... | go | func (s *Server) generateServerResources(dir string) ([]*goResource, error) {
var serverResources []*goResource
resources := s.apiDef.Resources
// sort the keys, so we have resource sorted by keys.
// the generated code actually don't need it to be sorted.
// but test fixture need it
var keys []string
for k :=... | [
"func",
"(",
"s",
"*",
"Server",
")",
"generateServerResources",
"(",
"dir",
"string",
")",
"(",
"[",
"]",
"*",
"goResource",
",",
"error",
")",
"{",
"var",
"serverResources",
"[",
"]",
"*",
"goResource",
"\n\n",
"resources",
":=",
"s",
".",
"apiDef",
... | // generate Server's Go representation of RAML resources | [
"generate",
"Server",
"s",
"Go",
"representation",
"of",
"RAML",
"resources"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/server_resources.go#L12-L40 |
125,150 | Jumpscale/go-raml | codegen/commons/commons.go | NormalizeURITitle | func NormalizeURITitle(URI string) string {
s := strings.Title(doNormalizeURI(URI))
return strings.Replace(s, " ", "", -1)
} | go | func NormalizeURITitle(URI string) string {
s := strings.Title(doNormalizeURI(URI))
return strings.Replace(s, " ", "", -1)
} | [
"func",
"NormalizeURITitle",
"(",
"URI",
"string",
")",
"string",
"{",
"s",
":=",
"strings",
".",
"Title",
"(",
"doNormalizeURI",
"(",
"URI",
")",
")",
"\n",
"return",
"strings",
".",
"Replace",
"(",
"s",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
... | // NormalizeURITitle does NormalizeURI with first character in upper case | [
"NormalizeURITitle",
"does",
"NormalizeURI",
"with",
"first",
"character",
"in",
"upper",
"case"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/commons/commons.go#L53-L57 |
125,151 | Jumpscale/go-raml | codegen/commons/commons.go | ParseDescription | func ParseDescription(desc string) []string {
if desc == "" {
return nil
}
// we need to trim it because our parser usually give
// space after last newline
desc = strings.TrimSpace(desc)
if desc == "" {
return []string{}
}
return strings.Split(desc, "\n")
} | go | func ParseDescription(desc string) []string {
if desc == "" {
return nil
}
// we need to trim it because our parser usually give
// space after last newline
desc = strings.TrimSpace(desc)
if desc == "" {
return []string{}
}
return strings.Split(desc, "\n")
} | [
"func",
"ParseDescription",
"(",
"desc",
"string",
")",
"[",
"]",
"string",
"{",
"if",
"desc",
"==",
"\"",
"\"",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"// we need to trim it because our parser usually give",
"// space after last newline",
"desc",
"=",
"strings",
... | // ParseDescription create string slice from an RAML description.
// each element is a description line | [
"ParseDescription",
"create",
"string",
"slice",
"from",
"an",
"RAML",
"description",
".",
"each",
"element",
"is",
"a",
"description",
"line"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/commons/commons.go#L61-L74 |
125,152 | Jumpscale/go-raml | codegen/commons/commons.go | GenerateFile | func GenerateFile(data interface{}, tmplFile, tmplName, filename string, override bool) error {
if !override && isFileExist(filename) {
log.Infof("file %v already exist and override=false, no need to regenerate", filename)
return nil
}
if err := checkCreateDir(filepath.Dir(filename)); err != nil {
}
// pass ... | go | func GenerateFile(data interface{}, tmplFile, tmplName, filename string, override bool) error {
if !override && isFileExist(filename) {
log.Infof("file %v already exist and override=false, no need to regenerate", filename)
return nil
}
if err := checkCreateDir(filepath.Dir(filename)); err != nil {
}
// pass ... | [
"func",
"GenerateFile",
"(",
"data",
"interface",
"{",
"}",
",",
"tmplFile",
",",
"tmplName",
",",
"filename",
"string",
",",
"override",
"bool",
")",
"error",
"{",
"if",
"!",
"override",
"&&",
"isFileExist",
"(",
"filename",
")",
"{",
"log",
".",
"Infof... | // GenerateFile generates file from a template.
// if file already exist and override==false, file won't be regenerated
// funcMap = this parameter is used for passing go function to the template | [
"GenerateFile",
"generates",
"file",
"from",
"a",
"template",
".",
"if",
"file",
"already",
"exist",
"and",
"override",
"==",
"false",
"file",
"won",
"t",
"be",
"regenerated",
"funcMap",
"=",
"this",
"parameter",
"is",
"used",
"for",
"passing",
"go",
"functi... | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/commons/commons.go#L79-L125 |
125,153 | Jumpscale/go-raml | codegen/commons/commons.go | MapToSortedStrings | func MapToSortedStrings(m map[string]struct{}) []string {
ss := []string{}
for k := range m {
ss = append(ss, k)
}
sort.Strings(ss)
return ss
} | go | func MapToSortedStrings(m map[string]struct{}) []string {
ss := []string{}
for k := range m {
ss = append(ss, k)
}
sort.Strings(ss)
return ss
} | [
"func",
"MapToSortedStrings",
"(",
"m",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
")",
"[",
"]",
"string",
"{",
"ss",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"k",
":=",
"range",
"m",
"{",
"ss",
"=",
"append",
"(",
"ss",
",",
"k",
... | // MapToSortedStrings returns sorted string arrays from a map | [
"MapToSortedStrings",
"returns",
"sorted",
"string",
"arrays",
"from",
"a",
"map"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/commons/commons.go#L128-L135 |
125,154 | Jumpscale/go-raml | codegen/commons/commons.go | runGoFmt | func runGoFmt(filePath string) error {
args := []string{
"-w",
filePath,
}
if out, err := exec.Command("gofmt", args...).CombinedOutput(); err != nil {
log.Errorf("Error running go fmt on '%s' failed:\n%s", filePath, string(out))
return errors.New("go fmt failed")
}
return nil
} | go | func runGoFmt(filePath string) error {
args := []string{
"-w",
filePath,
}
if out, err := exec.Command("gofmt", args...).CombinedOutput(); err != nil {
log.Errorf("Error running go fmt on '%s' failed:\n%s", filePath, string(out))
return errors.New("go fmt failed")
}
return nil
} | [
"func",
"runGoFmt",
"(",
"filePath",
"string",
")",
"error",
"{",
"args",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"filePath",
",",
"}",
"\n\n",
"if",
"out",
",",
"err",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"args",
"...",
")... | // run `go fmt` command to a file | [
"run",
"go",
"fmt",
"command",
"to",
"a",
"file"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/commons/commons.go#L170-L181 |
125,155 | Jumpscale/go-raml | codegen/commons/commons.go | AtoiOrPanic | func AtoiOrPanic(str string) int {
i, err := strconv.Atoi(str)
if err != nil {
log.Fatalf("%v is not valid integer string. err = %v", str, err)
}
return i
} | go | func AtoiOrPanic(str string) int {
i, err := strconv.Atoi(str)
if err != nil {
log.Fatalf("%v is not valid integer string. err = %v", str, err)
}
return i
} | [
"func",
"AtoiOrPanic",
"(",
"str",
"string",
")",
"int",
"{",
"i",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"str",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"str",
",",
"err",
")",
"\n",
"}",
... | // AtoiOrPanic convert a string to int and panic if failed | [
"AtoiOrPanic",
"convert",
"a",
"string",
"to",
"int",
"and",
"panic",
"if",
"failed"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/commons/commons.go#L211-L217 |
125,156 | Jumpscale/go-raml | codegen/commons/commons.go | IsStrInArray | func IsStrInArray(arr []string, str string) bool {
for _, s := range arr {
if str == s {
return true
}
}
return false
} | go | func IsStrInArray(arr []string, str string) bool {
for _, s := range arr {
if str == s {
return true
}
}
return false
} | [
"func",
"IsStrInArray",
"(",
"arr",
"[",
"]",
"string",
",",
"str",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"s",
":=",
"range",
"arr",
"{",
"if",
"str",
"==",
"s",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
... | // IsStrInArray check if a string `str` is part of array `arr` | [
"IsStrInArray",
"check",
"if",
"a",
"string",
"str",
"is",
"part",
"of",
"array",
"arr"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/commons/commons.go#L228-L235 |
125,157 | Jumpscale/go-raml | codegen/nim/enum.go | FieldsStr | func (e *enum) FieldsStr() string {
var names []string
for _, f := range e.Fields {
names = append(names, f.Name)
}
return strings.Join(names, ", ")
} | go | func (e *enum) FieldsStr() string {
var names []string
for _, f := range e.Fields {
names = append(names, f.Name)
}
return strings.Join(names, ", ")
} | [
"func",
"(",
"e",
"*",
"enum",
")",
"FieldsStr",
"(",
")",
"string",
"{",
"var",
"names",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"e",
".",
"Fields",
"{",
"names",
"=",
"append",
"(",
"names",
",",
"f",
".",
"Name",
")",
... | // FieldsStr is a string representation of all the fields | [
"FieldsStr",
"is",
"a",
"string",
"representation",
"of",
"all",
"the",
"fields"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/nim/enum.go#L76-L82 |
125,158 | Jumpscale/go-raml | codegen/types/endpoint.go | ResourceName | func (ep Endpoint) ResourceName() string {
name := ep.Addr
splt := strings.Split(name, "/")
if len(splt) > 0 {
name = splt[0]
}
return strings.TrimSuffix(strings.TrimPrefix(name, "/"), "/")
} | go | func (ep Endpoint) ResourceName() string {
name := ep.Addr
splt := strings.Split(name, "/")
if len(splt) > 0 {
name = splt[0]
}
return strings.TrimSuffix(strings.TrimPrefix(name, "/"), "/")
} | [
"func",
"(",
"ep",
"Endpoint",
")",
"ResourceName",
"(",
")",
"string",
"{",
"name",
":=",
"ep",
".",
"Addr",
"\n",
"splt",
":=",
"strings",
".",
"Split",
"(",
"name",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"splt",
")",
">",
"0",
"{",
"n... | // ResourceName returns resource name of an endpoint | [
"ResourceName",
"returns",
"resource",
"name",
"of",
"an",
"endpoint"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/types/endpoint.go#L28-L35 |
125,159 | Jumpscale/go-raml | codegen/types/endpoint.go | PascalCaseTypeName | func PascalCaseTypeName(tip TypeInBody) string {
methodName := commons.SnackCaseServerMethodName(tip.Endpoint.Method.DisplayName, tip.Endpoint.Verb, tip.Endpoint.Resource)
suffix := commons.ReqBodySuffix
if tip.ReqResp == HTTPResponse {
suffix = commons.RespBodySuffix
}
return casee.ToPascalCase(methodName + suf... | go | func PascalCaseTypeName(tip TypeInBody) string {
methodName := commons.SnackCaseServerMethodName(tip.Endpoint.Method.DisplayName, tip.Endpoint.Verb, tip.Endpoint.Resource)
suffix := commons.ReqBodySuffix
if tip.ReqResp == HTTPResponse {
suffix = commons.RespBodySuffix
}
return casee.ToPascalCase(methodName + suf... | [
"func",
"PascalCaseTypeName",
"(",
"tip",
"TypeInBody",
")",
"string",
"{",
"methodName",
":=",
"commons",
".",
"SnackCaseServerMethodName",
"(",
"tip",
".",
"Endpoint",
".",
"Method",
".",
"DisplayName",
",",
"tip",
".",
"Endpoint",
".",
"Verb",
",",
"tip",
... | // PascalCaseTypeName generates pascalcase type name from snackcase method name | [
"PascalCaseTypeName",
"generates",
"pascalcase",
"type",
"name",
"from",
"snackcase",
"method",
"name"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/types/endpoint.go#L82-L89 |
125,160 | Jumpscale/go-raml | raml/resource.go | inheritResourceType | func (r *Resource) inheritResourceType(resourceTypes map[string]ResourceType, apiDef *APIDefinition) error {
// get resource type object to inherit
rt, err := r.getResourceType(resourceTypes)
if rt == nil || err != nil {
return err
}
// initialize dicts
dicts := initResourceTypeDicts(r, r.Type.Parameters)
r.... | go | func (r *Resource) inheritResourceType(resourceTypes map[string]ResourceType, apiDef *APIDefinition) error {
// get resource type object to inherit
rt, err := r.getResourceType(resourceTypes)
if rt == nil || err != nil {
return err
}
// initialize dicts
dicts := initResourceTypeDicts(r, r.Type.Parameters)
r.... | [
"func",
"(",
"r",
"*",
"Resource",
")",
"inheritResourceType",
"(",
"resourceTypes",
"map",
"[",
"string",
"]",
"ResourceType",
",",
"apiDef",
"*",
"APIDefinition",
")",
"error",
"{",
"// get resource type object to inherit",
"rt",
",",
"err",
":=",
"r",
".",
... | // inherit from a resource type | [
"inherit",
"from",
"a",
"resource",
"type"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/resource.go#L97-L126 |
125,161 | Jumpscale/go-raml | raml/resource.go | inheritMethods | func (r *Resource) inheritMethods(rt *ResourceType, apiDef *APIDefinition) {
// inherit all methods from resource type
// if it doesn't have the methods, we create it
for _, rtm := range rt.methods {
m := r.MethodByName(rtm.Name)
if m == nil {
m = newMethod(rtm.Name)
r.assignMethod(m, m.Name)
}
m.resou... | go | func (r *Resource) inheritMethods(rt *ResourceType, apiDef *APIDefinition) {
// inherit all methods from resource type
// if it doesn't have the methods, we create it
for _, rtm := range rt.methods {
m := r.MethodByName(rtm.Name)
if m == nil {
m = newMethod(rtm.Name)
r.assignMethod(m, m.Name)
}
m.resou... | [
"func",
"(",
"r",
"*",
"Resource",
")",
"inheritMethods",
"(",
"rt",
"*",
"ResourceType",
",",
"apiDef",
"*",
"APIDefinition",
")",
"{",
"// inherit all methods from resource type",
"// if it doesn't have the methods, we create it",
"for",
"_",
",",
"rtm",
":=",
"rang... | // inherit methods inherits all methods based on it's resource type | [
"inherit",
"methods",
"inherits",
"all",
"methods",
"based",
"on",
"it",
"s",
"resource",
"type"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/resource.go#L129-L152 |
125,162 | Jumpscale/go-raml | raml/resource.go | getResourceType | func (r *Resource) getResourceType(resourceTypes map[string]ResourceType) (*ResourceType, error) {
// check if it's specify a resource type to inherit
if r.Type == nil || r.Type.Name == "" {
return nil, nil
}
// get resource type from array of resource type map
for k, rt := range resourceTypes {
if k == r.Typ... | go | func (r *Resource) getResourceType(resourceTypes map[string]ResourceType) (*ResourceType, error) {
// check if it's specify a resource type to inherit
if r.Type == nil || r.Type.Name == "" {
return nil, nil
}
// get resource type from array of resource type map
for k, rt := range resourceTypes {
if k == r.Typ... | [
"func",
"(",
"r",
"*",
"Resource",
")",
"getResourceType",
"(",
"resourceTypes",
"map",
"[",
"string",
"]",
"ResourceType",
")",
"(",
"*",
"ResourceType",
",",
"error",
")",
"{",
"// check if it's specify a resource type to inherit",
"if",
"r",
".",
"Type",
"=="... | // get resource type from which this resource will inherit | [
"get",
"resource",
"type",
"from",
"which",
"this",
"resource",
"will",
"inherit"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/resource.go#L155-L168 |
125,163 | Jumpscale/go-raml | raml/resource.go | setMethods | func (r *Resource) setMethods(traitsMap map[string]Trait, apiDef *APIDefinition) {
if r.Get != nil {
r.Get.postProcess(r, "GET", traitsMap, apiDef)
}
if r.Post != nil {
r.Post.postProcess(r, "POST", traitsMap, apiDef)
}
if r.Put != nil {
r.Put.postProcess(r, "PUT", traitsMap, apiDef)
}
if r.Patch != nil {
... | go | func (r *Resource) setMethods(traitsMap map[string]Trait, apiDef *APIDefinition) {
if r.Get != nil {
r.Get.postProcess(r, "GET", traitsMap, apiDef)
}
if r.Post != nil {
r.Post.postProcess(r, "POST", traitsMap, apiDef)
}
if r.Put != nil {
r.Put.postProcess(r, "PUT", traitsMap, apiDef)
}
if r.Patch != nil {
... | [
"func",
"(",
"r",
"*",
"Resource",
")",
"setMethods",
"(",
"traitsMap",
"map",
"[",
"string",
"]",
"Trait",
",",
"apiDef",
"*",
"APIDefinition",
")",
"{",
"if",
"r",
".",
"Get",
"!=",
"nil",
"{",
"r",
".",
"Get",
".",
"postProcess",
"(",
"r",
",",
... | // set methods set all methods name
// and add it to Methods slice | [
"set",
"methods",
"set",
"all",
"methods",
"name",
"and",
"add",
"it",
"to",
"Methods",
"slice"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/resource.go#L172-L194 |
125,164 | Jumpscale/go-raml | raml/resource.go | MethodByName | func (r *Resource) MethodByName(name string) *Method {
switch name {
case "GET":
return r.Get
case "POST":
return r.Post
case "PUT":
return r.Put
case "PATCH":
return r.Patch
case "HEAD":
return r.Head
case "DELETE":
return r.Delete
case "OPTIONS":
return r.Options
default:
return nil
}
} | go | func (r *Resource) MethodByName(name string) *Method {
switch name {
case "GET":
return r.Get
case "POST":
return r.Post
case "PUT":
return r.Put
case "PATCH":
return r.Patch
case "HEAD":
return r.Head
case "DELETE":
return r.Delete
case "OPTIONS":
return r.Options
default:
return nil
}
} | [
"func",
"(",
"r",
"*",
"Resource",
")",
"MethodByName",
"(",
"name",
"string",
")",
"*",
"Method",
"{",
"switch",
"name",
"{",
"case",
"\"",
"\"",
":",
"return",
"r",
".",
"Get",
"\n",
"case",
"\"",
"\"",
":",
"return",
"r",
".",
"Post",
"\n",
"c... | // MethodByName return resource's method by it's name | [
"MethodByName",
"return",
"resource",
"s",
"method",
"by",
"it",
"s",
"name"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/resource.go#L197-L216 |
125,165 | Jumpscale/go-raml | raml/resource.go | substituteParams | func substituteParams(toReplace, words string, dicts map[string]interface{}) string {
// non empty scalar node remain unchanged
// except it has double chevron bracket
if toReplace != "" && (strings.Index(toReplace, "<<") < 0 && strings.Index(toReplace, ">>") < 0) {
return toReplace
}
if words == "" {
return t... | go | func substituteParams(toReplace, words string, dicts map[string]interface{}) string {
// non empty scalar node remain unchanged
// except it has double chevron bracket
if toReplace != "" && (strings.Index(toReplace, "<<") < 0 && strings.Index(toReplace, ">>") < 0) {
return toReplace
}
if words == "" {
return t... | [
"func",
"substituteParams",
"(",
"toReplace",
",",
"words",
"string",
",",
"dicts",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"string",
"{",
"// non empty scalar node remain unchanged",
"// except it has double chevron bracket",
"if",
"toReplace",
"!=",
"... | // substituteParams substitute all params inside double chevron to the correct value
// param value will be obtained from dicts map | [
"substituteParams",
"substitute",
"all",
"params",
"inside",
"double",
"chevron",
"to",
"the",
"correct",
"value",
"param",
"value",
"will",
"be",
"obtained",
"from",
"dicts",
"map"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/resource.go#L241-L269 |
125,166 | Jumpscale/go-raml | raml/resource.go | getParamValue | func getParamValue(param string, dicts map[string]interface{}) (string, bool) {
// split between inflectors and real param
// real param and each inflector is seperated by `|`
cleanParam, inflectors := func() (string, string) {
arr := strings.SplitN(param, "|", 2)
if len(arr) != 2 {
return param, ""
}
ret... | go | func getParamValue(param string, dicts map[string]interface{}) (string, bool) {
// split between inflectors and real param
// real param and each inflector is seperated by `|`
cleanParam, inflectors := func() (string, string) {
arr := strings.SplitN(param, "|", 2)
if len(arr) != 2 {
return param, ""
}
ret... | [
"func",
"getParamValue",
"(",
"param",
"string",
",",
"dicts",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"string",
",",
"bool",
")",
"{",
"// split between inflectors and real param",
"// real param and each inflector is seperated by `|`",
"cleanParam"... | // get value of a resource type param
// return false if not exists | [
"get",
"value",
"of",
"a",
"resource",
"type",
"param",
"return",
"false",
"if",
"not",
"exists"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/resource.go#L273-L309 |
125,167 | Jumpscale/go-raml | codegen/tarantool/server.go | NewServer | func NewServer(apiDef *raml.APIDefinition, apiDocsDir string, targetDir string) *Server {
resources := getServerResourcesDefs(apiDef)
return &Server{
apiDef: apiDef,
apiDocsDir: apiDocsDir,
TargetDir: targetDir,
Resources: resources,
}
} | go | func NewServer(apiDef *raml.APIDefinition, apiDocsDir string, targetDir string) *Server {
resources := getServerResourcesDefs(apiDef)
return &Server{
apiDef: apiDef,
apiDocsDir: apiDocsDir,
TargetDir: targetDir,
Resources: resources,
}
} | [
"func",
"NewServer",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"apiDocsDir",
"string",
",",
"targetDir",
"string",
")",
"*",
"Server",
"{",
"resources",
":=",
"getServerResourcesDefs",
"(",
"apiDef",
")",
"\n",
"return",
"&",
"Server",
"{",
"api... | // NewServer creates a new tarantool server | [
"NewServer",
"creates",
"a",
"new",
"tarantool",
"server"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/tarantool/server.go#L32-L40 |
125,168 | Jumpscale/go-raml | codegen/tarantool/server.go | generateMain | func (s *Server) generateMain() error {
filename := path.Join(s.TargetDir, "main.lua")
return commons.GenerateFile(s, "./templates/tarantool/server_main.tmpl", "server_main", filename, true)
} | go | func (s *Server) generateMain() error {
filename := path.Join(s.TargetDir, "main.lua")
return commons.GenerateFile(s, "./templates/tarantool/server_main.tmpl", "server_main", filename, true)
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"generateMain",
"(",
")",
"error",
"{",
"filename",
":=",
"path",
".",
"Join",
"(",
"s",
".",
"TargetDir",
",",
"\"",
"\"",
")",
"\n",
"return",
"commons",
".",
"GenerateFile",
"(",
"s",
",",
"\"",
"\"",
",",
... | // generateMain generates the main server file | [
"generateMain",
"generates",
"the",
"main",
"server",
"file"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/tarantool/server.go#L98-L101 |
125,169 | Jumpscale/go-raml | codegen/tarantool/server.go | generateResources | func (s *Server) generateResources() error {
var allMethods []method
for _, resource := range s.Resources {
filename := path.Join(s.TargetDir, fmt.Sprintf("%v_api", strings.ToLower(resource.Name))+".lua")
if err := commons.GenerateFile(resource, "./templates/tarantool/server_resource_api.tmpl",
"server_resou... | go | func (s *Server) generateResources() error {
var allMethods []method
for _, resource := range s.Resources {
filename := path.Join(s.TargetDir, fmt.Sprintf("%v_api", strings.ToLower(resource.Name))+".lua")
if err := commons.GenerateFile(resource, "./templates/tarantool/server_resource_api.tmpl",
"server_resou... | [
"func",
"(",
"s",
"*",
"Server",
")",
"generateResources",
"(",
")",
"error",
"{",
"var",
"allMethods",
"[",
"]",
"method",
"\n\n",
"for",
"_",
",",
"resource",
":=",
"range",
"s",
".",
"Resources",
"{",
"filename",
":=",
"path",
".",
"Join",
"(",
"s... | // generateResources generates all resource apis and end point handlers | [
"generateResources",
"generates",
"all",
"resource",
"apis",
"and",
"end",
"point",
"handlers"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/tarantool/server.go#L104-L134 |
125,170 | Jumpscale/go-raml | codegen/python/field.go | setType | func (pf *field) setType(apiDef *raml.APIDefinition, t, items string) {
pt := toPythonType(t)
if pt != nil {
pf.Type = pt.name
if pt.importName != "" {
pf.addImport(apiDef, pt.importModule, pt.importName)
}
return // type already set, no need to go down
}
ramlType := raml.Type{
Type: t,
Items: item... | go | func (pf *field) setType(apiDef *raml.APIDefinition, t, items string) {
pt := toPythonType(t)
if pt != nil {
pf.Type = pt.name
if pt.importName != "" {
pf.addImport(apiDef, pt.importModule, pt.importName)
}
return // type already set, no need to go down
}
ramlType := raml.Type{
Type: t,
Items: item... | [
"func",
"(",
"pf",
"*",
"field",
")",
"setType",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"t",
",",
"items",
"string",
")",
"{",
"pt",
":=",
"toPythonType",
"(",
"t",
")",
"\n",
"if",
"pt",
"!=",
"nil",
"{",
"pf",
".",
"Type",
"=",
... | // convert from raml Type to python type | [
"convert",
"from",
"raml",
"Type",
"to",
"python",
"type"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/python/field.go#L200-L249 |
125,171 | Jumpscale/go-raml | codegen/date/date.go | Get | func Get(typ, format string) ([]byte, error) {
switch typ {
case "date-only":
return get("date_only.go")
case "time-only":
return get("time_only.go")
case "datetime-only":
return get("datetime_only.go")
case "datetime":
if format == "" || strings.ToUpper(format) == "RFC3339" {
return get("datetime.go")
... | go | func Get(typ, format string) ([]byte, error) {
switch typ {
case "date-only":
return get("date_only.go")
case "time-only":
return get("time_only.go")
case "datetime-only":
return get("datetime_only.go")
case "datetime":
if format == "" || strings.ToUpper(format) == "RFC3339" {
return get("datetime.go")
... | [
"func",
"Get",
"(",
"typ",
",",
"format",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"switch",
"typ",
"{",
"case",
"\"",
"\"",
":",
"return",
"get",
"(",
"\"",
"\"",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"get",
"(",
... | // Get gets Go code of a specific RAML Date type
// The code returned is without `package date` line | [
"Get",
"gets",
"Go",
"code",
"of",
"a",
"specific",
"RAML",
"Date",
"type",
"The",
"code",
"returned",
"is",
"without",
"package",
"date",
"line"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/date/date.go#L12-L28 |
125,172 | Jumpscale/go-raml | raml/apidefinition.go | FindLibFile | func (apiDef *APIDefinition) FindLibFile(name string) (string, string) {
// search in it's document
if filename, ok := apiDef.Uses[name]; ok {
return "", filename
}
// search in included libraries
for _, lib := range apiDef.Libraries {
if filename, ok := lib.Uses[name]; ok {
return filepath.Dir(lib.Filenam... | go | func (apiDef *APIDefinition) FindLibFile(name string) (string, string) {
// search in it's document
if filename, ok := apiDef.Uses[name]; ok {
return "", filename
}
// search in included libraries
for _, lib := range apiDef.Libraries {
if filename, ok := lib.Uses[name]; ok {
return filepath.Dir(lib.Filenam... | [
"func",
"(",
"apiDef",
"*",
"APIDefinition",
")",
"FindLibFile",
"(",
"name",
"string",
")",
"(",
"string",
",",
"string",
")",
"{",
"// search in it's document",
"if",
"filename",
",",
"ok",
":=",
"apiDef",
".",
"Uses",
"[",
"name",
"]",
";",
"ok",
"{",... | // FindLibFile find lbrary dir and file by it's name
// we also search from included library | [
"FindLibFile",
"find",
"lbrary",
"dir",
"and",
"file",
"by",
"it",
"s",
"name",
"we",
"also",
"search",
"from",
"included",
"library"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/apidefinition.go#L152-L165 |
125,173 | Jumpscale/go-raml | raml/apidefinition.go | GetSecurityScheme | func (apiDef *APIDefinition) GetSecurityScheme(name string) (SecurityScheme, bool) {
var ss SecurityScheme
var ok bool
// split library name by '.'
// if there is '.', it means we need to look from the library
splitted := strings.Split(strings.TrimSpace(name), ".")
switch len(splitted) {
case 1:
ss, ok = api... | go | func (apiDef *APIDefinition) GetSecurityScheme(name string) (SecurityScheme, bool) {
var ss SecurityScheme
var ok bool
// split library name by '.'
// if there is '.', it means we need to look from the library
splitted := strings.Split(strings.TrimSpace(name), ".")
switch len(splitted) {
case 1:
ss, ok = api... | [
"func",
"(",
"apiDef",
"*",
"APIDefinition",
")",
"GetSecurityScheme",
"(",
"name",
"string",
")",
"(",
"SecurityScheme",
",",
"bool",
")",
"{",
"var",
"ss",
"SecurityScheme",
"\n",
"var",
"ok",
"bool",
"\n\n",
"// split library name by '.'",
"// if there is '.', ... | // GetSecurityScheme gets security scheme by it's name
// it also search in included library | [
"GetSecurityScheme",
"gets",
"security",
"scheme",
"by",
"it",
"s",
"name",
"it",
"also",
"search",
"in",
"included",
"library"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/apidefinition.go#L169-L189 |
125,174 | Jumpscale/go-raml | raml/apidefinition.go | createType | func (apiDef *APIDefinition) createType(name string, tip interface{},
inputProps map[interface{}]interface{}) bool {
created := false
// check that there is no type with this name
if _, exist := apiDef.Types[name]; exist {
return created
}
// convert the inputProps to properties
props := make(map[string]inte... | go | func (apiDef *APIDefinition) createType(name string, tip interface{},
inputProps map[interface{}]interface{}) bool {
created := false
// check that there is no type with this name
if _, exist := apiDef.Types[name]; exist {
return created
}
// convert the inputProps to properties
props := make(map[string]inte... | [
"func",
"(",
"apiDef",
"*",
"APIDefinition",
")",
"createType",
"(",
"name",
"string",
",",
"tip",
"interface",
"{",
"}",
",",
"inputProps",
"map",
"[",
"interface",
"{",
"}",
"]",
"interface",
"{",
"}",
")",
"bool",
"{",
"created",
":=",
"false",
"\n"... | // create new type | [
"create",
"new",
"type"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/apidefinition.go#L232-L260 |
125,175 | Jumpscale/go-raml | codegen/commons/json.go | IsJSONString | func IsJSONString(s string) bool {
s = strings.TrimSpace(s)
return strings.HasPrefix(s, "{") && strings.HasSuffix(s, "}")
} | go | func IsJSONString(s string) bool {
s = strings.TrimSpace(s)
return strings.HasPrefix(s, "{") && strings.HasSuffix(s, "}")
} | [
"func",
"IsJSONString",
"(",
"s",
"string",
")",
"bool",
"{",
"s",
"=",
"strings",
".",
"TrimSpace",
"(",
"s",
")",
"\n",
"return",
"strings",
".",
"HasPrefix",
"(",
"s",
",",
"\"",
"\"",
")",
"&&",
"strings",
".",
"HasSuffix",
"(",
"s",
",",
"\"",... | // IsJSONString returns true if a string is a JSON string | [
"IsJSONString",
"returns",
"true",
"if",
"a",
"string",
"is",
"a",
"JSON",
"string"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/commons/json.go#L18-L21 |
125,176 | Jumpscale/go-raml | codegen/golang/security_go.go | generate | func (gs *goSecurity) generate(dir string) error {
fileName := path.Join(dir, "oauth2_"+gs.Name+"_middleware.go")
return commons.GenerateFile(gs, "./templates/golang/oauth2_middleware.tmpl", "oauth2_middleware", fileName, true)
} | go | func (gs *goSecurity) generate(dir string) error {
fileName := path.Join(dir, "oauth2_"+gs.Name+"_middleware.go")
return commons.GenerateFile(gs, "./templates/golang/oauth2_middleware.tmpl", "oauth2_middleware", fileName, true)
} | [
"func",
"(",
"gs",
"*",
"goSecurity",
")",
"generate",
"(",
"dir",
"string",
")",
"error",
"{",
"fileName",
":=",
"path",
".",
"Join",
"(",
"dir",
",",
"\"",
"\"",
"+",
"gs",
".",
"Name",
"+",
"\"",
"\"",
")",
"\n",
"return",
"commons",
".",
"Gen... | // generate Go representation of a security scheme
// it implemented as struct based middleware | [
"generate",
"Go",
"representation",
"of",
"a",
"security",
"scheme",
"it",
"implemented",
"as",
"struct",
"based",
"middleware"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/security_go.go#L19-L22 |
125,177 | Jumpscale/go-raml | codegen/python/class.go | newClass | func newClass(apiDef *raml.APIDefinition, T raml.Type, name string, description string, properties map[string]interface{}, capnp bool) class {
pc := class{
name: name,
Description: commons.ParseDescription(description),
Fields: map[string]field{},
T: T,
Capnp: capnp,
imports: ... | go | func newClass(apiDef *raml.APIDefinition, T raml.Type, name string, description string, properties map[string]interface{}, capnp bool) class {
pc := class{
name: name,
Description: commons.ParseDescription(description),
Fields: map[string]field{},
T: T,
Capnp: capnp,
imports: ... | [
"func",
"newClass",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"T",
"raml",
".",
"Type",
",",
"name",
"string",
",",
"description",
"string",
",",
"properties",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"capnp",
"bool",
")",
"c... | // create a python class representations | [
"create",
"a",
"python",
"class",
"representations"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/python/class.go#L38-L80 |
125,178 | Jumpscale/go-raml | codegen/python/class.go | ChildProperties | func ChildProperties(Properties map[string]interface{}) []raml.Property {
props := make([]raml.Property, 0)
for propName, propInterface := range Properties {
props = append(props, raml.ToProperty(propName, propInterface))
}
return props
} | go | func ChildProperties(Properties map[string]interface{}) []raml.Property {
props := make([]raml.Property, 0)
for propName, propInterface := range Properties {
props = append(props, raml.ToProperty(propName, propInterface))
}
return props
} | [
"func",
"ChildProperties",
"(",
"Properties",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"[",
"]",
"raml",
".",
"Property",
"{",
"props",
":=",
"make",
"(",
"[",
"]",
"raml",
".",
"Property",
",",
"0",
")",
"\n\n",
"for",
"propName",
",",... | // ChildProperties returns child properties of a property | [
"ChildProperties",
"returns",
"child",
"properties",
"of",
"a",
"property"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/python/class.go#L120-L128 |
125,179 | Jumpscale/go-raml | codegen/python/class.go | generate | func (pc *class) generate(dir, template, name string) ([]string, error) {
fileName := filepath.Join(dir, pc.Name()+".py")
if pc.AliasOf != "" {
return []string{pc.Name()}, commons.GenerateFile(pc, "./templates/python/class_alias.tmpl",
"class_alias", fileName, true)
}
// generate enums
typeNames := make([]s... | go | func (pc *class) generate(dir, template, name string) ([]string, error) {
fileName := filepath.Join(dir, pc.Name()+".py")
if pc.AliasOf != "" {
return []string{pc.Name()}, commons.GenerateFile(pc, "./templates/python/class_alias.tmpl",
"class_alias", fileName, true)
}
// generate enums
typeNames := make([]s... | [
"func",
"(",
"pc",
"*",
"class",
")",
"generate",
"(",
"dir",
",",
"template",
",",
"name",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"fileName",
":=",
"filepath",
".",
"Join",
"(",
"dir",
",",
"pc",
".",
"Name",
"(",
")",
... | // generate a python class file | [
"generate",
"a",
"python",
"class",
"file"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/python/class.go#L163-L189 |
125,180 | Jumpscale/go-raml | codegen/python/class.go | Imports | func (pc *class) Imports() []string {
for _, field := range pc.Fields {
for _, imp := range field.imports {
// do not import ourself
if imp.Name == pc.Name() {
continue
}
pc.addImport(imp.Module, imp.Name)
}
}
return commons.MapToSortedStrings(pc.imports)
} | go | func (pc *class) Imports() []string {
for _, field := range pc.Fields {
for _, imp := range field.imports {
// do not import ourself
if imp.Name == pc.Name() {
continue
}
pc.addImport(imp.Module, imp.Name)
}
}
return commons.MapToSortedStrings(pc.imports)
} | [
"func",
"(",
"pc",
"*",
"class",
")",
"Imports",
"(",
")",
"[",
"]",
"string",
"{",
"for",
"_",
",",
"field",
":=",
"range",
"pc",
".",
"Fields",
"{",
"for",
"_",
",",
"imp",
":=",
"range",
"field",
".",
"imports",
"{",
"// do not import ourself",
... | // return list of import statements | [
"return",
"list",
"of",
"import",
"statements"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/python/class.go#L221-L233 |
125,181 | Jumpscale/go-raml | codegen/python/class.go | GenerateAllClasses | func GenerateAllClasses(apiDef *raml.APIDefinition, dir string, capnp bool) ([]string, error) {
// array of tip that need to be generated in the end of this
// process. because it needs other object to be registered first
delayedMI := []string{} // delayed multiple inheritance
template := "./templates/python/class_... | go | func GenerateAllClasses(apiDef *raml.APIDefinition, dir string, capnp bool) ([]string, error) {
// array of tip that need to be generated in the end of this
// process. because it needs other object to be registered first
delayedMI := []string{} // delayed multiple inheritance
template := "./templates/python/class_... | [
"func",
"GenerateAllClasses",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"dir",
"string",
",",
"capnp",
"bool",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"// array of tip that need to be generated in the end of this",
"// process. because it ne... | // generate all python classes from a RAML document | [
"generate",
"all",
"python",
"classes",
"from",
"a",
"RAML",
"document"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/python/class.go#L244-L297 |
125,182 | Jumpscale/go-raml | codegen/golang/field.go | newFieldDef | func newFieldDef(apiDef *raml.APIDefinition, structName string, prop raml.Property, pkg string) fieldDef {
var (
fieldType = prop.TypeString() // the field type
basicType = commons.GetBasicType(fieldType) // basic type of the field type
)
// for the types, check first if it is user defined type
i... | go | func newFieldDef(apiDef *raml.APIDefinition, structName string, prop raml.Property, pkg string) fieldDef {
var (
fieldType = prop.TypeString() // the field type
basicType = commons.GetBasicType(fieldType) // basic type of the field type
)
// for the types, check first if it is user defined type
i... | [
"func",
"newFieldDef",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"structName",
"string",
",",
"prop",
"raml",
".",
"Property",
",",
"pkg",
"string",
")",
"fieldDef",
"{",
"var",
"(",
"fieldType",
"=",
"prop",
".",
"TypeString",
"(",
")",
"//... | // newFieldDef creates new struct field from raml property. | [
"newFieldDef",
"creates",
"new",
"struct",
"field",
"from",
"raml",
"property",
"."
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/field.go#L24-L59 |
125,183 | Jumpscale/go-raml | codegen/golang/field.go | formatFieldName | func formatFieldName(name string) string {
var formatted string
for _, v := range strings.Split(name, "-") {
formatted += strings.Title(v)
}
return formatted
} | go | func formatFieldName(name string) string {
var formatted string
for _, v := range strings.Split(name, "-") {
formatted += strings.Title(v)
}
return formatted
} | [
"func",
"formatFieldName",
"(",
"name",
"string",
")",
"string",
"{",
"var",
"formatted",
"string",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"strings",
".",
"Split",
"(",
"name",
",",
"\"",
"\"",
")",
"{",
"formatted",
"+=",
"strings",
".",
"Title",
... | // format struct's field name
// - Title it
// - replace '-' with camel case version | [
"format",
"struct",
"s",
"field",
"name",
"-",
"Title",
"it",
"-",
"replace",
"-",
"with",
"camel",
"case",
"version"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/field.go#L131-L137 |
125,184 | Jumpscale/go-raml | codegen/python/server_method.go | setup | func (sm *serverMethod) setup(apiDef *raml.APIDefinition, r *raml.Resource, rd *resource.Resource, resourceParams []string) error {
sm.MethodName = commons.SnackCaseServerMethodName(sm.DisplayName, sm.Verb(), r)
if commons.HasJSONBody(&(sm.Bodies)) {
// TODO : make it to call proper func
sm.reqBody = casee.ToPas... | go | func (sm *serverMethod) setup(apiDef *raml.APIDefinition, r *raml.Resource, rd *resource.Resource, resourceParams []string) error {
sm.MethodName = commons.SnackCaseServerMethodName(sm.DisplayName, sm.Verb(), r)
if commons.HasJSONBody(&(sm.Bodies)) {
// TODO : make it to call proper func
sm.reqBody = casee.ToPas... | [
"func",
"(",
"sm",
"*",
"serverMethod",
")",
"setup",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"r",
"*",
"raml",
".",
"Resource",
",",
"rd",
"*",
"resource",
".",
"Resource",
",",
"resourceParams",
"[",
"]",
"string",
")",
"error",
"{",
... | // setup sets all needed variables | [
"setup",
"sets",
"all",
"needed",
"variables"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/python/server_method.go#L23-L49 |
125,185 | Jumpscale/go-raml | codegen/python/flask_server.go | NewFlaskServer | func NewFlaskServer(apiDef *raml.APIDefinition, apiDocsDir, targetDir string,
withMain bool, libRootURLs []string, gevent bool) *FlaskServer {
// TODO : get rid of this global variables
globAPIDef = apiDef
globLibRootURLs = libRootURLs
// generates resource
var prs []pythonResource
for _, rd := range getServer... | go | func NewFlaskServer(apiDef *raml.APIDefinition, apiDocsDir, targetDir string,
withMain bool, libRootURLs []string, gevent bool) *FlaskServer {
// TODO : get rid of this global variables
globAPIDef = apiDef
globLibRootURLs = libRootURLs
// generates resource
var prs []pythonResource
for _, rd := range getServer... | [
"func",
"NewFlaskServer",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"apiDocsDir",
",",
"targetDir",
"string",
",",
"withMain",
"bool",
",",
"libRootURLs",
"[",
"]",
"string",
",",
"gevent",
"bool",
")",
"*",
"FlaskServer",
"{",
"// TODO : get rid ... | // NewFlaskServer creates new flask server from an RAML file | [
"NewFlaskServer",
"creates",
"new",
"flask",
"server",
"from",
"an",
"RAML",
"file"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/python/flask_server.go#L26-L52 |
125,186 | Jumpscale/go-raml | raml/trait.go | initTraitDicts | func initTraitDicts(r *Resource, m *Method, dicts map[string]interface{}) map[string]interface{} {
dicts = initResourceTypeDicts(r, dicts)
dicts["methodName"] = strings.ToLower(m.Name)
return dicts
} | go | func initTraitDicts(r *Resource, m *Method, dicts map[string]interface{}) map[string]interface{} {
dicts = initResourceTypeDicts(r, dicts)
dicts["methodName"] = strings.ToLower(m.Name)
return dicts
} | [
"func",
"initTraitDicts",
"(",
"r",
"*",
"Resource",
",",
"m",
"*",
"Method",
",",
"dicts",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"dicts",
"=",
"initResourceTypeDicts",
"(",
"r",
... | // init trait dicts
// trait dicts contain current trait parameters that is currently applied to a method | [
"init",
"trait",
"dicts",
"trait",
"dicts",
"contain",
"current",
"trait",
"parameters",
"that",
"is",
"currently",
"applied",
"to",
"a",
"method"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/trait.go#L59-L63 |
125,187 | Jumpscale/go-raml | codegen/golang/server.go | NewServer | func NewServer(apiDef *raml.APIDefinition, packageName, apiDocsDir, rootImportPath string,
withMain bool, targetDir string, libsRootURLs []string) *Server {
// global variables
rootImportPath = setRootImportPath(rootImportPath, targetDir)
globAPIDef = apiDef
globRootImportPath = rootImportPath
globLibRootURLs = l... | go | func NewServer(apiDef *raml.APIDefinition, packageName, apiDocsDir, rootImportPath string,
withMain bool, targetDir string, libsRootURLs []string) *Server {
// global variables
rootImportPath = setRootImportPath(rootImportPath, targetDir)
globAPIDef = apiDef
globRootImportPath = rootImportPath
globLibRootURLs = l... | [
"func",
"NewServer",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"packageName",
",",
"apiDocsDir",
",",
"rootImportPath",
"string",
",",
"withMain",
"bool",
",",
"targetDir",
"string",
",",
"libsRootURLs",
"[",
"]",
"string",
")",
"*",
"Server",
"... | // NewServer creates a new Golang server | [
"NewServer",
"creates",
"a",
"new",
"Golang",
"server"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/server.go#L39-L56 |
125,188 | Jumpscale/go-raml | codegen/golang/server.go | Generate | func (gs *Server) Generate() error {
if err := commons.CheckDuplicatedTitleTypes(gs.apiDef); err != nil {
return err
}
if gs.RootImportPath == "" {
return fmt.Errorf("invalid import path = empty. please set --import-path or set target dir under gopath")
}
// helper package
gh := goramlHelper{
rootImportPath... | go | func (gs *Server) Generate() error {
if err := commons.CheckDuplicatedTitleTypes(gs.apiDef); err != nil {
return err
}
if gs.RootImportPath == "" {
return fmt.Errorf("invalid import path = empty. please set --import-path or set target dir under gopath")
}
// helper package
gh := goramlHelper{
rootImportPath... | [
"func",
"(",
"gs",
"*",
"Server",
")",
"Generate",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"commons",
".",
"CheckDuplicatedTitleTypes",
"(",
"gs",
".",
"apiDef",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"gs",
".... | // Generate implements codegen.Server.Generate interface | [
"Generate",
"implements",
"codegen",
".",
"Server",
".",
"Generate",
"interface"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/server.go#L64-L119 |
125,189 | Jumpscale/go-raml | codegen/golang/client.go | NewClient | func NewClient(apiDef *raml.APIDefinition, packageName, rootImportPath, targetDir string,
libsRootURLs []string) (Client, error) {
// rootImportPath only needed if we use libraries
if rootImportPath == "" && len(apiDef.Libraries) > 0 {
return Client{}, fmt.Errorf("--import-path can't be empty when we use librarie... | go | func NewClient(apiDef *raml.APIDefinition, packageName, rootImportPath, targetDir string,
libsRootURLs []string) (Client, error) {
// rootImportPath only needed if we use libraries
if rootImportPath == "" && len(apiDef.Libraries) > 0 {
return Client{}, fmt.Errorf("--import-path can't be empty when we use librarie... | [
"func",
"NewClient",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"packageName",
",",
"rootImportPath",
",",
"targetDir",
"string",
",",
"libsRootURLs",
"[",
"]",
"string",
")",
"(",
"Client",
",",
"error",
")",
"{",
"// rootImportPath only needed if w... | // NewClient creates a new Golang client | [
"NewClient",
"creates",
"a",
"new",
"Golang",
"client"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/client.go#L27-L65 |
125,190 | Jumpscale/go-raml | codegen/golang/client.go | Generate | func (gc Client) Generate() error {
if err := commons.CheckDuplicatedTitleTypes(gc.apiDef); err != nil {
return err
}
// helper package
gh := goramlHelper{
packageName: "goraml",
packageDir: "goraml",
}
if err := gh.generate(gc.TargetDir); err != nil {
return err
}
// generate struct
if err := genera... | go | func (gc Client) Generate() error {
if err := commons.CheckDuplicatedTitleTypes(gc.apiDef); err != nil {
return err
}
// helper package
gh := goramlHelper{
packageName: "goraml",
packageDir: "goraml",
}
if err := gh.generate(gc.TargetDir); err != nil {
return err
}
// generate struct
if err := genera... | [
"func",
"(",
"gc",
"Client",
")",
"Generate",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"commons",
".",
"CheckDuplicatedTitleTypes",
"(",
"gc",
".",
"apiDef",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// helper package",
"g... | // Generate generates all Go client files | [
"Generate",
"generates",
"all",
"Go",
"client",
"files"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/client.go#L68-L103 |
125,191 | Jumpscale/go-raml | codegen/golang/client.go | generateHelperFile | func (gc *Client) generateHelperFile(dir string) error {
fileName := filepath.Join(dir, "/client_utils.go")
return commons.GenerateFile(gc, "./templates/golang/client_utils_go.tmpl", "client_utils_go", fileName, true)
} | go | func (gc *Client) generateHelperFile(dir string) error {
fileName := filepath.Join(dir, "/client_utils.go")
return commons.GenerateFile(gc, "./templates/golang/client_utils_go.tmpl", "client_utils_go", fileName, true)
} | [
"func",
"(",
"gc",
"*",
"Client",
")",
"generateHelperFile",
"(",
"dir",
"string",
")",
"error",
"{",
"fileName",
":=",
"filepath",
".",
"Join",
"(",
"dir",
",",
"\"",
"\"",
")",
"\n",
"return",
"commons",
".",
"GenerateFile",
"(",
"gc",
",",
"\"",
"... | // generate Go client helper | [
"generate",
"Go",
"client",
"helper"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/client.go#L106-L109 |
125,192 | Jumpscale/go-raml | codegen/golang/client.go | generateClientFile | func (gc *Client) generateClientFile(dir string) error {
fileName := filepath.Join(dir, "/client_"+strings.ToLower(gc.Name)+".go")
return commons.GenerateFile(gc, "./templates/golang/client_go.tmpl", "client_go", fileName, true)
} | go | func (gc *Client) generateClientFile(dir string) error {
fileName := filepath.Join(dir, "/client_"+strings.ToLower(gc.Name)+".go")
return commons.GenerateFile(gc, "./templates/golang/client_go.tmpl", "client_go", fileName, true)
} | [
"func",
"(",
"gc",
"*",
"Client",
")",
"generateClientFile",
"(",
"dir",
"string",
")",
"error",
"{",
"fileName",
":=",
"filepath",
".",
"Join",
"(",
"dir",
",",
"\"",
"\"",
"+",
"strings",
".",
"ToLower",
"(",
"gc",
".",
"Name",
")",
"+",
"\"",
"\... | // generate Go client lib file | [
"generate",
"Go",
"client",
"lib",
"file"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/client.go#L141-L144 |
125,193 | Jumpscale/go-raml | codegen/nim/field.go | EscapedName | func (f field) EscapedName() string {
name := f.Name
if _, ok := nimKeywords[name]; !ok {
return name
}
return "`" + name + "`"
} | go | func (f field) EscapedName() string {
name := f.Name
if _, ok := nimKeywords[name]; !ok {
return name
}
return "`" + name + "`"
} | [
"func",
"(",
"f",
"field",
")",
"EscapedName",
"(",
")",
"string",
"{",
"name",
":=",
"f",
".",
"Name",
"\n",
"if",
"_",
",",
"ok",
":=",
"nimKeywords",
"[",
"name",
"]",
";",
"!",
"ok",
"{",
"return",
"name",
"\n",
"}",
"\n",
"return",
"\"",
"... | // EscapedName produces escaped name of Nim keyword
// or return as is if it is not Nim keyword | [
"EscapedName",
"produces",
"escaped",
"name",
"of",
"Nim",
"keyword",
"or",
"return",
"as",
"is",
"if",
"it",
"is",
"not",
"Nim",
"keyword"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/nim/field.go#L25-L31 |
125,194 | Jumpscale/go-raml | raml/resource_type.go | setMethods | func (rt *ResourceType) setMethods(traitsMap map[string]Trait, apiDef *APIDefinition) {
if rt.Get != nil {
rt.Get.Name = "GET"
rt.Get.inheritFromTraits(nil, append(rt.Is, rt.Get.Is...), traitsMap, apiDef)
rt.methods = append(rt.methods, rt.Get)
}
if rt.Post != nil {
rt.Post.Name = "POST"
rt.Post.inheritFro... | go | func (rt *ResourceType) setMethods(traitsMap map[string]Trait, apiDef *APIDefinition) {
if rt.Get != nil {
rt.Get.Name = "GET"
rt.Get.inheritFromTraits(nil, append(rt.Is, rt.Get.Is...), traitsMap, apiDef)
rt.methods = append(rt.methods, rt.Get)
}
if rt.Post != nil {
rt.Post.Name = "POST"
rt.Post.inheritFro... | [
"func",
"(",
"rt",
"*",
"ResourceType",
")",
"setMethods",
"(",
"traitsMap",
"map",
"[",
"string",
"]",
"Trait",
",",
"apiDef",
"*",
"APIDefinition",
")",
"{",
"if",
"rt",
".",
"Get",
"!=",
"nil",
"{",
"rt",
".",
"Get",
".",
"Name",
"=",
"\"",
"\""... | // set methods set all methods name
// and add it to methods slice | [
"set",
"methods",
"set",
"all",
"methods",
"name",
"and",
"add",
"it",
"to",
"methods",
"slice"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/resource_type.go#L122-L158 |
125,195 | Jumpscale/go-raml | raml/resource_type.go | setOptionalMethods | func (rt *ResourceType) setOptionalMethods() {
if rt.OptionalGet != nil {
rt.OptionalGet.Name = "GET"
rt.optionalMethods = append(rt.optionalMethods, rt.OptionalGet)
}
if rt.OptionalPost != nil {
rt.OptionalPost.Name = "POST"
rt.optionalMethods = append(rt.optionalMethods, rt.OptionalPost)
}
if rt.Optional... | go | func (rt *ResourceType) setOptionalMethods() {
if rt.OptionalGet != nil {
rt.OptionalGet.Name = "GET"
rt.optionalMethods = append(rt.optionalMethods, rt.OptionalGet)
}
if rt.OptionalPost != nil {
rt.OptionalPost.Name = "POST"
rt.optionalMethods = append(rt.optionalMethods, rt.OptionalPost)
}
if rt.Optional... | [
"func",
"(",
"rt",
"*",
"ResourceType",
")",
"setOptionalMethods",
"(",
")",
"{",
"if",
"rt",
".",
"OptionalGet",
"!=",
"nil",
"{",
"rt",
".",
"OptionalGet",
".",
"Name",
"=",
"\"",
"\"",
"\n",
"rt",
".",
"optionalMethods",
"=",
"append",
"(",
"rt",
... | // setOptionalMethods set name of all optional methods
// and add it to optionalMethods slice | [
"setOptionalMethods",
"set",
"name",
"of",
"all",
"optional",
"methods",
"and",
"add",
"it",
"to",
"optionalMethods",
"slice"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/resource_type.go#L162-L191 |
125,196 | Jumpscale/go-raml | raml/resource_type.go | mergeTypeName | func mergeTypeName(name, rtName string, apiDef *APIDefinition) string {
if apiDef == nil {
log.Warning("passing nil API definition to mergeTypeName")
return name
}
// check if this resource type is in library
splt := strings.Split(rtName, ".")
if len(splt) < 2 {
// if not in library, we need to do nothing
... | go | func mergeTypeName(name, rtName string, apiDef *APIDefinition) string {
if apiDef == nil {
log.Warning("passing nil API definition to mergeTypeName")
return name
}
// check if this resource type is in library
splt := strings.Split(rtName, ".")
if len(splt) < 2 {
// if not in library, we need to do nothing
... | [
"func",
"mergeTypeName",
"(",
"name",
",",
"rtName",
"string",
",",
"apiDef",
"*",
"APIDefinition",
")",
"string",
"{",
"if",
"apiDef",
"==",
"nil",
"{",
"log",
".",
"Warning",
"(",
"\"",
"\"",
")",
"\n",
"return",
"name",
"\n",
"}",
"\n\n",
"// check ... | // merge name of type with resource type name. | [
"merge",
"name",
"of",
"type",
"with",
"resource",
"type",
"name",
"."
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/resource_type.go#L205-L231 |
125,197 | Jumpscale/go-raml | commands/server.go | Execute | func (command *ServerCommand) Execute() error {
var apiDocsDir string
log.Infof("Generating a %v server", command.Language)
if !command.NoAPIDocs {
apiDocsDir = "apidocs"
}
cs := codegen.Server{
RAMLFile: command.RamlFile,
Kind: command.Kind,
Dir: command.Dir,
PackageName: ... | go | func (command *ServerCommand) Execute() error {
var apiDocsDir string
log.Infof("Generating a %v server", command.Language)
if !command.NoAPIDocs {
apiDocsDir = "apidocs"
}
cs := codegen.Server{
RAMLFile: command.RamlFile,
Kind: command.Kind,
Dir: command.Dir,
PackageName: ... | [
"func",
"(",
"command",
"*",
"ServerCommand",
")",
"Execute",
"(",
")",
"error",
"{",
"var",
"apiDocsDir",
"string",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"command",
".",
"Language",
")",
"\n\n",
"if",
"!",
"command",
".",
"NoAPIDocs",
"{"... | // Execute generates a Go server from an RAML specification | [
"Execute",
"generates",
"a",
"Go",
"server",
"from",
"an",
"RAML",
"specification"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/commands/server.go#L32-L53 |
125,198 | Jumpscale/go-raml | docs/tutorial/go/client/goramldir/goraml/api_error.go | NewAPIError | func NewAPIError(resp *http.Response, data interface{}) error {
// read response body
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
// creates object
goramlErr := APIError{
Code: resp.StatusCode,
RawMessage: b,
}
// no need to parse in case of `data` is nil
if data == nil {
r... | go | func NewAPIError(resp *http.Response, data interface{}) error {
// read response body
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
// creates object
goramlErr := APIError{
Code: resp.StatusCode,
RawMessage: b,
}
// no need to parse in case of `data` is nil
if data == nil {
r... | [
"func",
"NewAPIError",
"(",
"resp",
"*",
"http",
".",
"Response",
",",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"// read response body",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
... | // NewAPIError creates new APIError object.
// If data is nil, it raw message won't be parsed. | [
"NewAPIError",
"creates",
"new",
"APIError",
"object",
".",
"If",
"data",
"is",
"nil",
"it",
"raw",
"message",
"won",
"t",
"be",
"parsed",
"."
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/docs/tutorial/go/client/goramldir/goraml/api_error.go#L26-L58 |
125,199 | Jumpscale/go-raml | codegen/python/resources.go | setMiddlewares | func (pr *pythonResource) setMiddlewares() {
for _, pm := range pr.Methods {
for _, m := range pm.MiddlewaresArr {
pr.addMiddleware(m)
}
}
} | go | func (pr *pythonResource) setMiddlewares() {
for _, pm := range pr.Methods {
for _, m := range pm.MiddlewaresArr {
pr.addMiddleware(m)
}
}
} | [
"func",
"(",
"pr",
"*",
"pythonResource",
")",
"setMiddlewares",
"(",
")",
"{",
"for",
"_",
",",
"pm",
":=",
"range",
"pr",
".",
"Methods",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"pm",
".",
"MiddlewaresArr",
"{",
"pr",
".",
"addMiddleware",
"(",
... | // set middlewares to import | [
"set",
"middlewares",
"to",
"import"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/python/resources.go#L77-L83 |
Subsets and Splits
SQL Console for google/code_x_glue_ct_code_to_text
This query implements a thoughtful three-tier curation strategy to build a balanced safety dataset, categorizing code by destructive operations, safe I/O operations, and pure computational negatives with subsampling—revealing important patterns about how destructive intent manifests in Python code for model safety research.
SQL Console for google/code_x_glue_ct_code_to_text
This query performs meaningful classification of Python code samples into safety-relevant tiers based on destructive operations, I/O patterns, and pure computation, which could be valuable for building safety classifiers or curating training data, though the output itself is a filtered/ranked dataset rather than revealing novel statistical insights.