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
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
3,100 | 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",
"==",
"rootCatchAllRoute",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // 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 |
3,101 | 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",
",",
"error",
")",
"{",
"body",
",",
"err",
":=",
"encodeBody",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"c",
".",
"doReq",
"(",
"method",
",",
"urlStr",
",",
"body",
",",
"headers",
",",
"queryParams",
")",
"\n",
"}"
] | // 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 |
3,102 | 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",
"c",
".",
"doReq",
"(",
"method",
",",
"urlStr",
",",
"nil",
",",
"headers",
",",
"queryParams",
")",
"\n",
"}"
] | // 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 |
3,103 | 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",
",",
"output",
":",
"output",
",",
"}",
"\n",
"return",
"md",
".",
"generate",
"(",
")",
"\n",
"default",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"format",
")",
"\n",
"}",
"\n",
"}"
] | // 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 |
3,104 | 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 |
3,105 | 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",
".",
"generateEnums",
"(",
"dir",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"filename",
":=",
"filepath",
".",
"Join",
"(",
"dir",
",",
"s",
".",
"Name",
"+",
"\"",
"\"",
")",
"\n",
"return",
"commons",
".",
"GenerateFile",
"(",
"s",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"filename",
",",
"true",
")",
"\n",
"}"
] | // Generate generates struct code | [
"Generate",
"generates",
"struct",
"code"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/capnp/struct.go#L61-L71 |
3,106 | 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",
":=",
"f",
".",
"Enum",
".",
"generate",
"(",
"dir",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // 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 |
3,107 | 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",
"}",
"\n\n",
"return",
"NewJSONSchemaFromProps",
"(",
"&",
"t",
",",
"t",
".",
"Properties",
",",
"typ",
",",
"name",
")",
"\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 |
3,108 | 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 !isPropTypeSupported(rp) {
continue
}
p := newProperty(rp)
props[p.Name] = p
if p.Required {
required = append(required, p.Name)
}
}
// we need it to be sorted for testing purpose
sort.Strings(required)
js := JSONSchema{
Schema: schemaVer,
Name: name,
Type: typ,
T: t,
Properties: props,
Required: required,
}
if js.T == nil {
js.T = &Type{
Type: typ,
Properties: properties,
}
}
return js
} | 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 !isPropTypeSupported(rp) {
continue
}
p := newProperty(rp)
props[p.Name] = p
if p.Required {
required = append(required, p.Name)
}
}
// we need it to be sorted for testing purpose
sort.Strings(required)
js := JSONSchema{
Schema: schemaVer,
Name: name,
Type: typ,
T: t,
Properties: props,
Required: required,
}
if js.T == nil {
js.T = &Type{
Type: typ,
Properties: properties,
}
}
return js
} | [
"func",
"NewJSONSchemaFromProps",
"(",
"t",
"*",
"Type",
",",
"properties",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"typ",
",",
"name",
"string",
")",
"JSONSchema",
"{",
"var",
"required",
"[",
"]",
"string",
"\n\n",
"if",
"isTypeArray",
"(",
"typ",
")",
"{",
"return",
"newArraySchema",
"(",
"t",
",",
"typ",
",",
"name",
")",
"\n",
"}",
"\n\n",
"props",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"property",
",",
"len",
"(",
"properties",
")",
")",
"\n",
"for",
"name",
":=",
"range",
"properties",
"{",
"rp",
":=",
"t",
".",
"GetProperty",
"(",
"name",
")",
"\n",
"if",
"!",
"isPropTypeSupported",
"(",
"rp",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"p",
":=",
"newProperty",
"(",
"rp",
")",
"\n",
"props",
"[",
"p",
".",
"Name",
"]",
"=",
"p",
"\n",
"if",
"p",
".",
"Required",
"{",
"required",
"=",
"append",
"(",
"required",
",",
"p",
".",
"Name",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// we need it to be sorted for testing purpose",
"sort",
".",
"Strings",
"(",
"required",
")",
"\n",
"js",
":=",
"JSONSchema",
"{",
"Schema",
":",
"schemaVer",
",",
"Name",
":",
"name",
",",
"Type",
":",
"typ",
",",
"T",
":",
"t",
",",
"Properties",
":",
"props",
",",
"Required",
":",
"required",
",",
"}",
"\n",
"if",
"js",
".",
"T",
"==",
"nil",
"{",
"js",
".",
"T",
"=",
"&",
"Type",
"{",
"Type",
":",
"typ",
",",
"Properties",
":",
"properties",
",",
"}",
"\n",
"}",
"\n",
"return",
"js",
"\n",
"}"
] | // 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 |
3,109 | 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, prop := range parent.Properties {
if _, exist := oriProps[name]; !exist {
js.Properties[name] = prop
}
}
for _, name := range parent.Required {
if _, exist := oriProps[name]; !exist {
if !js.isRequired(name) {
js.Required = append(js.Required, name)
}
}
}
}
} | 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, prop := range parent.Properties {
if _, exist := oriProps[name]; !exist {
js.Properties[name] = prop
}
}
for _, name := range parent.Required {
if _, exist := oriProps[name]; !exist {
if !js.isRequired(name) {
js.Required = append(js.Required, name)
}
}
}
}
} | [
"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",
"{",
"}",
"{",
"}",
"\n",
"for",
"name",
",",
"prop",
":=",
"range",
"js",
".",
"Properties",
"{",
"oriProps",
"[",
"name",
"]",
"=",
"prop",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"parent",
":=",
"range",
"parents",
"{",
"for",
"name",
",",
"prop",
":=",
"range",
"parent",
".",
"Properties",
"{",
"if",
"_",
",",
"exist",
":=",
"oriProps",
"[",
"name",
"]",
";",
"!",
"exist",
"{",
"js",
".",
"Properties",
"[",
"name",
"]",
"=",
"prop",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"parent",
".",
"Required",
"{",
"if",
"_",
",",
"exist",
":=",
"oriProps",
"[",
"name",
"]",
";",
"!",
"exist",
"{",
"if",
"!",
"js",
".",
"isRequired",
"(",
"name",
")",
"{",
"js",
".",
"Required",
"=",
"append",
"(",
"js",
".",
"Required",
",",
"name",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"}"
] | // 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 |
3,110 | 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",
"for",
"name",
",",
"prop",
":=",
"range",
"js",
".",
"Properties",
"{",
"props",
"[",
"name",
"]",
"=",
"prop",
".",
"toRAMLProperty",
"(",
")",
"\n",
"}",
"\n",
"return",
"props",
"\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 |
3,111 | 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 variables
globAPIDef = apiDef
globLibRootURLs = libRootURLs
templates := templates(serverKindSanic)
return &SanicServer{
APIDef: apiDef,
Title: apiDef.Title,
apiDocsDir: apiDocsDir,
withMain: withMain,
ResourcesDef: prs,
Template: templates,
targetDir: targetDir,
}
} | 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 variables
globAPIDef = apiDef
globLibRootURLs = libRootURLs
templates := templates(serverKindSanic)
return &SanicServer{
APIDef: apiDef,
Title: apiDef.Title,
apiDocsDir: apiDocsDir,
withMain: withMain,
ResourcesDef: prs,
Template: templates,
targetDir: targetDir,
}
} | [
"func",
"NewSanicServer",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"apiDocsDir",
",",
"targetDir",
"string",
",",
"withMain",
"bool",
",",
"libRootURLs",
"[",
"]",
"string",
")",
"*",
"SanicServer",
"{",
"var",
"prs",
"[",
"]",
"pythonResource",
"\n",
"for",
"_",
",",
"rd",
":=",
"range",
"getServerResourcesDefs",
"(",
"apiDef",
")",
"{",
"pr",
":=",
"newResource",
"(",
"rd",
",",
"apiDef",
",",
"serverKindSanic",
")",
"\n",
"prs",
"=",
"append",
"(",
"prs",
",",
"pr",
")",
"\n",
"}",
"\n\n",
"// TODO : get rid of this global variables",
"globAPIDef",
"=",
"apiDef",
"\n",
"globLibRootURLs",
"=",
"libRootURLs",
"\n\n",
"templates",
":=",
"templates",
"(",
"serverKindSanic",
")",
"\n\n",
"return",
"&",
"SanicServer",
"{",
"APIDef",
":",
"apiDef",
",",
"Title",
":",
"apiDef",
".",
"Title",
",",
"apiDocsDir",
":",
"apiDocsDir",
",",
"withMain",
":",
"withMain",
",",
"ResourcesDef",
":",
"prs",
",",
"Template",
":",
"templates",
",",
"targetDir",
":",
"targetDir",
",",
"}",
"\n",
"}"
] | // 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 |
3,112 | 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",
"obj",
".",
"handleAdvancedType",
"(",
")",
"\n",
"return",
"obj",
"\n",
"}"
] | // 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 |
3,113 | 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")
if err := commons.GenerateFile(o, "./templates/nim/object_nim.tmpl", "object_nim", filename, true); err != nil {
return err
}
return nil
} | 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")
if err := commons.GenerateFile(o, "./templates/nim/object_nim.tmpl", "object_nim", filename, true); err != nil {
return err
}
return nil
} | [
"func",
"(",
"o",
"*",
"object",
")",
"generate",
"(",
"dir",
"string",
")",
"error",
"{",
"o",
".",
"handleAdvancedType",
"(",
")",
"\n\n",
"// generate enums",
"for",
"_",
",",
"f",
":=",
"range",
"o",
".",
"Fields",
"{",
"if",
"f",
".",
"Enum",
"!=",
"nil",
"{",
"if",
"err",
":=",
"f",
".",
"Enum",
".",
"generate",
"(",
"dir",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"o",
".",
"Enum",
"!=",
"nil",
"{",
"return",
"o",
".",
"Enum",
".",
"generate",
"(",
"dir",
")",
"\n",
"}",
"\n",
"filename",
":=",
"filepath",
".",
"Join",
"(",
"dir",
",",
"o",
".",
"Name",
"(",
")",
"+",
"\"",
"\"",
")",
"\n",
"if",
"err",
":=",
"commons",
".",
"GenerateFile",
"(",
"o",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"filename",
",",
"true",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // generate nim object representation | [
"generate",
"nim",
"object",
"representation"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/nim/object.go#L147-L167 |
3,114 | 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.IsArray():
o.makeArray(strType)
}
} | 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.IsArray():
o.makeArray(strType)
}
} | [
"func",
"(",
"o",
"*",
"object",
")",
"handleAdvancedType",
"(",
")",
"{",
"strType",
":=",
"o",
".",
"T",
".",
"TypeString",
"(",
")",
"\n\n",
"parents",
",",
"isMultipleInheritance",
":=",
"o",
".",
"T",
".",
"MultipleInheritance",
"(",
")",
"\n",
"switch",
"{",
"case",
"isMultipleInheritance",
":",
"//multiple inheritance",
"o",
".",
"inherit",
"(",
"parents",
")",
"\n",
"case",
"o",
".",
"T",
".",
"IsEnum",
"(",
")",
":",
"o",
".",
"makeEnum",
"(",
")",
"\n",
"case",
"strType",
"==",
"\"",
"\"",
"||",
"strType",
"==",
"\"",
"\"",
":",
"// plain type",
"case",
"o",
".",
"T",
".",
"IsArray",
"(",
")",
":",
"o",
".",
"makeArray",
"(",
"strType",
")",
"\n",
"}",
"\n",
"}"
] | // 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 |
3,115 | 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",
",",
"ok",
"\n",
"}"
] | // 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 |
3,116 | 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, "[")
inBracket = inBracket[last+1:]
return strings.TrimSuffix(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, "[")
inBracket = inBracket[last+1:]
return strings.TrimSuffix(inBracket, "]")
} | [
"func",
"extractTypeName",
"(",
"tip",
"string",
")",
"string",
"{",
"// trim all spaces",
"tip",
"=",
"strings",
".",
"TrimSpace",
"(",
"tip",
")",
"\n\n",
"// detect array",
"if",
"strings",
".",
"Index",
"(",
"tip",
",",
"\"",
"\"",
")",
"<",
"0",
"{",
"return",
"tip",
"\n",
"}",
"\n\n",
"// find type inside square bracket",
"inBracket",
":=",
"reSquareBracket",
".",
"FindString",
"(",
"tip",
")",
"\n",
"if",
"inBracket",
"==",
"\"",
"\"",
"{",
"return",
"tip",
"\n",
"}",
"\n",
"last",
":=",
"strings",
".",
"LastIndex",
"(",
"inBracket",
",",
"\"",
"\"",
")",
"\n",
"inBracket",
"=",
"inBracket",
"[",
"last",
"+",
"1",
":",
"]",
"\n",
"return",
"strings",
".",
"TrimSuffix",
"(",
"inBracket",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // 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 |
3,117 | 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()
}
}
if needImportGoraml {
ip[`"`+joinImportPath(globRootImportPath, "goraml")+`"`] = struct{}{}
}
return ip
} | 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()
}
}
if needImportGoraml {
ip[`"`+joinImportPath(globRootImportPath, "goraml")+`"`] = struct{}{}
}
return ip
} | [
"func",
"(",
"cs",
"ClientService",
")",
"libImportPaths",
"(",
")",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
"{",
"ip",
":=",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
"{",
"}",
"\n\n",
"var",
"needImportGoraml",
"bool",
"\n",
"// methods",
"for",
"_",
",",
"gm",
":=",
"range",
"cs",
".",
"Methods",
"{",
"for",
"lib",
":=",
"range",
"gm",
".",
"libImported",
"(",
"globRootImportPath",
")",
"{",
"ip",
"[",
"lib",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"if",
"!",
"needImportGoraml",
"{",
"needImportGoraml",
"=",
"gm",
".",
"needImportGoraml",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"needImportGoraml",
"{",
"ip",
"[",
"`\"`",
"+",
"joinImportPath",
"(",
"globRootImportPath",
",",
"\"",
"\"",
")",
"+",
"`\"`",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"return",
"ip",
"\n",
"}"
] | // 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 |
3,118 | 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,
}
return gl
} | 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,
}
return gl
} | [
"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",
",",
"}",
"\n",
"return",
"gl",
"\n",
"}"
] | // create new library instance | [
"create",
"new",
"library",
"instance"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/libraries.go#L34-L45 |
3,119 | 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",
"}",
"\n\n",
"fileDir",
":=",
"goLibPackageDir",
"(",
"gl",
".",
"name",
",",
"libraries",
".",
"StripLibRootURL",
"(",
"gl",
".",
"Filename",
",",
"gl",
".",
"libRootURLs",
")",
")",
"\n\n",
"return",
"filepath",
".",
"Join",
"(",
"baseDir",
",",
"fileDir",
")",
"\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 |
3,120 | 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
libName := strings.Split(typ, ".")[0]
if libName == "goraml" { // special package name, reserved for goraml
return fmt.Sprintf(`"%s"`, joinImportPath(rootImportPath, "goraml"))
}
// raml file of this lib
libDir, libFile := globAPIDef.FindLibFile(commons.DenormalizePkgName(libName))
if libFile == "" {
return ""
}
libPath := libraries.JoinPath(libDir, libFile, libRootURLs)
importPath := joinImportPath(rootImportPath, path.Join(goLibPackageDir(libName, libPath), typeDir))
return aliasLibTypeImportPath(importPath)
} | 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
libName := strings.Split(typ, ".")[0]
if libName == "goraml" { // special package name, reserved for goraml
return fmt.Sprintf(`"%s"`, joinImportPath(rootImportPath, "goraml"))
}
// raml file of this lib
libDir, libFile := globAPIDef.FindLibFile(commons.DenormalizePkgName(libName))
if libFile == "" {
return ""
}
libPath := libraries.JoinPath(libDir, libFile, libRootURLs)
importPath := joinImportPath(rootImportPath, path.Join(goLibPackageDir(libName, libPath), typeDir))
return aliasLibTypeImportPath(importPath)
} | [
"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",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"strings",
".",
"Index",
"(",
"typ",
",",
"\"",
"\"",
")",
">=",
"0",
"{",
"return",
"`\"encoding/json\"`",
"\n",
"}",
"\n\n",
"// library name in the current document",
"libName",
":=",
"strings",
".",
"Split",
"(",
"typ",
",",
"\"",
"\"",
")",
"[",
"0",
"]",
"\n\n",
"if",
"libName",
"==",
"\"",
"\"",
"{",
"// special package name, reserved for goraml",
"return",
"fmt",
".",
"Sprintf",
"(",
"`\"%s\"`",
",",
"joinImportPath",
"(",
"rootImportPath",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"// raml file of this lib",
"libDir",
",",
"libFile",
":=",
"globAPIDef",
".",
"FindLibFile",
"(",
"commons",
".",
"DenormalizePkgName",
"(",
"libName",
")",
")",
"\n\n",
"if",
"libFile",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"libPath",
":=",
"libraries",
".",
"JoinPath",
"(",
"libDir",
",",
"libFile",
",",
"libRootURLs",
")",
"\n\n",
"importPath",
":=",
"joinImportPath",
"(",
"rootImportPath",
",",
"path",
".",
"Join",
"(",
"goLibPackageDir",
"(",
"libName",
",",
"libPath",
")",
",",
"typeDir",
")",
")",
"\n",
"return",
"aliasLibTypeImportPath",
"(",
"importPath",
")",
"\n",
"}"
] | // 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 |
3,121 | 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",
".",
"Split",
"(",
"dir",
",",
"\"",
"\"",
")",
"\n",
"elems",
"[",
"len",
"(",
"elems",
")",
"-",
"1",
"]",
"=",
"commons",
".",
"NormalizeIdentifier",
"(",
"elems",
"[",
"len",
"(",
"elems",
")",
"-",
"1",
"]",
")",
"\n",
"return",
"strings",
".",
"Join",
"(",
"elems",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // 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 |
3,122 | 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",
",",
"resp",
".",
"Type",
"(",
")",
")",
"\n",
"}",
"\n",
"types",
"=",
"append",
"(",
"types",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"...",
")",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"types",
",",
"\"",
"\"",
")",
")",
"\n",
"}"
] | // 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 |
3,123 | 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 |
3,124 | 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
if err := c.generateMain(); err != nil {
return err
}
return nil
} | 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
if err := c.generateMain(); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Generate",
"(",
")",
"error",
"{",
"rs",
":=",
"getAllResources",
"(",
"c",
".",
"APIDef",
",",
"false",
")",
"\n\n",
"if",
"err",
":=",
"generateAllObjects",
"(",
"c",
".",
"APIDef",
",",
"c",
".",
"Dir",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// services files",
"if",
"err",
":=",
"c",
".",
"generateServices",
"(",
"rs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"generateSecurity",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// main client file",
"if",
"err",
":=",
"c",
".",
"generateMain",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // 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 |
3,125 | 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",
"(",
"splt",
"[",
"0",
"]",
")",
"\n",
"}"
] | // 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 |
3,126 | 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",
"return",
"commons",
".",
"GenerateFile",
"(",
"gr",
",",
"resourceIfTemplate",
",",
"\"",
"\"",
",",
"filename",
",",
"true",
")",
"\n",
"}"
] | // 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 |
3,127 | 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)+"_api")
if err := commons.GenerateFile(mainCtx, "./templates/golang/server_resource_api_main_go.tmpl",
"server_resource_api_main_go", mainFile+".go", false); err != nil {
return err
}
// generate per methods file
for _, sm := range gr.Methods {
ctx := map[string]interface{}{
"Method": sm,
"APIName": gr.Name,
"PackageName": gr.PackageName,
}
filename := mainFile + "_" + sm.MethodName + ".go"
if err := commons.GenerateFile(ctx, "./templates/golang/server_resource_api_impl_go.tmpl",
"server_resource_api_impl_go", filename, false); err != nil {
return err
}
}
return nil
} | 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)+"_api")
if err := commons.GenerateFile(mainCtx, "./templates/golang/server_resource_api_main_go.tmpl",
"server_resource_api_main_go", mainFile+".go", false); err != nil {
return err
}
// generate per methods file
for _, sm := range gr.Methods {
ctx := map[string]interface{}{
"Method": sm,
"APIName": gr.Name,
"PackageName": gr.PackageName,
}
filename := mainFile + "_" + sm.MethodName + ".go"
if err := commons.GenerateFile(ctx, "./templates/golang/server_resource_api_impl_go.tmpl",
"server_resource_api_impl_go", filename, false); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"gr",
"*",
"goResource",
")",
"generateAPIImplementations",
"(",
"dir",
"string",
")",
"error",
"{",
"// generate the main API impl file, which only contains struct",
"mainCtx",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"gr",
".",
"PackageName",
",",
"\"",
"\"",
":",
"gr",
".",
"Name",
",",
"\"",
"\"",
":",
"gr",
".",
"Endpoint",
",",
"}",
"\n\n",
"mainFile",
":=",
"filepath",
".",
"Join",
"(",
"dir",
",",
"strings",
".",
"ToLower",
"(",
"gr",
".",
"Name",
")",
"+",
"\"",
"\"",
")",
"\n",
"if",
"err",
":=",
"commons",
".",
"GenerateFile",
"(",
"mainCtx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"mainFile",
"+",
"\"",
"\"",
",",
"false",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// generate per methods file",
"for",
"_",
",",
"sm",
":=",
"range",
"gr",
".",
"Methods",
"{",
"ctx",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"sm",
",",
"\"",
"\"",
":",
"gr",
".",
"Name",
",",
"\"",
"\"",
":",
"gr",
".",
"PackageName",
",",
"}",
"\n",
"filename",
":=",
"mainFile",
"+",
"\"",
"\"",
"+",
"sm",
".",
"MethodName",
"+",
"\"",
"\"",
"\n",
"if",
"err",
":=",
"commons",
".",
"GenerateFile",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"filename",
",",
"false",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // 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 |
3,128 | 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/justinas/alice"] = struct{}{}
}
for _, sb := range gm.SecuredBy {
if lib := libImportPath(globRootImportPath, sb.Name, globLibRootURLs); lib != "" {
ip[lib] = struct{}{}
}
}
}
// return sorted array for predictable order
// we need it for unit test to always return same order
return commons.MapToSortedStrings(ip)
} | 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/justinas/alice"] = struct{}{}
}
for _, sb := range gm.SecuredBy {
if lib := libImportPath(globRootImportPath, sb.Name, globLibRootURLs); lib != "" {
ip[lib] = struct{}{}
}
}
}
// return sorted array for predictable order
// we need it for unit test to always return same order
return commons.MapToSortedStrings(ip)
} | [
"func",
"(",
"gr",
"goResource",
")",
"InterfaceImportPaths",
"(",
")",
"[",
"]",
"string",
"{",
"ip",
":=",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
"{",
"\"",
"\"",
":",
"struct",
"{",
"}",
"{",
"}",
",",
"\"",
"\"",
":",
"struct",
"{",
"}",
"{",
"}",
",",
"}",
"\n\n",
"for",
"_",
",",
"gm",
":=",
"range",
"gr",
".",
"Methods",
"{",
"// if has middleware, we need to import middleware helper library",
"if",
"len",
"(",
"gm",
".",
"Middlewares",
")",
">",
"0",
"{",
"ip",
"[",
"\"",
"\"",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"sb",
":=",
"range",
"gm",
".",
"SecuredBy",
"{",
"if",
"lib",
":=",
"libImportPath",
"(",
"globRootImportPath",
",",
"sb",
".",
"Name",
",",
"globLibRootURLs",
")",
";",
"lib",
"!=",
"\"",
"\"",
"{",
"ip",
"[",
"lib",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"// return sorted array for predictable order",
"// we need it for unit test to always return same order",
"return",
"commons",
".",
"MapToSortedStrings",
"(",
"ip",
")",
"\n",
"}"
] | // 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 |
3,129 | 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.MapToSortedStrings(ip)
} | 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.MapToSortedStrings(ip)
} | [
"func",
"(",
"gr",
"goResource",
")",
"APILibImportPaths",
"(",
")",
"[",
"]",
"string",
"{",
"ip",
":=",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
"{",
"}",
"\n\n",
"// methods",
"for",
"_",
",",
"gm",
":=",
"range",
"gr",
".",
"Methods",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"gm",
".",
"Imports",
"(",
")",
"{",
"ip",
"[",
"v",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// return sorted array for predictable order",
"// we need it for unit test to always return same order",
"return",
"commons",
".",
"MapToSortedStrings",
"(",
"ip",
")",
"\n",
"}"
] | // 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 |
3,130 | 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 NewFlaskServer(apiDef, apiDocsDir, targetDir, true, libRootURLs, true)
case serverKindSanic:
return NewSanicServer(apiDef, apiDocsDir, targetDir, withMain, libRootURLs)
default:
log.Fatalf("Invalid kind of python server : %v", kind)
return nil
}
} | 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 NewFlaskServer(apiDef, apiDocsDir, targetDir, true, libRootURLs, true)
case serverKindSanic:
return NewSanicServer(apiDef, apiDocsDir, targetDir, withMain, libRootURLs)
default:
log.Fatalf("Invalid kind of python server : %v", kind)
return nil
}
} | [
"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",
")",
"\n",
"case",
"serverKindGeventFlask",
":",
"return",
"NewFlaskServer",
"(",
"apiDef",
",",
"apiDocsDir",
",",
"targetDir",
",",
"true",
",",
"libRootURLs",
",",
"true",
")",
"\n",
"case",
"serverKindSanic",
":",
"return",
"NewSanicServer",
"(",
"apiDef",
",",
"apiDocsDir",
",",
"targetDir",
",",
"withMain",
",",
"libRootURLs",
")",
"\n\n",
"default",
":",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"kind",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // 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 |
3,131 | 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 kind {
case "":
kind = clientNameRequests
case clientNameRequests, clientNameAiohttp, clientNameGeventRequests:
default:
log.Fatalf("invalid client kind:%v", kind)
}
c := Client{
Name: commons.NormalizeURI(apiDef.Title),
APIDef: apiDef,
BaseURI: apiDef.BaseURI,
Services: services,
Kind: kind,
UnmarshallResponse: unmarshallResponse,
}
if strings.Index(c.BaseURI, "{version}") > 0 {
c.BaseURI = strings.Replace(c.BaseURI, "{version}", apiDef.Version, -1)
}
c.initTemplates()
c.Securities = getClientSecurityDefs(apiDef.SecuritySchemes, c.Template)
return c
} | 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 kind {
case "":
kind = clientNameRequests
case clientNameRequests, clientNameAiohttp, clientNameGeventRequests:
default:
log.Fatalf("invalid client kind:%v", kind)
}
c := Client{
Name: commons.NormalizeURI(apiDef.Title),
APIDef: apiDef,
BaseURI: apiDef.BaseURI,
Services: services,
Kind: kind,
UnmarshallResponse: unmarshallResponse,
}
if strings.Index(c.BaseURI, "{version}") > 0 {
c.BaseURI = strings.Replace(c.BaseURI, "{version}", apiDef.Version, -1)
}
c.initTemplates()
c.Securities = getClientSecurityDefs(apiDef.SecuritySchemes, c.Template)
return c
} | [
"func",
"NewClient",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"kind",
"string",
",",
"unmarshallResponse",
"bool",
")",
"Client",
"{",
"services",
":=",
"map",
"[",
"string",
"]",
"*",
"service",
"{",
"}",
"\n",
"for",
"uri",
",",
"res",
":=",
"range",
"apiDef",
".",
"Resources",
"{",
"rd",
":=",
"resource",
".",
"New",
"(",
"apiDef",
",",
"&",
"res",
",",
"commons",
".",
"NormalizeURITitle",
"(",
"apiDef",
".",
"Title",
")",
",",
"false",
")",
"\n",
"services",
"[",
"uri",
"]",
"=",
"newService",
"(",
"uri",
",",
"&",
"rd",
",",
"unmarshallResponse",
")",
"\n",
"}",
"\n",
"switch",
"kind",
"{",
"case",
"\"",
"\"",
":",
"kind",
"=",
"clientNameRequests",
"\n",
"case",
"clientNameRequests",
",",
"clientNameAiohttp",
",",
"clientNameGeventRequests",
":",
"default",
":",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"kind",
")",
"\n",
"}",
"\n\n",
"c",
":=",
"Client",
"{",
"Name",
":",
"commons",
".",
"NormalizeURI",
"(",
"apiDef",
".",
"Title",
")",
",",
"APIDef",
":",
"apiDef",
",",
"BaseURI",
":",
"apiDef",
".",
"BaseURI",
",",
"Services",
":",
"services",
",",
"Kind",
":",
"kind",
",",
"UnmarshallResponse",
":",
"unmarshallResponse",
",",
"}",
"\n",
"if",
"strings",
".",
"Index",
"(",
"c",
".",
"BaseURI",
",",
"\"",
"\"",
")",
">",
"0",
"{",
"c",
".",
"BaseURI",
"=",
"strings",
".",
"Replace",
"(",
"c",
".",
"BaseURI",
",",
"\"",
"\"",
",",
"apiDef",
".",
"Version",
",",
"-",
"1",
")",
"\n",
"}",
"\n",
"c",
".",
"initTemplates",
"(",
")",
"\n",
"c",
".",
"Securities",
"=",
"getClientSecurityDefs",
"(",
"apiDef",
".",
"SecuritySchemes",
",",
"c",
".",
"Template",
")",
"\n\n",
"return",
"c",
"\n",
"}"
] | // 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 |
3,132 | 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.GenerateFile(nil, c.Template.httpClientFile, c.Template.httpClientName, filepath.Join(dir, "http_client.py"), true); err != nil {
return err
}
if err := c.generateServices(dir); err != nil {
return err
}
if err := c.generateSecurity(dir); err != nil {
return err
}
// python classes
classes, err := GenerateAllClasses(c.APIDef, dir, false)
if err != nil {
return err
}
// helper for python classes
if err := commons.GenerateFile(nil, "./templates/python/client_support.tmpl",
"client_support", filepath.Join(dir, "client_support.py"), true); err != nil {
return err
}
if c.UnmarshallResponse {
if err := commons.GenerateFile(nil, "./templates/python/unmarshall_error.tmpl",
"unmarshall_error", filepath.Join(dir, "unmarshall_error.py"), true); err != nil {
return err
}
if err := commons.GenerateFile(nil, "./templates/python/unhandled_api_error.tmpl",
"unhandled_api_error", filepath.Join(dir, "unhandled_api_error.py"), true); err != nil {
return err
}
}
sort.Strings(classes)
c.Classes = classes
return commons.GenerateFile(c, c.Template.initFile, c.Template.initName, filepath.Join(dir, "__init__.py"), true)
} | 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.GenerateFile(nil, c.Template.httpClientFile, c.Template.httpClientName, filepath.Join(dir, "http_client.py"), true); err != nil {
return err
}
if err := c.generateServices(dir); err != nil {
return err
}
if err := c.generateSecurity(dir); err != nil {
return err
}
// python classes
classes, err := GenerateAllClasses(c.APIDef, dir, false)
if err != nil {
return err
}
// helper for python classes
if err := commons.GenerateFile(nil, "./templates/python/client_support.tmpl",
"client_support", filepath.Join(dir, "client_support.py"), true); err != nil {
return err
}
if c.UnmarshallResponse {
if err := commons.GenerateFile(nil, "./templates/python/unmarshall_error.tmpl",
"unmarshall_error", filepath.Join(dir, "unmarshall_error.py"), true); err != nil {
return err
}
if err := commons.GenerateFile(nil, "./templates/python/unhandled_api_error.tmpl",
"unhandled_api_error", filepath.Join(dir, "unhandled_api_error.py"), true); err != nil {
return err
}
}
sort.Strings(classes)
c.Classes = classes
return commons.GenerateFile(c, c.Template.initFile, c.Template.initName, filepath.Join(dir, "__init__.py"), true)
} | [
"func",
"(",
"c",
"Client",
")",
"Generate",
"(",
"dir",
"string",
")",
"error",
"{",
"globAPIDef",
"=",
"c",
".",
"APIDef",
"\n\n",
"// generate helper",
"if",
"err",
":=",
"commons",
".",
"GenerateFile",
"(",
"nil",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"filepath",
".",
"Join",
"(",
"dir",
",",
"\"",
"\"",
")",
",",
"true",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// generate http client",
"if",
"err",
":=",
"commons",
".",
"GenerateFile",
"(",
"nil",
",",
"c",
".",
"Template",
".",
"httpClientFile",
",",
"c",
".",
"Template",
".",
"httpClientName",
",",
"filepath",
".",
"Join",
"(",
"dir",
",",
"\"",
"\"",
")",
",",
"true",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"generateServices",
"(",
"dir",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"generateSecurity",
"(",
"dir",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// python classes",
"classes",
",",
"err",
":=",
"GenerateAllClasses",
"(",
"c",
".",
"APIDef",
",",
"dir",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// helper for python classes",
"if",
"err",
":=",
"commons",
".",
"GenerateFile",
"(",
"nil",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"filepath",
".",
"Join",
"(",
"dir",
",",
"\"",
"\"",
")",
",",
"true",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"UnmarshallResponse",
"{",
"if",
"err",
":=",
"commons",
".",
"GenerateFile",
"(",
"nil",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"filepath",
".",
"Join",
"(",
"dir",
",",
"\"",
"\"",
")",
",",
"true",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"commons",
".",
"GenerateFile",
"(",
"nil",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"filepath",
".",
"Join",
"(",
"dir",
",",
"\"",
"\"",
")",
",",
"true",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"sort",
".",
"Strings",
"(",
"classes",
")",
"\n",
"c",
".",
"Classes",
"=",
"classes",
"\n",
"return",
"commons",
".",
"GenerateFile",
"(",
"c",
",",
"c",
".",
"Template",
".",
"initFile",
",",
"c",
".",
"Template",
".",
"initName",
",",
"filepath",
".",
"Join",
"(",
"dir",
",",
"\"",
"\"",
")",
",",
"true",
")",
"\n",
"}"
] | // 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 |
3,133 | 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 := range resources {
keys = append(keys, k)
}
sort.Strings(keys)
// create resource def
var err error
for _, endpoint := range keys {
r := resources[endpoint]
rd := resource.New(s.apiDef, &r, endpoint, true)
pkgName := strings.ToLower(commons.NormalizeIdentifier(rd.Name))
gr := newGoResource(&rd, pkgName)
err = gr.generate(&r, endpoint, dir, s.libsRootURLs)
if err != nil {
return nil, err
}
serverResources = append(serverResources, gr)
}
return serverResources, nil
} | 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 := range resources {
keys = append(keys, k)
}
sort.Strings(keys)
// create resource def
var err error
for _, endpoint := range keys {
r := resources[endpoint]
rd := resource.New(s.apiDef, &r, endpoint, true)
pkgName := strings.ToLower(commons.NormalizeIdentifier(rd.Name))
gr := newGoResource(&rd, pkgName)
err = gr.generate(&r, endpoint, dir, s.libsRootURLs)
if err != nil {
return nil, err
}
serverResources = append(serverResources, gr)
}
return serverResources, nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"generateServerResources",
"(",
"dir",
"string",
")",
"(",
"[",
"]",
"*",
"goResource",
",",
"error",
")",
"{",
"var",
"serverResources",
"[",
"]",
"*",
"goResource",
"\n\n",
"resources",
":=",
"s",
".",
"apiDef",
".",
"Resources",
"\n\n",
"// 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",
"\n",
"for",
"k",
":=",
"range",
"resources",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"k",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"keys",
")",
"\n\n",
"// create resource def",
"var",
"err",
"error",
"\n",
"for",
"_",
",",
"endpoint",
":=",
"range",
"keys",
"{",
"r",
":=",
"resources",
"[",
"endpoint",
"]",
"\n",
"rd",
":=",
"resource",
".",
"New",
"(",
"s",
".",
"apiDef",
",",
"&",
"r",
",",
"endpoint",
",",
"true",
")",
"\n",
"pkgName",
":=",
"strings",
".",
"ToLower",
"(",
"commons",
".",
"NormalizeIdentifier",
"(",
"rd",
".",
"Name",
")",
")",
"\n",
"gr",
":=",
"newGoResource",
"(",
"&",
"rd",
",",
"pkgName",
")",
"\n",
"err",
"=",
"gr",
".",
"generate",
"(",
"&",
"r",
",",
"endpoint",
",",
"dir",
",",
"s",
".",
"libsRootURLs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"serverResources",
"=",
"append",
"(",
"serverResources",
",",
"gr",
")",
"\n",
"}",
"\n",
"return",
"serverResources",
",",
"nil",
"\n",
"}"
] | // 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 |
3,134 | 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",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n\n",
"}"
] | // 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 |
3,135 | 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",
".",
"TrimSpace",
"(",
"desc",
")",
"\n\n",
"if",
"desc",
"==",
"\"",
"\"",
"{",
"return",
"[",
"]",
"string",
"{",
"}",
"\n",
"}",
"\n\n",
"return",
"strings",
".",
"Split",
"(",
"desc",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"}"
] | // 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 |
3,136 | 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 function to template
funcMap := template.FuncMap{
"ToLower": strings.ToLower,
}
// all template files path is relative to current directory (./)
// while go-bindata files exist in templates directory
tmplFile = strings.Replace(tmplFile, "./", "", -1)
byteData, err := templates.Asset(tmplFile)
if err != nil {
return err
}
t, err := template.New(tmplName).Funcs(funcMap).Parse(string(byteData))
if err != nil {
return err
}
f, err := os.Create(filename)
if err != nil {
return err
}
defer f.Close()
log.Infof("generating file %v", filename)
if err := t.ExecuteTemplate(f, tmplName, data); err != nil {
return err
}
switch {
case strings.HasSuffix(filename, ".go"):
return runGoFmt(filename)
case strings.HasSuffix(filename, ".py"):
return runAutoPep8(filename)
}
return nil
} | 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 Go function to template
funcMap := template.FuncMap{
"ToLower": strings.ToLower,
}
// all template files path is relative to current directory (./)
// while go-bindata files exist in templates directory
tmplFile = strings.Replace(tmplFile, "./", "", -1)
byteData, err := templates.Asset(tmplFile)
if err != nil {
return err
}
t, err := template.New(tmplName).Funcs(funcMap).Parse(string(byteData))
if err != nil {
return err
}
f, err := os.Create(filename)
if err != nil {
return err
}
defer f.Close()
log.Infof("generating file %v", filename)
if err := t.ExecuteTemplate(f, tmplName, data); err != nil {
return err
}
switch {
case strings.HasSuffix(filename, ".go"):
return runGoFmt(filename)
case strings.HasSuffix(filename, ".py"):
return runAutoPep8(filename)
}
return nil
} | [
"func",
"GenerateFile",
"(",
"data",
"interface",
"{",
"}",
",",
"tmplFile",
",",
"tmplName",
",",
"filename",
"string",
",",
"override",
"bool",
")",
"error",
"{",
"if",
"!",
"override",
"&&",
"isFileExist",
"(",
"filename",
")",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"filename",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"checkCreateDir",
"(",
"filepath",
".",
"Dir",
"(",
"filename",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"}",
"\n\n",
"// pass Go function to template",
"funcMap",
":=",
"template",
".",
"FuncMap",
"{",
"\"",
"\"",
":",
"strings",
".",
"ToLower",
",",
"}",
"\n\n",
"// all template files path is relative to current directory (./)",
"// while go-bindata files exist in templates directory",
"tmplFile",
"=",
"strings",
".",
"Replace",
"(",
"tmplFile",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n\n",
"byteData",
",",
"err",
":=",
"templates",
".",
"Asset",
"(",
"tmplFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"t",
",",
"err",
":=",
"template",
".",
"New",
"(",
"tmplName",
")",
".",
"Funcs",
"(",
"funcMap",
")",
".",
"Parse",
"(",
"string",
"(",
"byteData",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"f",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"filename",
")",
"\n",
"if",
"err",
":=",
"t",
".",
"ExecuteTemplate",
"(",
"f",
",",
"tmplName",
",",
"data",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"switch",
"{",
"case",
"strings",
".",
"HasSuffix",
"(",
"filename",
",",
"\"",
"\"",
")",
":",
"return",
"runGoFmt",
"(",
"filename",
")",
"\n",
"case",
"strings",
".",
"HasSuffix",
"(",
"filename",
",",
"\"",
"\"",
")",
":",
"return",
"runAutoPep8",
"(",
"filename",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // 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",
"function",
"to",
"the",
"template"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/commons/commons.go#L79-L125 |
3,137 | 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",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"ss",
")",
"\n",
"return",
"ss",
"\n",
"}"
] | // 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 |
3,138 | 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",
"...",
")",
".",
"CombinedOutput",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"filePath",
",",
"string",
"(",
"out",
")",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // 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 |
3,139 | 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",
"}",
"\n",
"return",
"i",
"\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 |
3,140 | 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 |
3,141 | 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",
")",
"\n",
"}",
"\n",
"return",
"strings",
".",
"Join",
"(",
"names",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // 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 |
3,142 | 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",
"{",
"name",
"=",
"splt",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"strings",
".",
"TrimSuffix",
"(",
"strings",
".",
"TrimPrefix",
"(",
"name",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
")",
"\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 |
3,143 | 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 + suffix)
} | 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 + suffix)
} | [
"func",
"PascalCaseTypeName",
"(",
"tip",
"TypeInBody",
")",
"string",
"{",
"methodName",
":=",
"commons",
".",
"SnackCaseServerMethodName",
"(",
"tip",
".",
"Endpoint",
".",
"Method",
".",
"DisplayName",
",",
"tip",
".",
"Endpoint",
".",
"Verb",
",",
"tip",
".",
"Endpoint",
".",
"Resource",
")",
"\n",
"suffix",
":=",
"commons",
".",
"ReqBodySuffix",
"\n",
"if",
"tip",
".",
"ReqResp",
"==",
"HTTPResponse",
"{",
"suffix",
"=",
"commons",
".",
"RespBodySuffix",
"\n",
"}",
"\n",
"return",
"casee",
".",
"ToPascalCase",
"(",
"methodName",
"+",
"suffix",
")",
"\n",
"}"
] | // 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 |
3,144 | 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.Description = substituteParams(r.Description, rt.Description, dicts)
// uri parameters
if len(r.URIParameters) == 0 {
r.URIParameters = map[string]NamedParameter{}
}
for name, up := range rt.URIParameters {
p, ok := r.URIParameters[name]
if !ok {
p = NamedParameter{}
}
p.inherit(up, dicts)
r.URIParameters[name] = p
}
// methods
r.inheritMethods(rt, apiDef)
return nil
} | 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.Description = substituteParams(r.Description, rt.Description, dicts)
// uri parameters
if len(r.URIParameters) == 0 {
r.URIParameters = map[string]NamedParameter{}
}
for name, up := range rt.URIParameters {
p, ok := r.URIParameters[name]
if !ok {
p = NamedParameter{}
}
p.inherit(up, dicts)
r.URIParameters[name] = p
}
// methods
r.inheritMethods(rt, apiDef)
return nil
} | [
"func",
"(",
"r",
"*",
"Resource",
")",
"inheritResourceType",
"(",
"resourceTypes",
"map",
"[",
"string",
"]",
"ResourceType",
",",
"apiDef",
"*",
"APIDefinition",
")",
"error",
"{",
"// get resource type object to inherit",
"rt",
",",
"err",
":=",
"r",
".",
"getResourceType",
"(",
"resourceTypes",
")",
"\n",
"if",
"rt",
"==",
"nil",
"||",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// initialize dicts",
"dicts",
":=",
"initResourceTypeDicts",
"(",
"r",
",",
"r",
".",
"Type",
".",
"Parameters",
")",
"\n\n",
"r",
".",
"Description",
"=",
"substituteParams",
"(",
"r",
".",
"Description",
",",
"rt",
".",
"Description",
",",
"dicts",
")",
"\n\n",
"// uri parameters",
"if",
"len",
"(",
"r",
".",
"URIParameters",
")",
"==",
"0",
"{",
"r",
".",
"URIParameters",
"=",
"map",
"[",
"string",
"]",
"NamedParameter",
"{",
"}",
"\n",
"}",
"\n",
"for",
"name",
",",
"up",
":=",
"range",
"rt",
".",
"URIParameters",
"{",
"p",
",",
"ok",
":=",
"r",
".",
"URIParameters",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"p",
"=",
"NamedParameter",
"{",
"}",
"\n",
"}",
"\n",
"p",
".",
"inherit",
"(",
"up",
",",
"dicts",
")",
"\n",
"r",
".",
"URIParameters",
"[",
"name",
"]",
"=",
"p",
"\n",
"}",
"\n\n",
"// methods",
"r",
".",
"inheritMethods",
"(",
"rt",
",",
"apiDef",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // inherit from a resource type | [
"inherit",
"from",
"a",
"resource",
"type"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/resource.go#L97-L126 |
3,145 | 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.resourceTypeName = r.Type.Name
m.inheritFromResourceType(r, rtm, rt, apiDef)
}
// inherit optional methods if only the resource also has the method
for _, rtm := range rt.optionalMethods {
m := r.MethodByName(rtm.Name)
if m == nil {
continue
}
m.resourceTypeName = r.Type.Name
m.inheritFromResourceType(r, rtm, rt, apiDef)
}
} | 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.resourceTypeName = r.Type.Name
m.inheritFromResourceType(r, rtm, rt, apiDef)
}
// inherit optional methods if only the resource also has the method
for _, rtm := range rt.optionalMethods {
m := r.MethodByName(rtm.Name)
if m == nil {
continue
}
m.resourceTypeName = r.Type.Name
m.inheritFromResourceType(r, rtm, rt, apiDef)
}
} | [
"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",
")",
"\n",
"if",
"m",
"==",
"nil",
"{",
"m",
"=",
"newMethod",
"(",
"rtm",
".",
"Name",
")",
"\n",
"r",
".",
"assignMethod",
"(",
"m",
",",
"m",
".",
"Name",
")",
"\n",
"}",
"\n",
"m",
".",
"resourceTypeName",
"=",
"r",
".",
"Type",
".",
"Name",
"\n",
"m",
".",
"inheritFromResourceType",
"(",
"r",
",",
"rtm",
",",
"rt",
",",
"apiDef",
")",
"\n",
"}",
"\n\n",
"// inherit optional methods if only the resource also has the method",
"for",
"_",
",",
"rtm",
":=",
"range",
"rt",
".",
"optionalMethods",
"{",
"m",
":=",
"r",
".",
"MethodByName",
"(",
"rtm",
".",
"Name",
")",
"\n",
"if",
"m",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"m",
".",
"resourceTypeName",
"=",
"r",
".",
"Type",
".",
"Name",
"\n",
"m",
".",
"inheritFromResourceType",
"(",
"r",
",",
"rtm",
",",
"rt",
",",
"apiDef",
")",
"\n",
"}",
"\n\n",
"}"
] | // 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 |
3,146 | 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.Type.Name {
return &rt, nil
}
}
return nil, fmt.Errorf("can't find resource type named :%v", r.Type.Name)
} | 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.Type.Name {
return &rt, nil
}
}
return nil, fmt.Errorf("can't find resource type named :%v", r.Type.Name)
} | [
"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",
"\n",
"}",
"\n\n",
"// get resource type from array of resource type map",
"for",
"k",
",",
"rt",
":=",
"range",
"resourceTypes",
"{",
"if",
"k",
"==",
"r",
".",
"Type",
".",
"Name",
"{",
"return",
"&",
"rt",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"r",
".",
"Type",
".",
"Name",
")",
"\n",
"}"
] | // 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 |
3,147 | 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 {
r.Patch.postProcess(r, "PATCH", traitsMap, apiDef)
}
if r.Head != nil {
r.Head.postProcess(r, "HEAD", traitsMap, apiDef)
}
if r.Delete != nil {
r.Delete.postProcess(r, "DELETE", traitsMap, apiDef)
}
if r.Options != nil {
r.Options.postProcess(r, "OPTIONS", traitsMap, apiDef)
}
} | 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 {
r.Patch.postProcess(r, "PATCH", traitsMap, apiDef)
}
if r.Head != nil {
r.Head.postProcess(r, "HEAD", traitsMap, apiDef)
}
if r.Delete != nil {
r.Delete.postProcess(r, "DELETE", traitsMap, apiDef)
}
if r.Options != nil {
r.Options.postProcess(r, "OPTIONS", traitsMap, apiDef)
}
} | [
"func",
"(",
"r",
"*",
"Resource",
")",
"setMethods",
"(",
"traitsMap",
"map",
"[",
"string",
"]",
"Trait",
",",
"apiDef",
"*",
"APIDefinition",
")",
"{",
"if",
"r",
".",
"Get",
"!=",
"nil",
"{",
"r",
".",
"Get",
".",
"postProcess",
"(",
"r",
",",
"\"",
"\"",
",",
"traitsMap",
",",
"apiDef",
")",
"\n",
"}",
"\n",
"if",
"r",
".",
"Post",
"!=",
"nil",
"{",
"r",
".",
"Post",
".",
"postProcess",
"(",
"r",
",",
"\"",
"\"",
",",
"traitsMap",
",",
"apiDef",
")",
"\n",
"}",
"\n",
"if",
"r",
".",
"Put",
"!=",
"nil",
"{",
"r",
".",
"Put",
".",
"postProcess",
"(",
"r",
",",
"\"",
"\"",
",",
"traitsMap",
",",
"apiDef",
")",
"\n",
"}",
"\n",
"if",
"r",
".",
"Patch",
"!=",
"nil",
"{",
"r",
".",
"Patch",
".",
"postProcess",
"(",
"r",
",",
"\"",
"\"",
",",
"traitsMap",
",",
"apiDef",
")",
"\n",
"}",
"\n",
"if",
"r",
".",
"Head",
"!=",
"nil",
"{",
"r",
".",
"Head",
".",
"postProcess",
"(",
"r",
",",
"\"",
"\"",
",",
"traitsMap",
",",
"apiDef",
")",
"\n",
"}",
"\n",
"if",
"r",
".",
"Delete",
"!=",
"nil",
"{",
"r",
".",
"Delete",
".",
"postProcess",
"(",
"r",
",",
"\"",
"\"",
",",
"traitsMap",
",",
"apiDef",
")",
"\n",
"}",
"\n",
"if",
"r",
".",
"Options",
"!=",
"nil",
"{",
"r",
".",
"Options",
".",
"postProcess",
"(",
"r",
",",
"\"",
"\"",
",",
"traitsMap",
",",
"apiDef",
")",
"\n",
"}",
"\n",
"}"
] | // 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 |
3,148 | 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",
"case",
"\"",
"\"",
":",
"return",
"r",
".",
"Put",
"\n",
"case",
"\"",
"\"",
":",
"return",
"r",
".",
"Patch",
"\n",
"case",
"\"",
"\"",
":",
"return",
"r",
".",
"Head",
"\n",
"case",
"\"",
"\"",
":",
"return",
"r",
".",
"Delete",
"\n",
"case",
"\"",
"\"",
":",
"return",
"r",
".",
"Options",
"\n",
"default",
":",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // 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 |
3,149 | 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 toReplace
}
removeParamBracket := func(param string) string {
param = strings.TrimSpace(param)
return param[2 : len(param)-2]
}
// search params
params := dcRe.FindAllString(words, -1)
// substitute the params
for _, p := range params {
pVal, ok := getParamValue(removeParamBracket(p), dicts)
if !ok {
// only replace if param is found
continue
}
words = strings.Replace(words, p, pVal, -1)
}
return words
} | 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 toReplace
}
removeParamBracket := func(param string) string {
param = strings.TrimSpace(param)
return param[2 : len(param)-2]
}
// search params
params := dcRe.FindAllString(words, -1)
// substitute the params
for _, p := range params {
pVal, ok := getParamValue(removeParamBracket(p), dicts)
if !ok {
// only replace if param is found
continue
}
words = strings.Replace(words, p, pVal, -1)
}
return words
} | [
"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",
"\n",
"}",
"\n",
"if",
"words",
"==",
"\"",
"\"",
"{",
"return",
"toReplace",
"\n",
"}",
"\n\n",
"removeParamBracket",
":=",
"func",
"(",
"param",
"string",
")",
"string",
"{",
"param",
"=",
"strings",
".",
"TrimSpace",
"(",
"param",
")",
"\n",
"return",
"param",
"[",
"2",
":",
"len",
"(",
"param",
")",
"-",
"2",
"]",
"\n",
"}",
"\n\n",
"// search params",
"params",
":=",
"dcRe",
".",
"FindAllString",
"(",
"words",
",",
"-",
"1",
")",
"\n\n",
"// substitute the params",
"for",
"_",
",",
"p",
":=",
"range",
"params",
"{",
"pVal",
",",
"ok",
":=",
"getParamValue",
"(",
"removeParamBracket",
"(",
"p",
")",
",",
"dicts",
")",
"\n",
"if",
"!",
"ok",
"{",
"// only replace if param is found",
"continue",
"\n",
"}",
"\n",
"words",
"=",
"strings",
".",
"Replace",
"(",
"words",
",",
"p",
",",
"pVal",
",",
"-",
"1",
")",
"\n",
"}",
"\n",
"return",
"words",
"\n",
"}"
] | // 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 |
3,150 | 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, ""
}
return strings.TrimSpace(arr[0]), strings.TrimSpace(arr[1])
}()
// get the value
val, ok := func() (string, bool) {
// get from type parameters
val, ok := dicts[cleanParam]
if !ok {
return "", false
}
return fmt.Sprintf("%v", val), true
}()
if !ok {
return "", false
}
// inflect the value if needed
if inflectors != "" {
for _, inflector := range strings.Split(inflectors, "|") {
inflector = strings.TrimSpace(inflector)
var ok bool
val, ok = doInflect(val, inflector)
if !ok {
log.Fatalf("invalid inflector " + inflector)
}
}
}
return val, true
} | 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, ""
}
return strings.TrimSpace(arr[0]), strings.TrimSpace(arr[1])
}()
// get the value
val, ok := func() (string, bool) {
// get from type parameters
val, ok := dicts[cleanParam]
if !ok {
return "", false
}
return fmt.Sprintf("%v", val), true
}()
if !ok {
return "", false
}
// inflect the value if needed
if inflectors != "" {
for _, inflector := range strings.Split(inflectors, "|") {
inflector = strings.TrimSpace(inflector)
var ok bool
val, ok = doInflect(val, inflector)
if !ok {
log.Fatalf("invalid inflector " + inflector)
}
}
}
return val, true
} | [
"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",
")",
"\n",
"if",
"len",
"(",
"arr",
")",
"!=",
"2",
"{",
"return",
"param",
",",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"strings",
".",
"TrimSpace",
"(",
"arr",
"[",
"0",
"]",
")",
",",
"strings",
".",
"TrimSpace",
"(",
"arr",
"[",
"1",
"]",
")",
"\n",
"}",
"(",
")",
"\n\n",
"// get the value",
"val",
",",
"ok",
":=",
"func",
"(",
")",
"(",
"string",
",",
"bool",
")",
"{",
"// get from type parameters",
"val",
",",
"ok",
":=",
"dicts",
"[",
"cleanParam",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"val",
")",
",",
"true",
"\n",
"}",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}",
"\n\n",
"// inflect the value if needed",
"if",
"inflectors",
"!=",
"\"",
"\"",
"{",
"for",
"_",
",",
"inflector",
":=",
"range",
"strings",
".",
"Split",
"(",
"inflectors",
",",
"\"",
"\"",
")",
"{",
"inflector",
"=",
"strings",
".",
"TrimSpace",
"(",
"inflector",
")",
"\n",
"var",
"ok",
"bool",
"\n",
"val",
",",
"ok",
"=",
"doInflect",
"(",
"val",
",",
"inflector",
")",
"\n",
"if",
"!",
"ok",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
"+",
"inflector",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"val",
",",
"true",
"\n",
"}"
] | // 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 |
3,151 | 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",
"{",
"apiDef",
":",
"apiDef",
",",
"apiDocsDir",
":",
"apiDocsDir",
",",
"TargetDir",
":",
"targetDir",
",",
"Resources",
":",
"resources",
",",
"}",
"\n",
"}"
] | // 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 |
3,152 | 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",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"filename",
",",
"true",
")",
"\n",
"}"
] | // 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 |
3,153 | 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_resource_api", filename, true); err != nil {
return err
}
for _, method := range resource.Methods {
allMethods = append(allMethods, *method)
filename := path.Join(s.TargetDir, handlersDir, method.Handler()+".lua")
// generate method handler file
if err := commons.GenerateFile(method, "./templates/tarantool/server_method_handler.tmpl",
"server_method_handler", filename, false); err != nil {
return err
}
}
}
methods := map[string]interface{}{
"Methods": allMethods,
}
// Generate handlers file
filename := path.Join(s.TargetDir, handlersDir, "handlers.lua")
return commons.GenerateFile(methods, "./templates/tarantool/server_handlers.tmpl", "server_handlers", filename, true)
} | 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_resource_api", filename, true); err != nil {
return err
}
for _, method := range resource.Methods {
allMethods = append(allMethods, *method)
filename := path.Join(s.TargetDir, handlersDir, method.Handler()+".lua")
// generate method handler file
if err := commons.GenerateFile(method, "./templates/tarantool/server_method_handler.tmpl",
"server_method_handler", filename, false); err != nil {
return err
}
}
}
methods := map[string]interface{}{
"Methods": allMethods,
}
// Generate handlers file
filename := path.Join(s.TargetDir, handlersDir, "handlers.lua")
return commons.GenerateFile(methods, "./templates/tarantool/server_handlers.tmpl", "server_handlers", filename, true)
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"generateResources",
"(",
")",
"error",
"{",
"var",
"allMethods",
"[",
"]",
"method",
"\n\n",
"for",
"_",
",",
"resource",
":=",
"range",
"s",
".",
"Resources",
"{",
"filename",
":=",
"path",
".",
"Join",
"(",
"s",
".",
"TargetDir",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"strings",
".",
"ToLower",
"(",
"resource",
".",
"Name",
")",
")",
"+",
"\"",
"\"",
")",
"\n\n",
"if",
"err",
":=",
"commons",
".",
"GenerateFile",
"(",
"resource",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"filename",
",",
"true",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"method",
":=",
"range",
"resource",
".",
"Methods",
"{",
"allMethods",
"=",
"append",
"(",
"allMethods",
",",
"*",
"method",
")",
"\n",
"filename",
":=",
"path",
".",
"Join",
"(",
"s",
".",
"TargetDir",
",",
"handlersDir",
",",
"method",
".",
"Handler",
"(",
")",
"+",
"\"",
"\"",
")",
"\n\n",
"// generate method handler file",
"if",
"err",
":=",
"commons",
".",
"GenerateFile",
"(",
"method",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"filename",
",",
"false",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"methods",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"allMethods",
",",
"}",
"\n\n",
"// Generate handlers file",
"filename",
":=",
"path",
".",
"Join",
"(",
"s",
".",
"TargetDir",
",",
"handlersDir",
",",
"\"",
"\"",
")",
"\n",
"return",
"commons",
".",
"GenerateFile",
"(",
"methods",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"filename",
",",
"true",
")",
"\n",
"}"
] | // 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 |
3,154 | 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: items,
}
// other types that need some processing
switch {
case ramlType.IsBidimensiArray(): // bidimensional array
log.Info("validator has no support for bidimensional array, ignore it")
case ramlType.IsArray(): // array
pf.IsList = true
pf.setType(apiDef, ramlType.ArrayType(), "")
case strings.HasSuffix(t, "{}"): // map
log.Info("validator has no support for map, ignore it")
case ramlType.IsUnion():
// send the list of union types to the template
unionTypes, _ := ramlType.Union()
for _, typename := range unionTypes {
if v, ok := typeMap[typename]; ok {
switch typename {
case "datetime":
pf.addImport(apiDef, "datetime", "datetime")
case "uuid":
pf.addImport(apiDef, "uuid", "UUID")
case "string":
pf.addImport(apiDef, "six", "string_types")
default:
pf.addImport(apiDef, "."+typename, typename)
}
pf.UnionTypes = append(pf.UnionTypes, v)
}
pf.Type = t
}
case strings.Index(t, ".") > 1:
pf.Type = t[strings.Index(t, ".")+1:]
default:
pf.Type = t
pf.addImport(apiDef, "."+t, t)
}
} | 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: items,
}
// other types that need some processing
switch {
case ramlType.IsBidimensiArray(): // bidimensional array
log.Info("validator has no support for bidimensional array, ignore it")
case ramlType.IsArray(): // array
pf.IsList = true
pf.setType(apiDef, ramlType.ArrayType(), "")
case strings.HasSuffix(t, "{}"): // map
log.Info("validator has no support for map, ignore it")
case ramlType.IsUnion():
// send the list of union types to the template
unionTypes, _ := ramlType.Union()
for _, typename := range unionTypes {
if v, ok := typeMap[typename]; ok {
switch typename {
case "datetime":
pf.addImport(apiDef, "datetime", "datetime")
case "uuid":
pf.addImport(apiDef, "uuid", "UUID")
case "string":
pf.addImport(apiDef, "six", "string_types")
default:
pf.addImport(apiDef, "."+typename, typename)
}
pf.UnionTypes = append(pf.UnionTypes, v)
}
pf.Type = t
}
case strings.Index(t, ".") > 1:
pf.Type = t[strings.Index(t, ".")+1:]
default:
pf.Type = t
pf.addImport(apiDef, "."+t, t)
}
} | [
"func",
"(",
"pf",
"*",
"field",
")",
"setType",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"t",
",",
"items",
"string",
")",
"{",
"pt",
":=",
"toPythonType",
"(",
"t",
")",
"\n",
"if",
"pt",
"!=",
"nil",
"{",
"pf",
".",
"Type",
"=",
"pt",
".",
"name",
"\n",
"if",
"pt",
".",
"importName",
"!=",
"\"",
"\"",
"{",
"pf",
".",
"addImport",
"(",
"apiDef",
",",
"pt",
".",
"importModule",
",",
"pt",
".",
"importName",
")",
"\n",
"}",
"\n",
"return",
"// type already set, no need to go down",
"\n",
"}",
"\n\n",
"ramlType",
":=",
"raml",
".",
"Type",
"{",
"Type",
":",
"t",
",",
"Items",
":",
"items",
",",
"}",
"\n",
"// other types that need some processing",
"switch",
"{",
"case",
"ramlType",
".",
"IsBidimensiArray",
"(",
")",
":",
"// bidimensional array",
"log",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"case",
"ramlType",
".",
"IsArray",
"(",
")",
":",
"// array",
"pf",
".",
"IsList",
"=",
"true",
"\n",
"pf",
".",
"setType",
"(",
"apiDef",
",",
"ramlType",
".",
"ArrayType",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"case",
"strings",
".",
"HasSuffix",
"(",
"t",
",",
"\"",
"\"",
")",
":",
"// map",
"log",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"case",
"ramlType",
".",
"IsUnion",
"(",
")",
":",
"// send the list of union types to the template",
"unionTypes",
",",
"_",
":=",
"ramlType",
".",
"Union",
"(",
")",
"\n",
"for",
"_",
",",
"typename",
":=",
"range",
"unionTypes",
"{",
"if",
"v",
",",
"ok",
":=",
"typeMap",
"[",
"typename",
"]",
";",
"ok",
"{",
"switch",
"typename",
"{",
"case",
"\"",
"\"",
":",
"pf",
".",
"addImport",
"(",
"apiDef",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"case",
"\"",
"\"",
":",
"pf",
".",
"addImport",
"(",
"apiDef",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"case",
"\"",
"\"",
":",
"pf",
".",
"addImport",
"(",
"apiDef",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"default",
":",
"pf",
".",
"addImport",
"(",
"apiDef",
",",
"\"",
"\"",
"+",
"typename",
",",
"typename",
")",
"\n",
"}",
"\n",
"pf",
".",
"UnionTypes",
"=",
"append",
"(",
"pf",
".",
"UnionTypes",
",",
"v",
")",
"\n",
"}",
"\n\n",
"pf",
".",
"Type",
"=",
"t",
"\n",
"}",
"\n",
"case",
"strings",
".",
"Index",
"(",
"t",
",",
"\"",
"\"",
")",
">",
"1",
":",
"pf",
".",
"Type",
"=",
"t",
"[",
"strings",
".",
"Index",
"(",
"t",
",",
"\"",
"\"",
")",
"+",
"1",
":",
"]",
"\n",
"default",
":",
"pf",
".",
"Type",
"=",
"t",
"\n",
"pf",
".",
"addImport",
"(",
"apiDef",
",",
"\"",
"\"",
"+",
"t",
",",
"t",
")",
"\n",
"}",
"\n",
"}"
] | // 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 |
3,155 | 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")
} else if strings.ToUpper(format) == "RFC2616" {
return get("datetime_rfc2616.go")
}
}
return []byte{}, fmt.Errorf("unrecognized combination of type :%v format : %v", typ, format)
} | 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")
} else if strings.ToUpper(format) == "RFC2616" {
return get("datetime_rfc2616.go")
}
}
return []byte{}, fmt.Errorf("unrecognized combination of type :%v format : %v", typ, format)
} | [
"func",
"Get",
"(",
"typ",
",",
"format",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"switch",
"typ",
"{",
"case",
"\"",
"\"",
":",
"return",
"get",
"(",
"\"",
"\"",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"get",
"(",
"\"",
"\"",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"get",
"(",
"\"",
"\"",
")",
"\n",
"case",
"\"",
"\"",
":",
"if",
"format",
"==",
"\"",
"\"",
"||",
"strings",
".",
"ToUpper",
"(",
"format",
")",
"==",
"\"",
"\"",
"{",
"return",
"get",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"strings",
".",
"ToUpper",
"(",
"format",
")",
"==",
"\"",
"\"",
"{",
"return",
"get",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"[",
"]",
"byte",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"typ",
",",
"format",
")",
"\n",
"}"
] | // 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 |
3,156 | 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.Filename), filename
}
}
return "", ""
} | 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.Filename), filename
}
}
return "", ""
} | [
"func",
"(",
"apiDef",
"*",
"APIDefinition",
")",
"FindLibFile",
"(",
"name",
"string",
")",
"(",
"string",
",",
"string",
")",
"{",
"// search in it's document",
"if",
"filename",
",",
"ok",
":=",
"apiDef",
".",
"Uses",
"[",
"name",
"]",
";",
"ok",
"{",
"return",
"\"",
"\"",
",",
"filename",
"\n",
"}",
"\n\n",
"// search in included libraries",
"for",
"_",
",",
"lib",
":=",
"range",
"apiDef",
".",
"Libraries",
"{",
"if",
"filename",
",",
"ok",
":=",
"lib",
".",
"Uses",
"[",
"name",
"]",
";",
"ok",
"{",
"return",
"filepath",
".",
"Dir",
"(",
"lib",
".",
"Filename",
")",
",",
"filename",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"\"",
"\"",
"\n",
"}"
] | // 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 |
3,157 | 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 = apiDef.SecuritySchemes[name]
case 2:
var l *Library
l, ok = apiDef.Libraries[splitted[0]]
if !ok {
return ss, false
}
ss, ok = l.SecuritySchemes[splitted[1]]
}
return ss, ok
} | 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 = apiDef.SecuritySchemes[name]
case 2:
var l *Library
l, ok = apiDef.Libraries[splitted[0]]
if !ok {
return ss, false
}
ss, ok = l.SecuritySchemes[splitted[1]]
}
return ss, ok
} | [
"func",
"(",
"apiDef",
"*",
"APIDefinition",
")",
"GetSecurityScheme",
"(",
"name",
"string",
")",
"(",
"SecurityScheme",
",",
"bool",
")",
"{",
"var",
"ss",
"SecurityScheme",
"\n",
"var",
"ok",
"bool",
"\n\n",
"// split library name by '.'",
"// if there is '.', it means we need to look from the library",
"splitted",
":=",
"strings",
".",
"Split",
"(",
"strings",
".",
"TrimSpace",
"(",
"name",
")",
",",
"\"",
"\"",
")",
"\n\n",
"switch",
"len",
"(",
"splitted",
")",
"{",
"case",
"1",
":",
"ss",
",",
"ok",
"=",
"apiDef",
".",
"SecuritySchemes",
"[",
"name",
"]",
"\n",
"case",
"2",
":",
"var",
"l",
"*",
"Library",
"\n",
"l",
",",
"ok",
"=",
"apiDef",
".",
"Libraries",
"[",
"splitted",
"[",
"0",
"]",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"ss",
",",
"false",
"\n",
"}",
"\n",
"ss",
",",
"ok",
"=",
"l",
".",
"SecuritySchemes",
"[",
"splitted",
"[",
"1",
"]",
"]",
"\n",
"}",
"\n",
"return",
"ss",
",",
"ok",
"\n",
"}"
] | // 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 |
3,158 | 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]interface{})
for k, p := range inputProps {
name, ok := k.(string)
if !ok {
panic(fmt.Errorf("property key:%v need to be a string", k))
}
props[name] = p
}
t := Type{
Name: name,
Type: tip,
Properties: props,
}
apiDef.Types[name] = t
created = true
return created
} | 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]interface{})
for k, p := range inputProps {
name, ok := k.(string)
if !ok {
panic(fmt.Errorf("property key:%v need to be a string", k))
}
props[name] = p
}
t := Type{
Name: name,
Type: tip,
Properties: props,
}
apiDef.Types[name] = t
created = true
return created
} | [
"func",
"(",
"apiDef",
"*",
"APIDefinition",
")",
"createType",
"(",
"name",
"string",
",",
"tip",
"interface",
"{",
"}",
",",
"inputProps",
"map",
"[",
"interface",
"{",
"}",
"]",
"interface",
"{",
"}",
")",
"bool",
"{",
"created",
":=",
"false",
"\n",
"// check that there is no type with this name",
"if",
"_",
",",
"exist",
":=",
"apiDef",
".",
"Types",
"[",
"name",
"]",
";",
"exist",
"{",
"return",
"created",
"\n",
"}",
"\n\n",
"// convert the inputProps to properties",
"props",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n\n",
"for",
"k",
",",
"p",
":=",
"range",
"inputProps",
"{",
"name",
",",
"ok",
":=",
"k",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"k",
")",
")",
"\n",
"}",
"\n",
"props",
"[",
"name",
"]",
"=",
"p",
"\n",
"}",
"\n\n",
"t",
":=",
"Type",
"{",
"Name",
":",
"name",
",",
"Type",
":",
"tip",
",",
"Properties",
":",
"props",
",",
"}",
"\n",
"apiDef",
".",
"Types",
"[",
"name",
"]",
"=",
"t",
"\n",
"created",
"=",
"true",
"\n",
"return",
"created",
"\n",
"}"
] | // create new type | [
"create",
"new",
"type"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/raml/apidefinition.go#L232-L260 |
3,159 | 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",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // 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 |
3,160 | 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",
".",
"GenerateFile",
"(",
"gs",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fileName",
",",
"true",
")",
"\n",
"}"
] | // 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 |
3,161 | 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: make(map[string]struct{}),
}
if pc.T.IsAlias() {
return pc
}
// initialize the fields
types := globAPIDef.Types
typeHierarchy := getTypeHierarchy(name, T, types)
ramlTypes := make([]raml.Type, 0)
for _, v := range typeHierarchy {
for _, iv := range v {
ramlTypes = append(ramlTypes, iv)
}
}
mergedProps := getTypeProperties(ramlTypes)
for k, v := range properties {
prop := raml.ToProperty(k, v)
mergedProps[k] = prop
}
for propName, propInterface := range mergedProps {
op := objectProperties(propName, propInterface)
field, err := newField(name, apiDef, T, propName, propInterface, types, op, typeHierarchy)
if err != nil {
continue
}
pc.Fields[field.Name] = field
}
return pc
} | 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: make(map[string]struct{}),
}
if pc.T.IsAlias() {
return pc
}
// initialize the fields
types := globAPIDef.Types
typeHierarchy := getTypeHierarchy(name, T, types)
ramlTypes := make([]raml.Type, 0)
for _, v := range typeHierarchy {
for _, iv := range v {
ramlTypes = append(ramlTypes, iv)
}
}
mergedProps := getTypeProperties(ramlTypes)
for k, v := range properties {
prop := raml.ToProperty(k, v)
mergedProps[k] = prop
}
for propName, propInterface := range mergedProps {
op := objectProperties(propName, propInterface)
field, err := newField(name, apiDef, T, propName, propInterface, types, op, typeHierarchy)
if err != nil {
continue
}
pc.Fields[field.Name] = field
}
return pc
} | [
"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",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
")",
",",
"}",
"\n\n",
"if",
"pc",
".",
"T",
".",
"IsAlias",
"(",
")",
"{",
"return",
"pc",
"\n",
"}",
"\n\n",
"// initialize the fields",
"types",
":=",
"globAPIDef",
".",
"Types",
"\n\n",
"typeHierarchy",
":=",
"getTypeHierarchy",
"(",
"name",
",",
"T",
",",
"types",
")",
"\n",
"ramlTypes",
":=",
"make",
"(",
"[",
"]",
"raml",
".",
"Type",
",",
"0",
")",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"typeHierarchy",
"{",
"for",
"_",
",",
"iv",
":=",
"range",
"v",
"{",
"ramlTypes",
"=",
"append",
"(",
"ramlTypes",
",",
"iv",
")",
"\n",
"}",
"\n",
"}",
"\n",
"mergedProps",
":=",
"getTypeProperties",
"(",
"ramlTypes",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"properties",
"{",
"prop",
":=",
"raml",
".",
"ToProperty",
"(",
"k",
",",
"v",
")",
"\n",
"mergedProps",
"[",
"k",
"]",
"=",
"prop",
"\n",
"}",
"\n\n",
"for",
"propName",
",",
"propInterface",
":=",
"range",
"mergedProps",
"{",
"op",
":=",
"objectProperties",
"(",
"propName",
",",
"propInterface",
")",
"\n",
"field",
",",
"err",
":=",
"newField",
"(",
"name",
",",
"apiDef",
",",
"T",
",",
"propName",
",",
"propInterface",
",",
"types",
",",
"op",
",",
"typeHierarchy",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"continue",
"\n",
"}",
"\n\n",
"pc",
".",
"Fields",
"[",
"field",
".",
"Name",
"]",
"=",
"field",
"\n",
"}",
"\n\n",
"return",
"pc",
"\n",
"}"
] | // 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 |
3,162 | 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",
",",
"propInterface",
":=",
"range",
"Properties",
"{",
"props",
"=",
"append",
"(",
"props",
",",
"raml",
".",
"ToProperty",
"(",
"propName",
",",
"propInterface",
")",
")",
"\n",
"}",
"\n\n",
"return",
"props",
"\n",
"}"
] | // 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 |
3,163 | 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([]string, 0)
for _, f := range pc.Fields {
if f.Enum != nil {
typeNames = append(typeNames, f.Enum.Name)
if err := f.Enum.generate(dir); err != nil {
return typeNames, err
}
}
}
if pc.Enum != nil {
typeNames = append(typeNames, pc.Enum.Name)
return typeNames, pc.Enum.generate(dir)
}
typeNames = append(typeNames, pc.Name())
return typeNames, commons.GenerateFile(pc, template, name, fileName, true)
} | 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([]string, 0)
for _, f := range pc.Fields {
if f.Enum != nil {
typeNames = append(typeNames, f.Enum.Name)
if err := f.Enum.generate(dir); err != nil {
return typeNames, err
}
}
}
if pc.Enum != nil {
typeNames = append(typeNames, pc.Enum.Name)
return typeNames, pc.Enum.generate(dir)
}
typeNames = append(typeNames, pc.Name())
return typeNames, commons.GenerateFile(pc, template, name, fileName, true)
} | [
"func",
"(",
"pc",
"*",
"class",
")",
"generate",
"(",
"dir",
",",
"template",
",",
"name",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"fileName",
":=",
"filepath",
".",
"Join",
"(",
"dir",
",",
"pc",
".",
"Name",
"(",
")",
"+",
"\"",
"\"",
")",
"\n\n",
"if",
"pc",
".",
"AliasOf",
"!=",
"\"",
"\"",
"{",
"return",
"[",
"]",
"string",
"{",
"pc",
".",
"Name",
"(",
")",
"}",
",",
"commons",
".",
"GenerateFile",
"(",
"pc",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fileName",
",",
"true",
")",
"\n",
"}",
"\n\n",
"// generate enums",
"typeNames",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"pc",
".",
"Fields",
"{",
"if",
"f",
".",
"Enum",
"!=",
"nil",
"{",
"typeNames",
"=",
"append",
"(",
"typeNames",
",",
"f",
".",
"Enum",
".",
"Name",
")",
"\n",
"if",
"err",
":=",
"f",
".",
"Enum",
".",
"generate",
"(",
"dir",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"typeNames",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"pc",
".",
"Enum",
"!=",
"nil",
"{",
"typeNames",
"=",
"append",
"(",
"typeNames",
",",
"pc",
".",
"Enum",
".",
"Name",
")",
"\n",
"return",
"typeNames",
",",
"pc",
".",
"Enum",
".",
"generate",
"(",
"dir",
")",
"\n",
"}",
"\n\n",
"typeNames",
"=",
"append",
"(",
"typeNames",
",",
"pc",
".",
"Name",
"(",
")",
")",
"\n",
"return",
"typeNames",
",",
"commons",
".",
"GenerateFile",
"(",
"pc",
",",
"template",
",",
"name",
",",
"fileName",
",",
"true",
")",
"\n",
"}"
] | // 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 |
3,164 | 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",
"if",
"imp",
".",
"Name",
"==",
"pc",
".",
"Name",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n",
"pc",
".",
"addImport",
"(",
"imp",
".",
"Module",
",",
"imp",
".",
"Name",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"commons",
".",
"MapToSortedStrings",
"(",
"pc",
".",
"imports",
")",
"\n",
"}"
] | // 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 |
3,165 | 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_python.tmpl"
templateName := "class_python"
names := []string{}
for name, t := range types.AllTypes(apiDef, "") {
var errGen error
var results []string
switch tip := t.Type.(type) {
case string:
rt := raml.Type{
Type: tip,
}
if rt.IsMultipleInheritance() {
delayedMI = append(delayedMI, tip)
}
case types.TypeInBody:
newTipName := types.PascalCaseTypeName(tip)
pc := newClass(apiDef, raml.Type{Type: "object"}, newTipName, "", tip.Properties, capnp)
results, errGen = pc.generate(dir, template, templateName)
case raml.Type:
if name == "UUID" {
continue
}
pc := newClassFromType(apiDef, tip, name, capnp)
results, errGen = pc.generate(dir, template, templateName)
}
if errGen != nil {
return names, errGen
}
names = append(names, results...)
}
for _, tip := range delayedMI {
rt := raml.Type{
Type: tip,
}
if parents, isMult := rt.MultipleInheritance(); isMult {
pc := newClassFromType(apiDef, rt, strings.Join(parents, ""), capnp)
results, err := pc.generate(dir, template, templateName)
if err != nil {
return names, err
}
names = append(names, results...)
}
}
return names, nil
} | 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_python.tmpl"
templateName := "class_python"
names := []string{}
for name, t := range types.AllTypes(apiDef, "") {
var errGen error
var results []string
switch tip := t.Type.(type) {
case string:
rt := raml.Type{
Type: tip,
}
if rt.IsMultipleInheritance() {
delayedMI = append(delayedMI, tip)
}
case types.TypeInBody:
newTipName := types.PascalCaseTypeName(tip)
pc := newClass(apiDef, raml.Type{Type: "object"}, newTipName, "", tip.Properties, capnp)
results, errGen = pc.generate(dir, template, templateName)
case raml.Type:
if name == "UUID" {
continue
}
pc := newClassFromType(apiDef, tip, name, capnp)
results, errGen = pc.generate(dir, template, templateName)
}
if errGen != nil {
return names, errGen
}
names = append(names, results...)
}
for _, tip := range delayedMI {
rt := raml.Type{
Type: tip,
}
if parents, isMult := rt.MultipleInheritance(); isMult {
pc := newClassFromType(apiDef, rt, strings.Join(parents, ""), capnp)
results, err := pc.generate(dir, template, templateName)
if err != nil {
return names, err
}
names = append(names, results...)
}
}
return names, nil
} | [
"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",
"\n",
"template",
":=",
"\"",
"\"",
"\n",
"templateName",
":=",
"\"",
"\"",
"\n\n",
"names",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"name",
",",
"t",
":=",
"range",
"types",
".",
"AllTypes",
"(",
"apiDef",
",",
"\"",
"\"",
")",
"{",
"var",
"errGen",
"error",
"\n",
"var",
"results",
"[",
"]",
"string",
"\n",
"switch",
"tip",
":=",
"t",
".",
"Type",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"rt",
":=",
"raml",
".",
"Type",
"{",
"Type",
":",
"tip",
",",
"}",
"\n",
"if",
"rt",
".",
"IsMultipleInheritance",
"(",
")",
"{",
"delayedMI",
"=",
"append",
"(",
"delayedMI",
",",
"tip",
")",
"\n",
"}",
"\n",
"case",
"types",
".",
"TypeInBody",
":",
"newTipName",
":=",
"types",
".",
"PascalCaseTypeName",
"(",
"tip",
")",
"\n",
"pc",
":=",
"newClass",
"(",
"apiDef",
",",
"raml",
".",
"Type",
"{",
"Type",
":",
"\"",
"\"",
"}",
",",
"newTipName",
",",
"\"",
"\"",
",",
"tip",
".",
"Properties",
",",
"capnp",
")",
"\n",
"results",
",",
"errGen",
"=",
"pc",
".",
"generate",
"(",
"dir",
",",
"template",
",",
"templateName",
")",
"\n",
"case",
"raml",
".",
"Type",
":",
"if",
"name",
"==",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"\n",
"pc",
":=",
"newClassFromType",
"(",
"apiDef",
",",
"tip",
",",
"name",
",",
"capnp",
")",
"\n",
"results",
",",
"errGen",
"=",
"pc",
".",
"generate",
"(",
"dir",
",",
"template",
",",
"templateName",
")",
"\n",
"}",
"\n\n",
"if",
"errGen",
"!=",
"nil",
"{",
"return",
"names",
",",
"errGen",
"\n",
"}",
"\n",
"names",
"=",
"append",
"(",
"names",
",",
"results",
"...",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"tip",
":=",
"range",
"delayedMI",
"{",
"rt",
":=",
"raml",
".",
"Type",
"{",
"Type",
":",
"tip",
",",
"}",
"\n",
"if",
"parents",
",",
"isMult",
":=",
"rt",
".",
"MultipleInheritance",
"(",
")",
";",
"isMult",
"{",
"pc",
":=",
"newClassFromType",
"(",
"apiDef",
",",
"rt",
",",
"strings",
".",
"Join",
"(",
"parents",
",",
"\"",
"\"",
")",
",",
"capnp",
")",
"\n",
"results",
",",
"err",
":=",
"pc",
".",
"generate",
"(",
"dir",
",",
"template",
",",
"templateName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"names",
",",
"err",
"\n",
"}",
"\n",
"names",
"=",
"append",
"(",
"names",
",",
"results",
"...",
")",
"\n",
"}",
"\n\n",
"}",
"\n",
"return",
"names",
",",
"nil",
"\n\n",
"}"
] | // 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 |
3,166 | 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
if _, ok := apiDef.Types[basicType]; ok {
titledType := strings.Title(basicType)
// check if it is a recursive type
if titledType == strings.Title(structName) {
titledType = "*" + titledType // add `pointer`, otherwise compiler will complain
}
// use strings.Replace instead of simple assignment because the fieldType
// might be an array
fieldType = strings.Replace(fieldType, basicType, titledType, 1)
}
fieldType = convertToGoType(fieldType, prop.Items.Type)
fd := fieldDef{
Name: formatFieldName(prop.Name),
fieldType: fieldType,
IsOmitted: !prop.Required,
}
fd.buildValidators(prop)
if prop.IsEnum() {
fd.Enum = newEnum(structName, prop, pkg, false)
fd.fieldType = fd.Enum.Name
}
return fd
} | 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
if _, ok := apiDef.Types[basicType]; ok {
titledType := strings.Title(basicType)
// check if it is a recursive type
if titledType == strings.Title(structName) {
titledType = "*" + titledType // add `pointer`, otherwise compiler will complain
}
// use strings.Replace instead of simple assignment because the fieldType
// might be an array
fieldType = strings.Replace(fieldType, basicType, titledType, 1)
}
fieldType = convertToGoType(fieldType, prop.Items.Type)
fd := fieldDef{
Name: formatFieldName(prop.Name),
fieldType: fieldType,
IsOmitted: !prop.Required,
}
fd.buildValidators(prop)
if prop.IsEnum() {
fd.Enum = newEnum(structName, prop, pkg, false)
fd.fieldType = fd.Enum.Name
}
return fd
} | [
"func",
"newFieldDef",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"structName",
"string",
",",
"prop",
"raml",
".",
"Property",
",",
"pkg",
"string",
")",
"fieldDef",
"{",
"var",
"(",
"fieldType",
"=",
"prop",
".",
"TypeString",
"(",
")",
"// the field type",
"\n",
"basicType",
"=",
"commons",
".",
"GetBasicType",
"(",
"fieldType",
")",
"// basic type of the field type",
"\n",
")",
"\n\n",
"// for the types, check first if it is user defined type",
"if",
"_",
",",
"ok",
":=",
"apiDef",
".",
"Types",
"[",
"basicType",
"]",
";",
"ok",
"{",
"titledType",
":=",
"strings",
".",
"Title",
"(",
"basicType",
")",
"\n\n",
"// check if it is a recursive type",
"if",
"titledType",
"==",
"strings",
".",
"Title",
"(",
"structName",
")",
"{",
"titledType",
"=",
"\"",
"\"",
"+",
"titledType",
"// add `pointer`, otherwise compiler will complain",
"\n",
"}",
"\n\n",
"// use strings.Replace instead of simple assignment because the fieldType",
"// might be an array",
"fieldType",
"=",
"strings",
".",
"Replace",
"(",
"fieldType",
",",
"basicType",
",",
"titledType",
",",
"1",
")",
"\n",
"}",
"\n",
"fieldType",
"=",
"convertToGoType",
"(",
"fieldType",
",",
"prop",
".",
"Items",
".",
"Type",
")",
"\n\n",
"fd",
":=",
"fieldDef",
"{",
"Name",
":",
"formatFieldName",
"(",
"prop",
".",
"Name",
")",
",",
"fieldType",
":",
"fieldType",
",",
"IsOmitted",
":",
"!",
"prop",
".",
"Required",
",",
"}",
"\n\n",
"fd",
".",
"buildValidators",
"(",
"prop",
")",
"\n\n",
"if",
"prop",
".",
"IsEnum",
"(",
")",
"{",
"fd",
".",
"Enum",
"=",
"newEnum",
"(",
"structName",
",",
"prop",
",",
"pkg",
",",
"false",
")",
"\n",
"fd",
".",
"fieldType",
"=",
"fd",
".",
"Enum",
".",
"Name",
"\n",
"}",
"\n\n",
"return",
"fd",
"\n",
"}"
] | // 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 |
3,167 | 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",
"(",
"v",
")",
"\n",
"}",
"\n",
"return",
"formatted",
"\n",
"}"
] | // 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 |
3,168 | 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.ToPascalCase(sm.MethodName + commons.ReqBodySuffix)
}
sm.Params = strings.Join(resourceParams, ", ")
sm.Endpoint = strings.Replace(sm.Endpoint, "{", "<", -1)
sm.Endpoint = strings.Replace(sm.Endpoint, "}", ">", -1)
// security middlewares
for _, v := range sm.SecuredBy {
if !security.ValidateScheme(v.Name, apiDef) {
continue
}
// oauth2 middleware
m, err := newPythonOauth2Middleware(v)
if err != nil {
log.Errorf("error creating middleware for method.err = %v", err)
return err
}
sm.MiddlewaresArr = append(sm.MiddlewaresArr, m)
}
return nil
} | 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.ToPascalCase(sm.MethodName + commons.ReqBodySuffix)
}
sm.Params = strings.Join(resourceParams, ", ")
sm.Endpoint = strings.Replace(sm.Endpoint, "{", "<", -1)
sm.Endpoint = strings.Replace(sm.Endpoint, "}", ">", -1)
// security middlewares
for _, v := range sm.SecuredBy {
if !security.ValidateScheme(v.Name, apiDef) {
continue
}
// oauth2 middleware
m, err := newPythonOauth2Middleware(v)
if err != nil {
log.Errorf("error creating middleware for method.err = %v", err)
return err
}
sm.MiddlewaresArr = append(sm.MiddlewaresArr, m)
}
return nil
} | [
"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",
")",
"\n\n",
"if",
"commons",
".",
"HasJSONBody",
"(",
"&",
"(",
"sm",
".",
"Bodies",
")",
")",
"{",
"// TODO : make it to call proper func",
"sm",
".",
"reqBody",
"=",
"casee",
".",
"ToPascalCase",
"(",
"sm",
".",
"MethodName",
"+",
"commons",
".",
"ReqBodySuffix",
")",
"\n",
"}",
"\n\n",
"sm",
".",
"Params",
"=",
"strings",
".",
"Join",
"(",
"resourceParams",
",",
"\"",
"\"",
")",
"\n",
"sm",
".",
"Endpoint",
"=",
"strings",
".",
"Replace",
"(",
"sm",
".",
"Endpoint",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n",
"sm",
".",
"Endpoint",
"=",
"strings",
".",
"Replace",
"(",
"sm",
".",
"Endpoint",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n\n",
"// security middlewares",
"for",
"_",
",",
"v",
":=",
"range",
"sm",
".",
"SecuredBy",
"{",
"if",
"!",
"security",
".",
"ValidateScheme",
"(",
"v",
".",
"Name",
",",
"apiDef",
")",
"{",
"continue",
"\n",
"}",
"\n",
"// oauth2 middleware",
"m",
",",
"err",
":=",
"newPythonOauth2Middleware",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"sm",
".",
"MiddlewaresArr",
"=",
"append",
"(",
"sm",
".",
"MiddlewaresArr",
",",
"m",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // 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 |
3,169 | 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 getServerResourcesDefs(apiDef) {
pr := newResource(rd, apiDef, serverKindFlask)
prs = append(prs, pr)
}
templates := templates(serverKindFlask)
return &FlaskServer{
APIDef: apiDef,
Title: apiDef.Title,
apiDocsDir: apiDocsDir,
WithMain: withMain,
ResourcesDef: prs,
Gevent: gevent,
Template: templates,
targetDir: targetDir,
}
} | 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 getServerResourcesDefs(apiDef) {
pr := newResource(rd, apiDef, serverKindFlask)
prs = append(prs, pr)
}
templates := templates(serverKindFlask)
return &FlaskServer{
APIDef: apiDef,
Title: apiDef.Title,
apiDocsDir: apiDocsDir,
WithMain: withMain,
ResourcesDef: prs,
Gevent: gevent,
Template: templates,
targetDir: targetDir,
}
} | [
"func",
"NewFlaskServer",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"apiDocsDir",
",",
"targetDir",
"string",
",",
"withMain",
"bool",
",",
"libRootURLs",
"[",
"]",
"string",
",",
"gevent",
"bool",
")",
"*",
"FlaskServer",
"{",
"// TODO : get rid of this global variables",
"globAPIDef",
"=",
"apiDef",
"\n",
"globLibRootURLs",
"=",
"libRootURLs",
"\n\n",
"// generates resource",
"var",
"prs",
"[",
"]",
"pythonResource",
"\n",
"for",
"_",
",",
"rd",
":=",
"range",
"getServerResourcesDefs",
"(",
"apiDef",
")",
"{",
"pr",
":=",
"newResource",
"(",
"rd",
",",
"apiDef",
",",
"serverKindFlask",
")",
"\n",
"prs",
"=",
"append",
"(",
"prs",
",",
"pr",
")",
"\n",
"}",
"\n\n",
"templates",
":=",
"templates",
"(",
"serverKindFlask",
")",
"\n\n",
"return",
"&",
"FlaskServer",
"{",
"APIDef",
":",
"apiDef",
",",
"Title",
":",
"apiDef",
".",
"Title",
",",
"apiDocsDir",
":",
"apiDocsDir",
",",
"WithMain",
":",
"withMain",
",",
"ResourcesDef",
":",
"prs",
",",
"Gevent",
":",
"gevent",
",",
"Template",
":",
"templates",
",",
"targetDir",
":",
"targetDir",
",",
"}",
"\n",
"}"
] | // 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 |
3,170 | 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",
",",
"dicts",
")",
"\n",
"dicts",
"[",
"\"",
"\"",
"]",
"=",
"strings",
".",
"ToLower",
"(",
"m",
".",
"Name",
")",
"\n",
"return",
"dicts",
"\n",
"}"
] | // 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 |
3,171 | 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 = libsRootURLs
return &Server{
apiDef: apiDef,
PackageName: packageName,
apiDocsDir: apiDocsDir,
withMain: withMain,
RootImportPath: rootImportPath,
TargetDir: targetDir,
libsRootURLs: libsRootURLs,
}
} | 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 = libsRootURLs
return &Server{
apiDef: apiDef,
PackageName: packageName,
apiDocsDir: apiDocsDir,
withMain: withMain,
RootImportPath: rootImportPath,
TargetDir: targetDir,
libsRootURLs: libsRootURLs,
}
} | [
"func",
"NewServer",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"packageName",
",",
"apiDocsDir",
",",
"rootImportPath",
"string",
",",
"withMain",
"bool",
",",
"targetDir",
"string",
",",
"libsRootURLs",
"[",
"]",
"string",
")",
"*",
"Server",
"{",
"// global variables",
"rootImportPath",
"=",
"setRootImportPath",
"(",
"rootImportPath",
",",
"targetDir",
")",
"\n",
"globAPIDef",
"=",
"apiDef",
"\n",
"globRootImportPath",
"=",
"rootImportPath",
"\n",
"globLibRootURLs",
"=",
"libsRootURLs",
"\n\n",
"return",
"&",
"Server",
"{",
"apiDef",
":",
"apiDef",
",",
"PackageName",
":",
"packageName",
",",
"apiDocsDir",
":",
"apiDocsDir",
",",
"withMain",
":",
"withMain",
",",
"RootImportPath",
":",
"rootImportPath",
",",
"TargetDir",
":",
"targetDir",
",",
"libsRootURLs",
":",
"libsRootURLs",
",",
"}",
"\n",
"}"
] | // 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 |
3,172 | 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: gs.RootImportPath,
packageName: "goraml",
packageDir: "goraml",
}
if err := gh.generate(gs.TargetDir); err != nil {
return err
}
if err := generateAllStructs(gs.apiDef, gs.TargetDir); err != nil {
return err
}
// security scheme
if err := generateSecurity(gs.apiDef.SecuritySchemes, gs.TargetDir, gs.PackageName); err != nil {
log.Errorf("failed to generate security scheme:%v", err)
return err
}
// genereate resources
rds, err := gs.generateServerResources(gs.TargetDir)
if err != nil {
return err
}
gs.ResourcesDef = rds
// libraries
if err := generateLibraries(gs.apiDef.Libraries, gs.TargetDir, gs.libsRootURLs); err != nil {
return err
}
// routes
if err := commons.GenerateFile(gs, "./templates/golang/server_routes.tmpl", "server_routes", filepath.Join(gs.TargetDir, "routes.go"), true); err != nil {
return err
}
// generate main
if gs.withMain {
// HTML front page
if err := commons.GenerateFile(gs, "./templates/index.html.tmpl", "index.html", filepath.Join(gs.TargetDir, "index.html"), false); err != nil {
return err
}
// main file
return commons.GenerateFile(gs, "./templates/golang/server_main_go.tmpl", "server_main_go", filepath.Join(gs.TargetDir, "main.go"), true)
}
return nil
} | 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: gs.RootImportPath,
packageName: "goraml",
packageDir: "goraml",
}
if err := gh.generate(gs.TargetDir); err != nil {
return err
}
if err := generateAllStructs(gs.apiDef, gs.TargetDir); err != nil {
return err
}
// security scheme
if err := generateSecurity(gs.apiDef.SecuritySchemes, gs.TargetDir, gs.PackageName); err != nil {
log.Errorf("failed to generate security scheme:%v", err)
return err
}
// genereate resources
rds, err := gs.generateServerResources(gs.TargetDir)
if err != nil {
return err
}
gs.ResourcesDef = rds
// libraries
if err := generateLibraries(gs.apiDef.Libraries, gs.TargetDir, gs.libsRootURLs); err != nil {
return err
}
// routes
if err := commons.GenerateFile(gs, "./templates/golang/server_routes.tmpl", "server_routes", filepath.Join(gs.TargetDir, "routes.go"), true); err != nil {
return err
}
// generate main
if gs.withMain {
// HTML front page
if err := commons.GenerateFile(gs, "./templates/index.html.tmpl", "index.html", filepath.Join(gs.TargetDir, "index.html"), false); err != nil {
return err
}
// main file
return commons.GenerateFile(gs, "./templates/golang/server_main_go.tmpl", "server_main_go", filepath.Join(gs.TargetDir, "main.go"), true)
}
return nil
} | [
"func",
"(",
"gs",
"*",
"Server",
")",
"Generate",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"commons",
".",
"CheckDuplicatedTitleTypes",
"(",
"gs",
".",
"apiDef",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"gs",
".",
"RootImportPath",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// helper package",
"gh",
":=",
"goramlHelper",
"{",
"rootImportPath",
":",
"gs",
".",
"RootImportPath",
",",
"packageName",
":",
"\"",
"\"",
",",
"packageDir",
":",
"\"",
"\"",
",",
"}",
"\n",
"if",
"err",
":=",
"gh",
".",
"generate",
"(",
"gs",
".",
"TargetDir",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"generateAllStructs",
"(",
"gs",
".",
"apiDef",
",",
"gs",
".",
"TargetDir",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// security scheme",
"if",
"err",
":=",
"generateSecurity",
"(",
"gs",
".",
"apiDef",
".",
"SecuritySchemes",
",",
"gs",
".",
"TargetDir",
",",
"gs",
".",
"PackageName",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// genereate resources",
"rds",
",",
"err",
":=",
"gs",
".",
"generateServerResources",
"(",
"gs",
".",
"TargetDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"gs",
".",
"ResourcesDef",
"=",
"rds",
"\n\n",
"// libraries",
"if",
"err",
":=",
"generateLibraries",
"(",
"gs",
".",
"apiDef",
".",
"Libraries",
",",
"gs",
".",
"TargetDir",
",",
"gs",
".",
"libsRootURLs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// routes",
"if",
"err",
":=",
"commons",
".",
"GenerateFile",
"(",
"gs",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"filepath",
".",
"Join",
"(",
"gs",
".",
"TargetDir",
",",
"\"",
"\"",
")",
",",
"true",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// generate main",
"if",
"gs",
".",
"withMain",
"{",
"// HTML front page",
"if",
"err",
":=",
"commons",
".",
"GenerateFile",
"(",
"gs",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"filepath",
".",
"Join",
"(",
"gs",
".",
"TargetDir",
",",
"\"",
"\"",
")",
",",
"false",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// main file",
"return",
"commons",
".",
"GenerateFile",
"(",
"gs",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"filepath",
".",
"Join",
"(",
"gs",
".",
"TargetDir",
",",
"\"",
"\"",
")",
",",
"true",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // 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 |
3,173 | 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 libraries")
}
// TODO : get rid of this global variable
rootImportPath = setRootImportPath(rootImportPath, targetDir)
globRootImportPath = rootImportPath
globAPIDef = apiDef
globLibRootURLs = libsRootURLs
// creates client services objects
services := map[string]*ClientService{}
for endpoint, res := range apiDef.Resources {
rd := resource.New(apiDef, &res, commons.NormalizeURITitle(endpoint), true)
services[endpoint] = newClientService(endpoint, packageName, &rd)
}
// creates client object
client := Client{
apiDef: apiDef,
Name: commons.NormalizeIdentifier(commons.NormalizeURI(apiDef.Title)),
BaseURI: apiDef.BaseURI,
libraries: apiDef.Libraries,
PackageName: packageName,
RootImportPath: rootImportPath,
Services: services,
TargetDir: targetDir,
libsRootURLs: libsRootURLs,
}
if strings.Index(client.BaseURI, "{version}") > 0 {
client.BaseURI = strings.Replace(client.BaseURI, "{version}", apiDef.Version, -1)
}
return client, nil
} | 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 libraries")
}
// TODO : get rid of this global variable
rootImportPath = setRootImportPath(rootImportPath, targetDir)
globRootImportPath = rootImportPath
globAPIDef = apiDef
globLibRootURLs = libsRootURLs
// creates client services objects
services := map[string]*ClientService{}
for endpoint, res := range apiDef.Resources {
rd := resource.New(apiDef, &res, commons.NormalizeURITitle(endpoint), true)
services[endpoint] = newClientService(endpoint, packageName, &rd)
}
// creates client object
client := Client{
apiDef: apiDef,
Name: commons.NormalizeIdentifier(commons.NormalizeURI(apiDef.Title)),
BaseURI: apiDef.BaseURI,
libraries: apiDef.Libraries,
PackageName: packageName,
RootImportPath: rootImportPath,
Services: services,
TargetDir: targetDir,
libsRootURLs: libsRootURLs,
}
if strings.Index(client.BaseURI, "{version}") > 0 {
client.BaseURI = strings.Replace(client.BaseURI, "{version}", apiDef.Version, -1)
}
return client, nil
} | [
"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",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// TODO : get rid of this global variable",
"rootImportPath",
"=",
"setRootImportPath",
"(",
"rootImportPath",
",",
"targetDir",
")",
"\n",
"globRootImportPath",
"=",
"rootImportPath",
"\n",
"globAPIDef",
"=",
"apiDef",
"\n",
"globLibRootURLs",
"=",
"libsRootURLs",
"\n\n",
"// creates client services objects",
"services",
":=",
"map",
"[",
"string",
"]",
"*",
"ClientService",
"{",
"}",
"\n",
"for",
"endpoint",
",",
"res",
":=",
"range",
"apiDef",
".",
"Resources",
"{",
"rd",
":=",
"resource",
".",
"New",
"(",
"apiDef",
",",
"&",
"res",
",",
"commons",
".",
"NormalizeURITitle",
"(",
"endpoint",
")",
",",
"true",
")",
"\n",
"services",
"[",
"endpoint",
"]",
"=",
"newClientService",
"(",
"endpoint",
",",
"packageName",
",",
"&",
"rd",
")",
"\n",
"}",
"\n\n",
"// creates client object",
"client",
":=",
"Client",
"{",
"apiDef",
":",
"apiDef",
",",
"Name",
":",
"commons",
".",
"NormalizeIdentifier",
"(",
"commons",
".",
"NormalizeURI",
"(",
"apiDef",
".",
"Title",
")",
")",
",",
"BaseURI",
":",
"apiDef",
".",
"BaseURI",
",",
"libraries",
":",
"apiDef",
".",
"Libraries",
",",
"PackageName",
":",
"packageName",
",",
"RootImportPath",
":",
"rootImportPath",
",",
"Services",
":",
"services",
",",
"TargetDir",
":",
"targetDir",
",",
"libsRootURLs",
":",
"libsRootURLs",
",",
"}",
"\n\n",
"if",
"strings",
".",
"Index",
"(",
"client",
".",
"BaseURI",
",",
"\"",
"\"",
")",
">",
"0",
"{",
"client",
".",
"BaseURI",
"=",
"strings",
".",
"Replace",
"(",
"client",
".",
"BaseURI",
",",
"\"",
"\"",
",",
"apiDef",
".",
"Version",
",",
"-",
"1",
")",
"\n",
"}",
"\n",
"return",
"client",
",",
"nil",
"\n",
"}"
] | // 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 |
3,174 | 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 := generateAllStructs(gc.apiDef, gc.TargetDir); err != nil {
return err
}
// libraries
if err := generateLibraries(gc.libraries, gc.TargetDir, gc.libsRootURLs); err != nil {
return err
}
if err := gc.generateHelperFile(gc.TargetDir); err != nil {
return err
}
if err := gc.generateSecurity(gc.TargetDir); err != nil {
return err
}
if err := gc.generateServices(gc.TargetDir); err != nil {
return err
}
return gc.generateClientFile(gc.TargetDir)
} | 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 := generateAllStructs(gc.apiDef, gc.TargetDir); err != nil {
return err
}
// libraries
if err := generateLibraries(gc.libraries, gc.TargetDir, gc.libsRootURLs); err != nil {
return err
}
if err := gc.generateHelperFile(gc.TargetDir); err != nil {
return err
}
if err := gc.generateSecurity(gc.TargetDir); err != nil {
return err
}
if err := gc.generateServices(gc.TargetDir); err != nil {
return err
}
return gc.generateClientFile(gc.TargetDir)
} | [
"func",
"(",
"gc",
"Client",
")",
"Generate",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"commons",
".",
"CheckDuplicatedTitleTypes",
"(",
"gc",
".",
"apiDef",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// helper package",
"gh",
":=",
"goramlHelper",
"{",
"packageName",
":",
"\"",
"\"",
",",
"packageDir",
":",
"\"",
"\"",
",",
"}",
"\n",
"if",
"err",
":=",
"gh",
".",
"generate",
"(",
"gc",
".",
"TargetDir",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// generate struct",
"if",
"err",
":=",
"generateAllStructs",
"(",
"gc",
".",
"apiDef",
",",
"gc",
".",
"TargetDir",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// libraries",
"if",
"err",
":=",
"generateLibraries",
"(",
"gc",
".",
"libraries",
",",
"gc",
".",
"TargetDir",
",",
"gc",
".",
"libsRootURLs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"gc",
".",
"generateHelperFile",
"(",
"gc",
".",
"TargetDir",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"gc",
".",
"generateSecurity",
"(",
"gc",
".",
"TargetDir",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"gc",
".",
"generateServices",
"(",
"gc",
".",
"TargetDir",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"gc",
".",
"generateClientFile",
"(",
"gc",
".",
"TargetDir",
")",
"\n",
"}"
] | // 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 |
3,175 | 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",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fileName",
",",
"true",
")",
"\n",
"}"
] | // generate Go client helper | [
"generate",
"Go",
"client",
"helper"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/client.go#L106-L109 |
3,176 | 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",
")",
"+",
"\"",
"\"",
")",
"\n",
"return",
"commons",
".",
"GenerateFile",
"(",
"gc",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fileName",
",",
"true",
")",
"\n",
"}"
] | // 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 |
3,177 | 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",
"\"",
"\"",
"+",
"name",
"+",
"\"",
"\"",
"\n",
"}"
] | // 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 |
3,178 | 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.inheritFromTraits(nil, append(rt.Is, rt.Post.Is...), traitsMap, apiDef)
rt.methods = append(rt.methods, rt.Post)
}
if rt.Put != nil {
rt.Put.Name = "PUT"
rt.Put.inheritFromTraits(nil, append(rt.Is, rt.Put.Is...), traitsMap, apiDef)
rt.methods = append(rt.methods, rt.Put)
}
if rt.Patch != nil {
rt.Patch.Name = "PATCH"
rt.Patch.inheritFromTraits(nil, append(rt.Is, rt.Patch.Is...), traitsMap, apiDef)
rt.methods = append(rt.methods, rt.Patch)
}
if rt.Head != nil {
rt.Head.Name = "HEAD"
rt.Head.inheritFromTraits(nil, append(rt.Is, rt.Head.Is...), traitsMap, apiDef)
rt.methods = append(rt.methods, rt.Head)
}
if rt.Delete != nil {
rt.Delete.Name = "DELETE"
rt.Delete.inheritFromTraits(nil, append(rt.Is, rt.Delete.Is...), traitsMap, apiDef)
rt.methods = append(rt.methods, rt.Delete)
}
if rt.Options != nil {
rt.Options.Name = "OPTIONS"
rt.Options.inheritFromTraits(nil, append(rt.Is, rt.Options.Is...), traitsMap, apiDef)
rt.methods = append(rt.methods, rt.Options)
}
} | 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.inheritFromTraits(nil, append(rt.Is, rt.Post.Is...), traitsMap, apiDef)
rt.methods = append(rt.methods, rt.Post)
}
if rt.Put != nil {
rt.Put.Name = "PUT"
rt.Put.inheritFromTraits(nil, append(rt.Is, rt.Put.Is...), traitsMap, apiDef)
rt.methods = append(rt.methods, rt.Put)
}
if rt.Patch != nil {
rt.Patch.Name = "PATCH"
rt.Patch.inheritFromTraits(nil, append(rt.Is, rt.Patch.Is...), traitsMap, apiDef)
rt.methods = append(rt.methods, rt.Patch)
}
if rt.Head != nil {
rt.Head.Name = "HEAD"
rt.Head.inheritFromTraits(nil, append(rt.Is, rt.Head.Is...), traitsMap, apiDef)
rt.methods = append(rt.methods, rt.Head)
}
if rt.Delete != nil {
rt.Delete.Name = "DELETE"
rt.Delete.inheritFromTraits(nil, append(rt.Is, rt.Delete.Is...), traitsMap, apiDef)
rt.methods = append(rt.methods, rt.Delete)
}
if rt.Options != nil {
rt.Options.Name = "OPTIONS"
rt.Options.inheritFromTraits(nil, append(rt.Is, rt.Options.Is...), traitsMap, apiDef)
rt.methods = append(rt.methods, rt.Options)
}
} | [
"func",
"(",
"rt",
"*",
"ResourceType",
")",
"setMethods",
"(",
"traitsMap",
"map",
"[",
"string",
"]",
"Trait",
",",
"apiDef",
"*",
"APIDefinition",
")",
"{",
"if",
"rt",
".",
"Get",
"!=",
"nil",
"{",
"rt",
".",
"Get",
".",
"Name",
"=",
"\"",
"\"",
"\n",
"rt",
".",
"Get",
".",
"inheritFromTraits",
"(",
"nil",
",",
"append",
"(",
"rt",
".",
"Is",
",",
"rt",
".",
"Get",
".",
"Is",
"...",
")",
",",
"traitsMap",
",",
"apiDef",
")",
"\n",
"rt",
".",
"methods",
"=",
"append",
"(",
"rt",
".",
"methods",
",",
"rt",
".",
"Get",
")",
"\n",
"}",
"\n",
"if",
"rt",
".",
"Post",
"!=",
"nil",
"{",
"rt",
".",
"Post",
".",
"Name",
"=",
"\"",
"\"",
"\n",
"rt",
".",
"Post",
".",
"inheritFromTraits",
"(",
"nil",
",",
"append",
"(",
"rt",
".",
"Is",
",",
"rt",
".",
"Post",
".",
"Is",
"...",
")",
",",
"traitsMap",
",",
"apiDef",
")",
"\n",
"rt",
".",
"methods",
"=",
"append",
"(",
"rt",
".",
"methods",
",",
"rt",
".",
"Post",
")",
"\n",
"}",
"\n",
"if",
"rt",
".",
"Put",
"!=",
"nil",
"{",
"rt",
".",
"Put",
".",
"Name",
"=",
"\"",
"\"",
"\n",
"rt",
".",
"Put",
".",
"inheritFromTraits",
"(",
"nil",
",",
"append",
"(",
"rt",
".",
"Is",
",",
"rt",
".",
"Put",
".",
"Is",
"...",
")",
",",
"traitsMap",
",",
"apiDef",
")",
"\n",
"rt",
".",
"methods",
"=",
"append",
"(",
"rt",
".",
"methods",
",",
"rt",
".",
"Put",
")",
"\n",
"}",
"\n",
"if",
"rt",
".",
"Patch",
"!=",
"nil",
"{",
"rt",
".",
"Patch",
".",
"Name",
"=",
"\"",
"\"",
"\n",
"rt",
".",
"Patch",
".",
"inheritFromTraits",
"(",
"nil",
",",
"append",
"(",
"rt",
".",
"Is",
",",
"rt",
".",
"Patch",
".",
"Is",
"...",
")",
",",
"traitsMap",
",",
"apiDef",
")",
"\n",
"rt",
".",
"methods",
"=",
"append",
"(",
"rt",
".",
"methods",
",",
"rt",
".",
"Patch",
")",
"\n",
"}",
"\n",
"if",
"rt",
".",
"Head",
"!=",
"nil",
"{",
"rt",
".",
"Head",
".",
"Name",
"=",
"\"",
"\"",
"\n",
"rt",
".",
"Head",
".",
"inheritFromTraits",
"(",
"nil",
",",
"append",
"(",
"rt",
".",
"Is",
",",
"rt",
".",
"Head",
".",
"Is",
"...",
")",
",",
"traitsMap",
",",
"apiDef",
")",
"\n",
"rt",
".",
"methods",
"=",
"append",
"(",
"rt",
".",
"methods",
",",
"rt",
".",
"Head",
")",
"\n",
"}",
"\n",
"if",
"rt",
".",
"Delete",
"!=",
"nil",
"{",
"rt",
".",
"Delete",
".",
"Name",
"=",
"\"",
"\"",
"\n",
"rt",
".",
"Delete",
".",
"inheritFromTraits",
"(",
"nil",
",",
"append",
"(",
"rt",
".",
"Is",
",",
"rt",
".",
"Delete",
".",
"Is",
"...",
")",
",",
"traitsMap",
",",
"apiDef",
")",
"\n",
"rt",
".",
"methods",
"=",
"append",
"(",
"rt",
".",
"methods",
",",
"rt",
".",
"Delete",
")",
"\n",
"}",
"\n",
"if",
"rt",
".",
"Options",
"!=",
"nil",
"{",
"rt",
".",
"Options",
".",
"Name",
"=",
"\"",
"\"",
"\n",
"rt",
".",
"Options",
".",
"inheritFromTraits",
"(",
"nil",
",",
"append",
"(",
"rt",
".",
"Is",
",",
"rt",
".",
"Options",
".",
"Is",
"...",
")",
",",
"traitsMap",
",",
"apiDef",
")",
"\n",
"rt",
".",
"methods",
"=",
"append",
"(",
"rt",
".",
"methods",
",",
"rt",
".",
"Options",
")",
"\n",
"}",
"\n",
"}"
] | // 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 |
3,179 | 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.OptionalPut != nil {
rt.OptionalPut.Name = "PUT"
rt.optionalMethods = append(rt.optionalMethods, rt.OptionalPut)
}
if rt.OptionalPatch != nil {
rt.OptionalPatch.Name = "PATCH"
rt.optionalMethods = append(rt.optionalMethods, rt.OptionalPatch)
}
if rt.OptionalHead != nil {
rt.OptionalHead.Name = "HEAD"
rt.optionalMethods = append(rt.optionalMethods, rt.OptionalHead)
}
if rt.OptionalDelete != nil {
rt.OptionalDelete.Name = "DELETE"
rt.optionalMethods = append(rt.optionalMethods, rt.OptionalDelete)
}
if rt.OptionalOptions != nil {
rt.OptionalOptions.Name = "OPTIONS"
rt.optionalMethods = append(rt.optionalMethods, rt.OptionalOptions)
}
} | 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.OptionalPut != nil {
rt.OptionalPut.Name = "PUT"
rt.optionalMethods = append(rt.optionalMethods, rt.OptionalPut)
}
if rt.OptionalPatch != nil {
rt.OptionalPatch.Name = "PATCH"
rt.optionalMethods = append(rt.optionalMethods, rt.OptionalPatch)
}
if rt.OptionalHead != nil {
rt.OptionalHead.Name = "HEAD"
rt.optionalMethods = append(rt.optionalMethods, rt.OptionalHead)
}
if rt.OptionalDelete != nil {
rt.OptionalDelete.Name = "DELETE"
rt.optionalMethods = append(rt.optionalMethods, rt.OptionalDelete)
}
if rt.OptionalOptions != nil {
rt.OptionalOptions.Name = "OPTIONS"
rt.optionalMethods = append(rt.optionalMethods, rt.OptionalOptions)
}
} | [
"func",
"(",
"rt",
"*",
"ResourceType",
")",
"setOptionalMethods",
"(",
")",
"{",
"if",
"rt",
".",
"OptionalGet",
"!=",
"nil",
"{",
"rt",
".",
"OptionalGet",
".",
"Name",
"=",
"\"",
"\"",
"\n",
"rt",
".",
"optionalMethods",
"=",
"append",
"(",
"rt",
".",
"optionalMethods",
",",
"rt",
".",
"OptionalGet",
")",
"\n",
"}",
"\n",
"if",
"rt",
".",
"OptionalPost",
"!=",
"nil",
"{",
"rt",
".",
"OptionalPost",
".",
"Name",
"=",
"\"",
"\"",
"\n",
"rt",
".",
"optionalMethods",
"=",
"append",
"(",
"rt",
".",
"optionalMethods",
",",
"rt",
".",
"OptionalPost",
")",
"\n",
"}",
"\n",
"if",
"rt",
".",
"OptionalPut",
"!=",
"nil",
"{",
"rt",
".",
"OptionalPut",
".",
"Name",
"=",
"\"",
"\"",
"\n",
"rt",
".",
"optionalMethods",
"=",
"append",
"(",
"rt",
".",
"optionalMethods",
",",
"rt",
".",
"OptionalPut",
")",
"\n",
"}",
"\n",
"if",
"rt",
".",
"OptionalPatch",
"!=",
"nil",
"{",
"rt",
".",
"OptionalPatch",
".",
"Name",
"=",
"\"",
"\"",
"\n",
"rt",
".",
"optionalMethods",
"=",
"append",
"(",
"rt",
".",
"optionalMethods",
",",
"rt",
".",
"OptionalPatch",
")",
"\n",
"}",
"\n",
"if",
"rt",
".",
"OptionalHead",
"!=",
"nil",
"{",
"rt",
".",
"OptionalHead",
".",
"Name",
"=",
"\"",
"\"",
"\n",
"rt",
".",
"optionalMethods",
"=",
"append",
"(",
"rt",
".",
"optionalMethods",
",",
"rt",
".",
"OptionalHead",
")",
"\n",
"}",
"\n",
"if",
"rt",
".",
"OptionalDelete",
"!=",
"nil",
"{",
"rt",
".",
"OptionalDelete",
".",
"Name",
"=",
"\"",
"\"",
"\n",
"rt",
".",
"optionalMethods",
"=",
"append",
"(",
"rt",
".",
"optionalMethods",
",",
"rt",
".",
"OptionalDelete",
")",
"\n",
"}",
"\n",
"if",
"rt",
".",
"OptionalOptions",
"!=",
"nil",
"{",
"rt",
".",
"OptionalOptions",
".",
"Name",
"=",
"\"",
"\"",
"\n",
"rt",
".",
"optionalMethods",
"=",
"append",
"(",
"rt",
".",
"optionalMethods",
",",
"rt",
".",
"OptionalOptions",
")",
"\n",
"}",
"\n",
"}"
] | // 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 |
3,180 | 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
return name
}
// get the library object from API definition root object
libName := splt[0]
lib, ok := apiDef.Libraries[libName]
if !ok {
return name
}
// type not exist in the library
if _, ok := lib.Types[name]; !ok {
return name
}
return strings.Join([]string{libName, name}, ".")
} | 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
return name
}
// get the library object from API definition root object
libName := splt[0]
lib, ok := apiDef.Libraries[libName]
if !ok {
return name
}
// type not exist in the library
if _, ok := lib.Types[name]; !ok {
return name
}
return strings.Join([]string{libName, name}, ".")
} | [
"func",
"mergeTypeName",
"(",
"name",
",",
"rtName",
"string",
",",
"apiDef",
"*",
"APIDefinition",
")",
"string",
"{",
"if",
"apiDef",
"==",
"nil",
"{",
"log",
".",
"Warning",
"(",
"\"",
"\"",
")",
"\n",
"return",
"name",
"\n",
"}",
"\n\n",
"// check if this resource type is in library",
"splt",
":=",
"strings",
".",
"Split",
"(",
"rtName",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"splt",
")",
"<",
"2",
"{",
"// if not in library, we need to do nothing",
"return",
"name",
"\n",
"}",
"\n\n",
"// get the library object from API definition root object",
"libName",
":=",
"splt",
"[",
"0",
"]",
"\n",
"lib",
",",
"ok",
":=",
"apiDef",
".",
"Libraries",
"[",
"libName",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"name",
"\n",
"}",
"\n\n",
"// type not exist in the library",
"if",
"_",
",",
"ok",
":=",
"lib",
".",
"Types",
"[",
"name",
"]",
";",
"!",
"ok",
"{",
"return",
"name",
"\n",
"}",
"\n\n",
"return",
"strings",
".",
"Join",
"(",
"[",
"]",
"string",
"{",
"libName",
",",
"name",
"}",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // 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 |
3,181 | 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: command.PackageName,
Lang: command.Language,
APIDocsDir: apiDocsDir,
RootImportPath: command.ImportPath,
WithMain: !command.NoMainGeneration,
LibRootURLs: strings.Split(command.LibRootURLs, ","),
}
return cs.Generate()
} | 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: command.PackageName,
Lang: command.Language,
APIDocsDir: apiDocsDir,
RootImportPath: command.ImportPath,
WithMain: !command.NoMainGeneration,
LibRootURLs: strings.Split(command.LibRootURLs, ","),
}
return cs.Generate()
} | [
"func",
"(",
"command",
"*",
"ServerCommand",
")",
"Execute",
"(",
")",
"error",
"{",
"var",
"apiDocsDir",
"string",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"command",
".",
"Language",
")",
"\n\n",
"if",
"!",
"command",
".",
"NoAPIDocs",
"{",
"apiDocsDir",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"cs",
":=",
"codegen",
".",
"Server",
"{",
"RAMLFile",
":",
"command",
".",
"RamlFile",
",",
"Kind",
":",
"command",
".",
"Kind",
",",
"Dir",
":",
"command",
".",
"Dir",
",",
"PackageName",
":",
"command",
".",
"PackageName",
",",
"Lang",
":",
"command",
".",
"Language",
",",
"APIDocsDir",
":",
"apiDocsDir",
",",
"RootImportPath",
":",
"command",
".",
"ImportPath",
",",
"WithMain",
":",
"!",
"command",
".",
"NoMainGeneration",
",",
"LibRootURLs",
":",
"strings",
".",
"Split",
"(",
"command",
".",
"LibRootURLs",
",",
"\"",
"\"",
")",
",",
"}",
"\n",
"return",
"cs",
".",
"Generate",
"(",
")",
"\n",
"}"
] | // 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 |
3,182 | 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 {
return goramlErr
}
// parse based on content type
switch resp.Header.Get("Content-Type") {
case "application/json":
err = json.Unmarshal(b, data)
case "text/plain":
_, err = fmt.Sscanf(string(b), "%v", data)
default:
return goramlErr
}
if err == nil {
goramlErr.Message = data
}
return goramlErr
} | 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 {
return goramlErr
}
// parse based on content type
switch resp.Header.Get("Content-Type") {
case "application/json":
err = json.Unmarshal(b, data)
case "text/plain":
_, err = fmt.Sscanf(string(b), "%v", data)
default:
return goramlErr
}
if err == nil {
goramlErr.Message = data
}
return goramlErr
} | [
"func",
"NewAPIError",
"(",
"resp",
"*",
"http",
".",
"Response",
",",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"// read response body",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// creates object",
"goramlErr",
":=",
"APIError",
"{",
"Code",
":",
"resp",
".",
"StatusCode",
",",
"RawMessage",
":",
"b",
",",
"}",
"\n\n",
"// no need to parse in case of `data` is nil",
"if",
"data",
"==",
"nil",
"{",
"return",
"goramlErr",
"\n",
"}",
"\n\n",
"// parse based on content type",
"switch",
"resp",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"{",
"case",
"\"",
"\"",
":",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"data",
")",
"\n",
"case",
"\"",
"\"",
":",
"_",
",",
"err",
"=",
"fmt",
".",
"Sscanf",
"(",
"string",
"(",
"b",
")",
",",
"\"",
"\"",
",",
"data",
")",
"\n",
"default",
":",
"return",
"goramlErr",
"\n",
"}",
"\n\n",
"if",
"err",
"==",
"nil",
"{",
"goramlErr",
".",
"Message",
"=",
"data",
"\n",
"}",
"\n",
"return",
"goramlErr",
"\n",
"}"
] | // 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 |
3,183 | 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",
"(",
"m",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // set middlewares to import | [
"set",
"middlewares",
"to",
"import"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/python/resources.go#L77-L83 |
3,184 | Jumpscale/go-raml | codegen/python/jsonschema.go | getParentsObjs | func getParentsObjs(parents []string) []raml.JSONSchema {
objs := []raml.JSONSchema{}
for _, p := range parents {
if v, ok := jsObjects[p]; ok {
objs = append(objs, v)
}
}
return objs
} | go | func getParentsObjs(parents []string) []raml.JSONSchema {
objs := []raml.JSONSchema{}
for _, p := range parents {
if v, ok := jsObjects[p]; ok {
objs = append(objs, v)
}
}
return objs
} | [
"func",
"getParentsObjs",
"(",
"parents",
"[",
"]",
"string",
")",
"[",
"]",
"raml",
".",
"JSONSchema",
"{",
"objs",
":=",
"[",
"]",
"raml",
".",
"JSONSchema",
"{",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"parents",
"{",
"if",
"v",
",",
"ok",
":=",
"jsObjects",
"[",
"p",
"]",
";",
"ok",
"{",
"objs",
"=",
"append",
"(",
"objs",
",",
"v",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"objs",
"\n",
"}"
] | // get JSON schema objects from array of JSON schema name | [
"get",
"JSON",
"schema",
"objects",
"from",
"array",
"of",
"JSON",
"schema",
"name"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/python/jsonschema.go#L133-L141 |
3,185 | Jumpscale/go-raml | codegen/python/jsonschema.go | jsArrayName | func jsArrayName(tip string) string {
if !commons.IsArrayType(tip) {
// make sure it is an array
return tip
}
return "List_" + commons.GetBasicType(tip)
} | go | func jsArrayName(tip string) string {
if !commons.IsArrayType(tip) {
// make sure it is an array
return tip
}
return "List_" + commons.GetBasicType(tip)
} | [
"func",
"jsArrayName",
"(",
"tip",
"string",
")",
"string",
"{",
"if",
"!",
"commons",
".",
"IsArrayType",
"(",
"tip",
")",
"{",
"// make sure it is an array",
"return",
"tip",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"+",
"commons",
".",
"GetBasicType",
"(",
"tip",
")",
"\n",
"}"
] | // return jsonschema name of new schema
// that created from an array | [
"return",
"jsonschema",
"name",
"of",
"new",
"schema",
"that",
"created",
"from",
"an",
"array"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/python/jsonschema.go#L151-L157 |
3,186 | Jumpscale/go-raml | codegen/python/jsonschema.go | Generate | func (js jsonSchema) Generate(dir string) error {
if js.Alias.Builtin {
return nil // plain builtin type can't be a JSON
}
filename := filepath.Join(dir, js.filename())
ctx := map[string]interface{}{
"Content": js.String(),
}
return commons.GenerateFile(ctx, "./templates/golang/json_schema.tmpl", "json_schema", filename, true)
} | go | func (js jsonSchema) Generate(dir string) error {
if js.Alias.Builtin {
return nil // plain builtin type can't be a JSON
}
filename := filepath.Join(dir, js.filename())
ctx := map[string]interface{}{
"Content": js.String(),
}
return commons.GenerateFile(ctx, "./templates/golang/json_schema.tmpl", "json_schema", filename, true)
} | [
"func",
"(",
"js",
"jsonSchema",
")",
"Generate",
"(",
"dir",
"string",
")",
"error",
"{",
"if",
"js",
".",
"Alias",
".",
"Builtin",
"{",
"return",
"nil",
"// plain builtin type can't be a JSON",
"\n",
"}",
"\n\n",
"filename",
":=",
"filepath",
".",
"Join",
"(",
"dir",
",",
"js",
".",
"filename",
"(",
")",
")",
"\n",
"ctx",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"js",
".",
"String",
"(",
")",
",",
"}",
"\n",
"return",
"commons",
".",
"GenerateFile",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"filename",
",",
"true",
")",
"\n",
"}"
] | // Generate generates a json file of this schema | [
"Generate",
"generates",
"a",
"json",
"file",
"of",
"this",
"schema"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/python/jsonschema.go#L164-L174 |
3,187 | Jumpscale/go-raml | codegen/libraries/libraries.go | IsRemote | func IsRemote(path string) bool {
return strings.HasPrefix(path, "http://") || strings.HasPrefix(path, "https://")
} | go | func IsRemote(path string) bool {
return strings.HasPrefix(path, "http://") || strings.HasPrefix(path, "https://")
} | [
"func",
"IsRemote",
"(",
"path",
"string",
")",
"bool",
"{",
"return",
"strings",
".",
"HasPrefix",
"(",
"path",
",",
"\"",
"\"",
")",
"||",
"strings",
".",
"HasPrefix",
"(",
"path",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // IsRemote returns true if this library is on the remote url | [
"IsRemote",
"returns",
"true",
"if",
"this",
"library",
"is",
"on",
"the",
"remote",
"url"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/libraries/libraries.go#L9-L11 |
3,188 | Jumpscale/go-raml | codegen/libraries/libraries.go | StripLibRootURL | func StripLibRootURL(libFile string, libRootURLs []string) string {
if !IsRemote(libFile) {
return libFile
}
for _, root := range libRootURLs {
if strings.HasPrefix(libFile, root) {
libFile = strings.TrimPrefix(libFile, root)
libFile = strings.TrimPrefix(libFile, "/")
break
}
}
return libFile
} | go | func StripLibRootURL(libFile string, libRootURLs []string) string {
if !IsRemote(libFile) {
return libFile
}
for _, root := range libRootURLs {
if strings.HasPrefix(libFile, root) {
libFile = strings.TrimPrefix(libFile, root)
libFile = strings.TrimPrefix(libFile, "/")
break
}
}
return libFile
} | [
"func",
"StripLibRootURL",
"(",
"libFile",
"string",
",",
"libRootURLs",
"[",
"]",
"string",
")",
"string",
"{",
"if",
"!",
"IsRemote",
"(",
"libFile",
")",
"{",
"return",
"libFile",
"\n",
"}",
"\n",
"for",
"_",
",",
"root",
":=",
"range",
"libRootURLs",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"libFile",
",",
"root",
")",
"{",
"libFile",
"=",
"strings",
".",
"TrimPrefix",
"(",
"libFile",
",",
"root",
")",
"\n",
"libFile",
"=",
"strings",
".",
"TrimPrefix",
"(",
"libFile",
",",
"\"",
"\"",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"libFile",
"\n",
"}"
] | // StripLibRootURL strips root URL from library path | [
"StripLibRootURL",
"strips",
"root",
"URL",
"from",
"library",
"path"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/libraries/libraries.go#L14-L26 |
3,189 | Jumpscale/go-raml | codegen/golang/util.go | setRootImportPath | func setRootImportPath(importPath, targetDir string) string {
// use import path if not empty
if len(importPath) > 0 {
return importPath
}
// get GOPATH dir
gopath, err := filepath.Abs(os.Getenv("GOPATH"))
if err != nil {
return ""
}
gopath = filepath.Join(gopath, "src")
// get absolute target dir
absTargetDir, err := filepath.Abs(targetDir)
if err != nil {
panic("invalid targetDir:" + err.Error())
}
// panic if user doesn't specify import path and target dir
// not under GOPATH.
if !strings.HasPrefix(absTargetDir, gopath) {
panic("please specify '--import-path' or set '--dir' under your GOPATH")
}
// set import path
newImportPath, err := filepath.Rel(gopath, absTargetDir)
if err != nil {
panic("failed to set import path automatically:" + err.Error())
}
// re-join because otherwise windows will use `\`
return path.Join(strings.Split(newImportPath, string(filepath.Separator))...)
} | go | func setRootImportPath(importPath, targetDir string) string {
// use import path if not empty
if len(importPath) > 0 {
return importPath
}
// get GOPATH dir
gopath, err := filepath.Abs(os.Getenv("GOPATH"))
if err != nil {
return ""
}
gopath = filepath.Join(gopath, "src")
// get absolute target dir
absTargetDir, err := filepath.Abs(targetDir)
if err != nil {
panic("invalid targetDir:" + err.Error())
}
// panic if user doesn't specify import path and target dir
// not under GOPATH.
if !strings.HasPrefix(absTargetDir, gopath) {
panic("please specify '--import-path' or set '--dir' under your GOPATH")
}
// set import path
newImportPath, err := filepath.Rel(gopath, absTargetDir)
if err != nil {
panic("failed to set import path automatically:" + err.Error())
}
// re-join because otherwise windows will use `\`
return path.Join(strings.Split(newImportPath, string(filepath.Separator))...)
} | [
"func",
"setRootImportPath",
"(",
"importPath",
",",
"targetDir",
"string",
")",
"string",
"{",
"// use import path if not empty",
"if",
"len",
"(",
"importPath",
")",
">",
"0",
"{",
"return",
"importPath",
"\n",
"}",
"\n\n",
"// get GOPATH dir",
"gopath",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"gopath",
"=",
"filepath",
".",
"Join",
"(",
"gopath",
",",
"\"",
"\"",
")",
"\n\n",
"// get absolute target dir",
"absTargetDir",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"targetDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n\n",
"// panic if user doesn't specify import path and target dir",
"// not under GOPATH.",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"absTargetDir",
",",
"gopath",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// set import path",
"newImportPath",
",",
"err",
":=",
"filepath",
".",
"Rel",
"(",
"gopath",
",",
"absTargetDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n\n",
"// re-join because otherwise windows will use `\\`",
"return",
"path",
".",
"Join",
"(",
"strings",
".",
"Split",
"(",
"newImportPath",
",",
"string",
"(",
"filepath",
".",
"Separator",
")",
")",
"...",
")",
"\n",
"}"
] | // try to set root import path based on target dir
// - do nothing if user specify import path
// - if target dir is under GOPATH, set it to the target dir | [
"try",
"to",
"set",
"root",
"import",
"path",
"based",
"on",
"target",
"dir",
"-",
"do",
"nothing",
"if",
"user",
"specify",
"import",
"path",
"-",
"if",
"target",
"dir",
"is",
"under",
"GOPATH",
"set",
"it",
"to",
"the",
"target",
"dir"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/util.go#L13-L46 |
3,190 | Jumpscale/go-raml | codegen/golang/method.go | addPackage | func addPackage(pkgName, typeStr string) string {
if typeStr == "" {
return ""
}
// we can't use raml package to get basic type and decide whether it is array
// or not because in this phase the type is already Go type, not RAML type
switch {
case strings.HasPrefix(typeStr, "[][]"): // bidimensi array
return "[][]" + addPackage(pkgName, strings.TrimPrefix(typeStr, "[][]"))
case strings.HasPrefix(typeStr, "[]"): // array array
return "[]" + addPackage(pkgName, strings.TrimPrefix(typeStr, "[]"))
default:
return aliasPackage(fmt.Sprintf("%v.%v", pkgName, typeStr))
}
} | go | func addPackage(pkgName, typeStr string) string {
if typeStr == "" {
return ""
}
// we can't use raml package to get basic type and decide whether it is array
// or not because in this phase the type is already Go type, not RAML type
switch {
case strings.HasPrefix(typeStr, "[][]"): // bidimensi array
return "[][]" + addPackage(pkgName, strings.TrimPrefix(typeStr, "[][]"))
case strings.HasPrefix(typeStr, "[]"): // array array
return "[]" + addPackage(pkgName, strings.TrimPrefix(typeStr, "[]"))
default:
return aliasPackage(fmt.Sprintf("%v.%v", pkgName, typeStr))
}
} | [
"func",
"addPackage",
"(",
"pkgName",
",",
"typeStr",
"string",
")",
"string",
"{",
"if",
"typeStr",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// we can't use raml package to get basic type and decide whether it is array",
"// or not because in this phase the type is already Go type, not RAML type",
"switch",
"{",
"case",
"strings",
".",
"HasPrefix",
"(",
"typeStr",
",",
"\"",
"\"",
")",
":",
"// bidimensi array",
"return",
"\"",
"\"",
"+",
"addPackage",
"(",
"pkgName",
",",
"strings",
".",
"TrimPrefix",
"(",
"typeStr",
",",
"\"",
"\"",
")",
")",
"\n",
"case",
"strings",
".",
"HasPrefix",
"(",
"typeStr",
",",
"\"",
"\"",
")",
":",
"// array array",
"return",
"\"",
"\"",
"+",
"addPackage",
"(",
"pkgName",
",",
"strings",
".",
"TrimPrefix",
"(",
"typeStr",
",",
"\"",
"\"",
")",
")",
"\n",
"default",
":",
"return",
"aliasPackage",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pkgName",
",",
"typeStr",
")",
")",
"\n",
"}",
"\n",
"}"
] | // add package name to the request and response body | [
"add",
"package",
"name",
"to",
"the",
"request",
"and",
"response",
"body"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/method.go#L54-L69 |
3,191 | Jumpscale/go-raml | codegen/golang/method.go | FailedRespBodyTypes | func (m method) FailedRespBodyTypes() (resps []respBody) {
for _, resp := range m.RespBodyTypes() {
if resp.Code < 200 || resp.Code >= 300 {
resps = append(resps, resp)
}
}
return
} | go | func (m method) FailedRespBodyTypes() (resps []respBody) {
for _, resp := range m.RespBodyTypes() {
if resp.Code < 200 || resp.Code >= 300 {
resps = append(resps, resp)
}
}
return
} | [
"func",
"(",
"m",
"method",
")",
"FailedRespBodyTypes",
"(",
")",
"(",
"resps",
"[",
"]",
"respBody",
")",
"{",
"for",
"_",
",",
"resp",
":=",
"range",
"m",
".",
"RespBodyTypes",
"(",
")",
"{",
"if",
"resp",
".",
"Code",
"<",
"200",
"||",
"resp",
".",
"Code",
">=",
"300",
"{",
"resps",
"=",
"append",
"(",
"resps",
",",
"resp",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // FailedRespBodyTypes return all response body that considered a failed response
// i.e. non 2xx status code | [
"FailedRespBodyTypes",
"return",
"all",
"response",
"body",
"that",
"considered",
"a",
"failed",
"response",
"i",
".",
"e",
".",
"non",
"2xx",
"status",
"code"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/method.go#L117-L124 |
3,192 | Jumpscale/go-raml | codegen/golang/method.go | needImportGoramlTypes | func (m method) needImportGoramlTypes() bool {
pkgPrefix := typePackage + "."
needImport := func(typeStr string) bool {
switch {
case strings.HasPrefix(typeStr, "[][]"+pkgPrefix):
return true
case strings.HasPrefix(typeStr, "[]"+pkgPrefix):
return true
case strings.HasPrefix(typeStr, pkgPrefix):
return true
default:
return false
}
}
if needImport(m.ReqBody()) {
return true
}
for _, resp := range m.RespBodyTypes() {
if needImport(resp.Type()) {
return true
}
}
return false
} | go | func (m method) needImportGoramlTypes() bool {
pkgPrefix := typePackage + "."
needImport := func(typeStr string) bool {
switch {
case strings.HasPrefix(typeStr, "[][]"+pkgPrefix):
return true
case strings.HasPrefix(typeStr, "[]"+pkgPrefix):
return true
case strings.HasPrefix(typeStr, pkgPrefix):
return true
default:
return false
}
}
if needImport(m.ReqBody()) {
return true
}
for _, resp := range m.RespBodyTypes() {
if needImport(resp.Type()) {
return true
}
}
return false
} | [
"func",
"(",
"m",
"method",
")",
"needImportGoramlTypes",
"(",
")",
"bool",
"{",
"pkgPrefix",
":=",
"typePackage",
"+",
"\"",
"\"",
"\n",
"needImport",
":=",
"func",
"(",
"typeStr",
"string",
")",
"bool",
"{",
"switch",
"{",
"case",
"strings",
".",
"HasPrefix",
"(",
"typeStr",
",",
"\"",
"\"",
"+",
"pkgPrefix",
")",
":",
"return",
"true",
"\n",
"case",
"strings",
".",
"HasPrefix",
"(",
"typeStr",
",",
"\"",
"\"",
"+",
"pkgPrefix",
")",
":",
"return",
"true",
"\n",
"case",
"strings",
".",
"HasPrefix",
"(",
"typeStr",
",",
"pkgPrefix",
")",
":",
"return",
"true",
"\n",
"default",
":",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"needImport",
"(",
"m",
".",
"ReqBody",
"(",
")",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"for",
"_",
",",
"resp",
":=",
"range",
"m",
".",
"RespBodyTypes",
"(",
")",
"{",
"if",
"needImport",
"(",
"resp",
".",
"Type",
"(",
")",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // returns true if need to import goraml generated types | [
"returns",
"true",
"if",
"need",
"to",
"import",
"goraml",
"generated",
"types"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/method.go#L154-L177 |
3,193 | Jumpscale/go-raml | codegen/golang/method.go | getOauth2MwrHandler | func getOauth2MwrHandler(ss raml.DefinitionChoice) (string, error) {
// construct security scopes
quotedScopes, err := security.GetQuotedScopes(ss)
if err != nil {
return "", err
}
scopesArgs := strings.Join(quotedScopes, ", ")
// middleware name
// need to handle case where it reside in different package
var packageName string
name := ss.Name
if splitted := strings.Split(name, "."); len(splitted) == 2 {
packageName = splitted[0]
name = splitted[1]
}
mwr := fmt.Sprintf(`NewOauth2%vMiddleware([]string{%v}).Handler`, name, scopesArgs)
if packageName != "" {
mwr = packageName + "." + mwr
}
return mwr, nil
} | go | func getOauth2MwrHandler(ss raml.DefinitionChoice) (string, error) {
// construct security scopes
quotedScopes, err := security.GetQuotedScopes(ss)
if err != nil {
return "", err
}
scopesArgs := strings.Join(quotedScopes, ", ")
// middleware name
// need to handle case where it reside in different package
var packageName string
name := ss.Name
if splitted := strings.Split(name, "."); len(splitted) == 2 {
packageName = splitted[0]
name = splitted[1]
}
mwr := fmt.Sprintf(`NewOauth2%vMiddleware([]string{%v}).Handler`, name, scopesArgs)
if packageName != "" {
mwr = packageName + "." + mwr
}
return mwr, nil
} | [
"func",
"getOauth2MwrHandler",
"(",
"ss",
"raml",
".",
"DefinitionChoice",
")",
"(",
"string",
",",
"error",
")",
"{",
"// construct security scopes",
"quotedScopes",
",",
"err",
":=",
"security",
".",
"GetQuotedScopes",
"(",
"ss",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"scopesArgs",
":=",
"strings",
".",
"Join",
"(",
"quotedScopes",
",",
"\"",
"\"",
")",
"\n\n",
"// middleware name",
"// need to handle case where it reside in different package",
"var",
"packageName",
"string",
"\n",
"name",
":=",
"ss",
".",
"Name",
"\n\n",
"if",
"splitted",
":=",
"strings",
".",
"Split",
"(",
"name",
",",
"\"",
"\"",
")",
";",
"len",
"(",
"splitted",
")",
"==",
"2",
"{",
"packageName",
"=",
"splitted",
"[",
"0",
"]",
"\n",
"name",
"=",
"splitted",
"[",
"1",
"]",
"\n",
"}",
"\n",
"mwr",
":=",
"fmt",
".",
"Sprintf",
"(",
"`NewOauth2%vMiddleware([]string{%v}).Handler`",
",",
"name",
",",
"scopesArgs",
")",
"\n",
"if",
"packageName",
"!=",
"\"",
"\"",
"{",
"mwr",
"=",
"packageName",
"+",
"\"",
"\"",
"+",
"mwr",
"\n",
"}",
"\n",
"return",
"mwr",
",",
"nil",
"\n",
"}"
] | // get oauth2 middleware handler from a security scheme | [
"get",
"oauth2",
"middleware",
"handler",
"from",
"a",
"security",
"scheme"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/golang/method.go#L180-L202 |
3,194 | Jumpscale/go-raml | codegen/apidocs/apidocs.go | copyLibrariesFiles | func copyLibrariesFiles(uses map[string]string, libs map[string]*raml.Library, ramlFile, dir string,
libRootURLs []string) error {
baseDir := filepath.Dir(ramlFile)
// copy library files
for _, path := range uses {
if err := copyFile(baseDir, path, dir, libRootURLs); err != nil {
return err
}
}
// do it recursively
for _, l := range libs {
if err := copyLibrariesFiles(l.Uses, l.Libraries, filepath.Join(baseDir, l.Filename),
filepath.Join(dir, filepath.Dir(l.Filename)), libRootURLs); err != nil {
return err
}
}
return nil
} | go | func copyLibrariesFiles(uses map[string]string, libs map[string]*raml.Library, ramlFile, dir string,
libRootURLs []string) error {
baseDir := filepath.Dir(ramlFile)
// copy library files
for _, path := range uses {
if err := copyFile(baseDir, path, dir, libRootURLs); err != nil {
return err
}
}
// do it recursively
for _, l := range libs {
if err := copyLibrariesFiles(l.Uses, l.Libraries, filepath.Join(baseDir, l.Filename),
filepath.Join(dir, filepath.Dir(l.Filename)), libRootURLs); err != nil {
return err
}
}
return nil
} | [
"func",
"copyLibrariesFiles",
"(",
"uses",
"map",
"[",
"string",
"]",
"string",
",",
"libs",
"map",
"[",
"string",
"]",
"*",
"raml",
".",
"Library",
",",
"ramlFile",
",",
"dir",
"string",
",",
"libRootURLs",
"[",
"]",
"string",
")",
"error",
"{",
"baseDir",
":=",
"filepath",
".",
"Dir",
"(",
"ramlFile",
")",
"\n",
"// copy library files",
"for",
"_",
",",
"path",
":=",
"range",
"uses",
"{",
"if",
"err",
":=",
"copyFile",
"(",
"baseDir",
",",
"path",
",",
"dir",
",",
"libRootURLs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// do it recursively",
"for",
"_",
",",
"l",
":=",
"range",
"libs",
"{",
"if",
"err",
":=",
"copyLibrariesFiles",
"(",
"l",
".",
"Uses",
",",
"l",
".",
"Libraries",
",",
"filepath",
".",
"Join",
"(",
"baseDir",
",",
"l",
".",
"Filename",
")",
",",
"filepath",
".",
"Join",
"(",
"dir",
",",
"filepath",
".",
"Dir",
"(",
"l",
".",
"Filename",
")",
")",
",",
"libRootURLs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // copy all library files to apidocs directory | [
"copy",
"all",
"library",
"files",
"to",
"apidocs",
"directory"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/apidocs/apidocs.go#L37-L55 |
3,195 | Jumpscale/go-raml | codegen/apidocs/apidocs.go | copyFile | func copyFile(sourceDir, sourceFile, destDir string, libRootURLs []string) error {
var source io.Reader
if strings.HasPrefix(sourceFile, "http://") || strings.HasPrefix(sourceFile, "https://") {
resp, err := http.Get(sourceFile)
if err != nil {
return err
}
defer resp.Body.Close()
source = resp.Body
} else {
sourceFile, err := os.Open(filepath.Join(sourceDir, sourceFile))
if err != nil {
return err
}
source = sourceFile
}
dest := filepath.Join(destDir, libraries.StripLibRootURL(sourceFile, libRootURLs))
// create target dir if needed
if err := os.MkdirAll(filepath.Dir(dest), 0777); err != nil {
return err
}
// creaate dest file
destFile, err := os.OpenFile(dest, os.O_CREATE|os.O_RDWR, 0666)
if err != nil {
return err
}
_, err = io.Copy(destFile, source)
return err
} | go | func copyFile(sourceDir, sourceFile, destDir string, libRootURLs []string) error {
var source io.Reader
if strings.HasPrefix(sourceFile, "http://") || strings.HasPrefix(sourceFile, "https://") {
resp, err := http.Get(sourceFile)
if err != nil {
return err
}
defer resp.Body.Close()
source = resp.Body
} else {
sourceFile, err := os.Open(filepath.Join(sourceDir, sourceFile))
if err != nil {
return err
}
source = sourceFile
}
dest := filepath.Join(destDir, libraries.StripLibRootURL(sourceFile, libRootURLs))
// create target dir if needed
if err := os.MkdirAll(filepath.Dir(dest), 0777); err != nil {
return err
}
// creaate dest file
destFile, err := os.OpenFile(dest, os.O_CREATE|os.O_RDWR, 0666)
if err != nil {
return err
}
_, err = io.Copy(destFile, source)
return err
} | [
"func",
"copyFile",
"(",
"sourceDir",
",",
"sourceFile",
",",
"destDir",
"string",
",",
"libRootURLs",
"[",
"]",
"string",
")",
"error",
"{",
"var",
"source",
"io",
".",
"Reader",
"\n\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"sourceFile",
",",
"\"",
"\"",
")",
"||",
"strings",
".",
"HasPrefix",
"(",
"sourceFile",
",",
"\"",
"\"",
")",
"{",
"resp",
",",
"err",
":=",
"http",
".",
"Get",
"(",
"sourceFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"source",
"=",
"resp",
".",
"Body",
"\n",
"}",
"else",
"{",
"sourceFile",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filepath",
".",
"Join",
"(",
"sourceDir",
",",
"sourceFile",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"source",
"=",
"sourceFile",
"\n",
"}",
"\n\n",
"dest",
":=",
"filepath",
".",
"Join",
"(",
"destDir",
",",
"libraries",
".",
"StripLibRootURL",
"(",
"sourceFile",
",",
"libRootURLs",
")",
")",
"\n\n",
"// create target dir if needed",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"filepath",
".",
"Dir",
"(",
"dest",
")",
",",
"0777",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// creaate dest file",
"destFile",
",",
"err",
":=",
"os",
".",
"OpenFile",
"(",
"dest",
",",
"os",
".",
"O_CREATE",
"|",
"os",
".",
"O_RDWR",
",",
"0666",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"io",
".",
"Copy",
"(",
"destFile",
",",
"source",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // copy file from source to dest | [
"copy",
"file",
"from",
"source",
"to",
"dest"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/apidocs/apidocs.go#L58-L91 |
3,196 | Jumpscale/go-raml | codegen/apidocs/apidocs.go | extract | func extract(dir string) error {
// create dir if needed
if _, err := os.Stat(dir); os.IsNotExist(err) {
if err := os.MkdirAll(dir, 0777); err != nil {
return err
}
}
return unzip("apidocs_html.zip", dir)
} | go | func extract(dir string) error {
// create dir if needed
if _, err := os.Stat(dir); os.IsNotExist(err) {
if err := os.MkdirAll(dir, 0777); err != nil {
return err
}
}
return unzip("apidocs_html.zip", dir)
} | [
"func",
"extract",
"(",
"dir",
"string",
")",
"error",
"{",
"// create dir if needed",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"dir",
")",
";",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"dir",
",",
"0777",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"unzip",
"(",
"\"",
"\"",
",",
"dir",
")",
"\n",
"}"
] | // Extract extracts API docs data to specified path | [
"Extract",
"extracts",
"API",
"docs",
"data",
"to",
"specified",
"path"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/apidocs/apidocs.go#L94-L104 |
3,197 | Jumpscale/go-raml | codegen/types/types.go | Body | func (tib *TypeInBody) Body() raml.Bodies {
if tib.ReqResp == HTTPRequest {
return tib.Endpoint.Method.Bodies
}
for code, resp := range tib.Endpoint.Method.Responses {
if code == tib.RespCode {
return resp.Bodies
}
}
panic("failed to get body of " + tib.Endpoint.Verb + " " + tib.Endpoint.Addr)
} | go | func (tib *TypeInBody) Body() raml.Bodies {
if tib.ReqResp == HTTPRequest {
return tib.Endpoint.Method.Bodies
}
for code, resp := range tib.Endpoint.Method.Responses {
if code == tib.RespCode {
return resp.Bodies
}
}
panic("failed to get body of " + tib.Endpoint.Verb + " " + tib.Endpoint.Addr)
} | [
"func",
"(",
"tib",
"*",
"TypeInBody",
")",
"Body",
"(",
")",
"raml",
".",
"Bodies",
"{",
"if",
"tib",
".",
"ReqResp",
"==",
"HTTPRequest",
"{",
"return",
"tib",
".",
"Endpoint",
".",
"Method",
".",
"Bodies",
"\n",
"}",
"\n",
"for",
"code",
",",
"resp",
":=",
"range",
"tib",
".",
"Endpoint",
".",
"Method",
".",
"Responses",
"{",
"if",
"code",
"==",
"tib",
".",
"RespCode",
"{",
"return",
"resp",
".",
"Bodies",
"\n",
"}",
"\n",
"}",
"\n",
"panic",
"(",
"\"",
"\"",
"+",
"tib",
".",
"Endpoint",
".",
"Verb",
"+",
"\"",
"\"",
"+",
"tib",
".",
"Endpoint",
".",
"Addr",
")",
"\n",
"}"
] | // Body returns raml.Bodies from TypeInBody object | [
"Body",
"returns",
"raml",
".",
"Bodies",
"from",
"TypeInBody",
"object"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/types/types.go#L22-L32 |
3,198 | Jumpscale/go-raml | codegen/types/types.go | AllTypes | func AllTypes(apiDef *raml.APIDefinition, pkgName string) map[string]TypeTask {
mtt := map[string]TypeTask{}
// from types
for name, tip := range apiDef.Types {
mtt[name] = TypeTask{
Type: tip,
Pkg: pkgName,
Name: name,
}
}
for _, endpoints := range getAllEndpoints(apiDef) {
for _, ep := range endpoints {
tts := getTypesOfEndpoint(ep, pkgName)
for _, tt := range tts {
mtt[tt.Name] = tt
}
}
}
return mtt
} | go | func AllTypes(apiDef *raml.APIDefinition, pkgName string) map[string]TypeTask {
mtt := map[string]TypeTask{}
// from types
for name, tip := range apiDef.Types {
mtt[name] = TypeTask{
Type: tip,
Pkg: pkgName,
Name: name,
}
}
for _, endpoints := range getAllEndpoints(apiDef) {
for _, ep := range endpoints {
tts := getTypesOfEndpoint(ep, pkgName)
for _, tt := range tts {
mtt[tt.Name] = tt
}
}
}
return mtt
} | [
"func",
"AllTypes",
"(",
"apiDef",
"*",
"raml",
".",
"APIDefinition",
",",
"pkgName",
"string",
")",
"map",
"[",
"string",
"]",
"TypeTask",
"{",
"mtt",
":=",
"map",
"[",
"string",
"]",
"TypeTask",
"{",
"}",
"\n\n",
"// from types",
"for",
"name",
",",
"tip",
":=",
"range",
"apiDef",
".",
"Types",
"{",
"mtt",
"[",
"name",
"]",
"=",
"TypeTask",
"{",
"Type",
":",
"tip",
",",
"Pkg",
":",
"pkgName",
",",
"Name",
":",
"name",
",",
"}",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"endpoints",
":=",
"range",
"getAllEndpoints",
"(",
"apiDef",
")",
"{",
"for",
"_",
",",
"ep",
":=",
"range",
"endpoints",
"{",
"tts",
":=",
"getTypesOfEndpoint",
"(",
"ep",
",",
"pkgName",
")",
"\n",
"for",
"_",
",",
"tt",
":=",
"range",
"tts",
"{",
"mtt",
"[",
"tt",
".",
"Name",
"]",
"=",
"tt",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"mtt",
"\n",
"}"
] | // AllTypes returns all TypeTask that need to be generated by the code
// generator | [
"AllTypes",
"returns",
"all",
"TypeTask",
"that",
"need",
"to",
"be",
"generated",
"by",
"the",
"code",
"generator"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/types/types.go#L43-L64 |
3,199 | Jumpscale/go-raml | codegen/types/types.go | singleLineNewType | func singleLineNewType(tip string) bool {
rt := raml.Type{
Type: tip,
}
if rt.IsMultipleInheritance() {
return true
}
if rt.IsUnion() {
return true
}
if rt.IsArray() {
return true
}
return false
} | go | func singleLineNewType(tip string) bool {
rt := raml.Type{
Type: tip,
}
if rt.IsMultipleInheritance() {
return true
}
if rt.IsUnion() {
return true
}
if rt.IsArray() {
return true
}
return false
} | [
"func",
"singleLineNewType",
"(",
"tip",
"string",
")",
"bool",
"{",
"rt",
":=",
"raml",
".",
"Type",
"{",
"Type",
":",
"tip",
",",
"}",
"\n",
"if",
"rt",
".",
"IsMultipleInheritance",
"(",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"rt",
".",
"IsUnion",
"(",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"rt",
".",
"IsArray",
"(",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // single line type definition that need to be
// defined as a new type | [
"single",
"line",
"type",
"definition",
"that",
"need",
"to",
"be",
"defined",
"as",
"a",
"new",
"type"
] | f151e1e143c47282b294fe70c5e56f113988ed10 | https://github.com/Jumpscale/go-raml/blob/f151e1e143c47282b294fe70c5e56f113988ed10/codegen/types/types.go#L136-L150 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.