diff --git a/APLSource/Core/CompileObject.aplf b/APLSource/Core/CompileObject.aplf index 7c232d8..194bfdd 100644 --- a/APLSource/Core/CompileObject.aplf +++ b/APLSource/Core/CompileObject.aplf @@ -1,12 +1,14 @@ - r←depth CompileObject(toolsdir obj name);propnames;properties;mask;f;nstdclassmask;classnames;toolspath + r←depth CompileObject(toolsdir obj name);propnames;properties;mask;f;nstdclassmask;classnames;toolspath;componentspath r←⍬ r,←⊂':Class ',name toolspath←(∊depth/⊂'##.'),toolsdir + componentspath←(∊depth/⊂'##.'),'components' r,←⊂':Include ',toolspath r,←⊂'' r,←⊂' (⎕IO ⎕ML)←1' r,←⊂'' r,←⊂' :Field Private Shared ∆schema←⎕JSON ',Quote ⎕JSON obj + r,←⊂' :Field Private Shared ∆components←',componentspath r,←⊂' :Field Private Shared ∆propertyNames←∆schema.properties.⎕NL ¯9' r,←⊂' :Field Private Shared ∆properties←∆schema.properties.⍎¨∆propertyNames' r,←⊂'' diff --git a/APLSource/Core/CompileOperation.aplf b/APLSource/Core/CompileOperation.aplf new file mode 100644 index 0000000..995b285 --- /dev/null +++ b/APLSource/Core/CompileOperation.aplf @@ -0,0 +1,74 @@ + r←depth CompileOperation(command cmdObj name baseurl path schema toolsdir);reqBody;args;f;hasRequestBody;hasParameters;hasSharedParams;classname;classref;lines;hasNestClass;toolspath;componentspath + r←⍬ + r,←⊂':Class ',name + toolspath←(∊depth/⊂'##.'),toolsdir + componentspath←(∊depth/⊂'##.'),'components' + r,←⊂':Include ',toolspath + r,←⊂'' + r,←⊂' (⎕IO ⎕ML)←1' + r,←⊂'' + r,←⊂' :Field Private Shared ∆schema←⎕JSON ',Quote ⎕JSON cmdObj + r,←⊂' :Field Private Shared ∆components←',componentspath + r,←⊂' :Field Private Shared ∆baseurl←',Quote baseurl + r,←⊂' :Field Private Shared ∆path←',Quote path + + hasSharedParams←⊃0≠cmdObj.##.⎕NC'parameters' + (hasRequestBody hasParameters)←0≠cmdObj.⎕NC'requestBody' 'parameters' + r,←⊂'' + f←⍬ + f,←⊂'r←clt Run args' + f,←⊂':Access Public Shared' + f,←⊂'⍝ (Don''t modify, generated by ',(⊃⎕XSI),')' + f,←{6::'' ⋄ (⊂'⍝ Summary:'),CommentLines ⍵.summary}cmdObj + f,←{6::'' ⋄ (⊂'⍝ Description:'),CommentLines ⍵.description}cmdObj + f,←⊂'⍝ clt: obj, HttpClient instance' + :If hasParameters⍱hasSharedParams + :If hasRequestBody + f,←(⊂'⍝ args: obj, Request body'),{6::'' ⋄ CommentLines ⍵.description}cmdObj.requestBody + :Else + f,←⊂'⍝ args: bs, dummy' + :EndIf + :Else + reqBody←⍬ + :If hasRequestBody + reqBody←⎕NS'' + reqBody.name←'requestBody' + reqBody.description←{6::'' ⋄ ⍵.description}cmdObj.requestBody + reqBody.schema←schema ResolveRef cmdObj.requestBody.content + :EndIf + args←∊((hasParameters hasSharedParams)/cmdObj cmdObj.##).parameters,reqBody + f,←⊂'⍝ args: mv, parameters, vector of shape ',⍕(≢args) + f,←1↓¨↓⍕↑(⍕¨⍳≢args){ + paramschema←schema ResolveRef ⍵ + aplType←('integer' 'string' 'boolean' 'array' 'object'⍳⊂paramschema.type)⊃'ns' 'cv' 'bs' 'mv' 'obj' 'obj' + desc←{6::'' ⋄ ',',⍵.description~⎕UCS 10 13}⍵ + ('⍝ ',⍺,'⊃args:')(aplType,',')⍵.name paramschema.type desc + }¨args + :EndIf + f,←⊂'r←clt execute ',(Quote command),' ∆schema args' + f,←⊂'' + r,←(⊂' '),¨(1⌽'∇ ' '∇ ',(¯2+≢f)⍴⊂' '),¨f + :If hasRequestBody + :If hasNestClass←0≠⎕NC'cmdObj.requestBody.content.⍙application⍙47⍙json.schema.properties' + classname←'RequestBodyClass' + lines←(depth+1)CompileObject toolsdir cmdObj.requestBody.content.⍙application⍙47⍙json.schema classname + classref←'''',classname,'''' + :Else + classref←'∆schema.requestBody.content' + :EndIf + r,←⊂'' + f←⍬ + f,←⊂'r←NewRequestBody' + f,←⊂':Access Public Shared' + f,←⊂'⍝ (Don''t modify, generated by ',(⊃⎕XSI),')' + f,←⊂'⍝ r: Returns a requestbody object.' + f,←{6::'' ⋄ (⊂'⍝ Description:'),CommentLines ⍵.description}cmdObj.requestBody + f,←⊂'r←commandRequestBody ',classref + f,←⊂'' + r,←(⊂' '),¨(1⌽'∇ ' '∇ ',(¯2+≢f)⍴⊂' '),¨f + :If hasNestClass + r,←(⊂''),(⊂' '),¨lines + :EndIf + :EndIf + r,←⊂'' + r,←⊂':EndClass ⍝ ',name diff --git a/APLSource/Core/CompilePaths.aplf b/APLSource/Core/CompilePaths.aplf index 2b4fb61..3c7ba1f 100644 --- a/APLSource/Core/CompilePaths.aplf +++ b/APLSource/Core/CompilePaths.aplf @@ -1,17 +1,24 @@ - CompilePaths(schema svcdir toolsdir);paths;pathsdir;baseUrl;pathObjs;pathUrls;names;name;pathUrl;pathObj;depth;lines + CompilePaths(schema svcdir toolsdir);paths;baseUrl;pathObjs;pathUrls;name;pathUrl;depth;lines;command;cmdObj;cmds;cmdMatrix;operationIds;cmd;pathObj;hasParameters ⍝Compile paths section of schema into APL classes →(0=schema.⎕NC'paths')/0 paths←schema.paths.⎕NL ¯9 →(0=≢paths)/0 - pathsdir←svcdir,'/paths/' - 3 ⎕MKDIR pathsdir baseUrl←{6::'' ⋄ ⊃⍵.servers.url}schema - (pathObjs pathUrls names)←⊂'' + (pathObjs pathUrls)←⊂'' pathObjs←schema.paths.⍎¨paths pathUrls←JsonConvertNames paths - names←GenerateNamesFromPath pathUrls - :For name pathUrl pathObj :InEach names pathUrls pathObjs - depth←2 - lines←depth CompileService pathObj name baseUrl pathUrl schema toolsdir - (⊂lines)⎕NPUT(pathsdir,name,'.aplc')1 + cmds←pathObjs.⎕NL ¯9 + cmdMatrix←⊃⍪/pathUrls{(⊂⍺),⍵}¨pathObjs{⍵,⍺,⍪⍺⍎¨⍵}¨cmds + operationIds←(,/cmdMatrix[;2 1]){0=⍵.⎕NC'operationId':⍺ ⋄ ⍵.operationId}¨cmdMatrix[;4] + cmdMatrix,←GenerateNamesFromPath operationIds + :For pathUrl cmd pathObj cmdObj name :In ↓cmdMatrix + hasParameters←0<(pathObj cmdObj).⎕NC⊂⊂'parameters' + :If >/hasParameters + cmdObj.parameters←pathObj.parameters + :ElseIf ∧/hasParameters + cmdObj.parameters,←pathObj.parameters + :EndIf + depth←1 + lines←depth CompileOperation cmd cmdObj name baseUrl pathUrl schema toolsdir + (⊂lines)⎕NPUT(svcdir,'/',name,'.aplc')1 :EndFor diff --git a/APLSource/Core/CompileService.aplf b/APLSource/Core/CompileService.aplf deleted file mode 100644 index 41e2e14..0000000 --- a/APLSource/Core/CompileService.aplf +++ /dev/null @@ -1,76 +0,0 @@ - r←depth CompileService(obj name baseurl path schema toolsdir);commands;cmdObj;command;reqBody;args;f;hasRequestBody;hasParameters;hasSharedParams;classname;classref;lines;hasNestClass;toolspath - r←⍬ - r,←⊂':Class ',name - toolspath←(∊depth/⊂'##.'),toolsdir - r,←⊂':Include ',toolspath - r,←⊂'' - r,←⊂' (⎕IO ⎕ML)←1' - r,←⊂'' - r,←⊂' :Field Private Shared ∆schema←⎕JSON ',Quote ⎕JSON obj - r,←⊂' :Field Private Shared ∆baseurl←',Quote baseurl - r,←⊂' :Field Private Shared ∆path←',Quote path - - commands←obj.⎕NL ¯9 - hasSharedParams←⊃0≠obj.⎕NC'parameters' - :For command :In commands - cmdObj←obj.⍎command - (hasRequestBody hasParameters)←0≠cmdObj.⎕NC'requestBody' 'parameters' - r,←⊂'' - f←⍬ - f,←⊂'r←clt ',({(1 ⎕C⊃⍵),1↓⍵}command),' args' - f,←⊂':Access Public Shared' - f,←⊂'⍝ (Don''t modify, generated by ',(⊃⎕XSI),')' - f,←{6::'' ⋄ (⊂'⍝ Summary:'),CommentLines ⍵.summary}cmdObj - f,←{6::'' ⋄ (⊂'⍝ Description:'),CommentLines ⍵.description}cmdObj - f,←⊂'⍝ clt: obj, HttpClient instance' - :If hasParameters⍱hasSharedParams - :If hasRequestBody - f,←(⊂'⍝ args: obj, Request body'),{6::'' ⋄ CommentLines ⍵.description}cmdObj.requestBody - :Else - f,←⊂'⍝ args: bs, dummy' - :EndIf - :Else - reqBody←⍬ - :If hasRequestBody - reqBody←⎕NS'' - reqBody.name←'requestBody' - reqBody.description←{6::'' ⋄ ⍵.description}cmdObj.requestBody - reqBody.schema←schema ResolveRef cmdObj.requestBody.content - :EndIf - args←∊((hasParameters hasSharedParams)/cmdObj obj).parameters,reqBody - f,←⊂'⍝ args: mv, parameters, vector of shape ',⍕(≢args) - f,←1↓¨↓⍕↑(⍕¨⍳≢args){ - paramschema←schema ResolveRef ⍵ - aplType←('integer' 'string' 'boolean' 'array' 'object'⍳⊂paramschema.type)⊃'ns' 'cv' 'bs' 'mv' 'obj' 'obj' - desc←{6::'' ⋄ ',',⍵.description~⎕UCS 10 13}⍵ - ('⍝ ',⍺,'⊃args:')(aplType,',')⍵.name paramschema.type desc - }¨args - :EndIf - f,←⊂'r←clt execute ',(Quote command),' ∆schema.',command,' args' - f,←⊂'' - r,←(⊂' '),¨(1⌽'∇ ' '∇ ',(¯2+≢f)⍴⊂' '),¨f - :If hasRequestBody - :If hasNestClass←0≠⎕NC'cmdObj.requestBody.content.⍙application⍙47⍙json.schema.properties' - classname←({(1 ⎕C⊃⍵),1↓⍵}command),'RequestBodyClass' - lines←(depth+1)CompileObject toolsdir cmdObj.requestBody.content.⍙application⍙47⍙json.schema classname - classref←'''',classname,'''' - :Else - classref←'∆schema.',command,'.requestBody.content' - :EndIf - r,←⊂'' - f←⍬ - f,←⊂'r←New',({(1 ⎕C⊃⍵),1↓⍵}command),'RequestBody' - f,←⊂':Access Public Shared' - f,←⊂'⍝ (Don''t modify, generated by ',(⊃⎕XSI),')' - f,←⊂'⍝ r: Returns a requestbody object.' - f,←{6::'' ⋄ (⊂'⍝ Description:'),CommentLines ⍵.description}cmdObj.requestBody - f,←⊂'r←commandRequestBody ',classref - f,←⊂'' - r,←(⊂' '),¨(1⌽'∇ ' '∇ ',(¯2+≢f)⍴⊂' '),¨f - :If hasNestClass - r,←(⊂''),(⊂' '),¨lines - :EndIf - :EndIf - :EndFor - r,←⊂'' - r,←⊂':EndClass ⍝ ',name diff --git a/APLSource/Core/GenerateNamesFromPath.aplf b/APLSource/Core/GenerateNamesFromPath.aplf index a0a528e..c139ccc 100644 --- a/APLSource/Core/GenerateNamesFromPath.aplf +++ b/APLSource/Core/GenerateNamesFromPath.aplf @@ -3,7 +3,8 @@ string←'''(?:[^\r\n'']|'''')*''' pattern←'(\((?:',string,'|[^()'']|(?1))*\))' ⍝ group: (nested)parens - names←'^_?.'⎕R'\u0'⊢'^/'pattern'((/{\w+})+)' '[^A-Za-zÀ-ÖØ-Ýß-öø-üþ∆⍙Ⓐ-Ⓩ0-9]'⎕R'' 'Key' 'Key' '_'⊢⊆paths + names←'^/'pattern'/(\w)(\w*)' '[^A-Za-zÀ-ÖØ-Ýß-öø-üþ∆⍙Ⓐ-Ⓩ0-9]'⎕R'' 'Key' '\u1\2' '_'⊢⊆paths~¨⊂'{}' + names←'^_?.' '_(.)'⎕R'\u0' '\u1'⊢names ⍝ PascalCase names←{⊆⊢/⍵⌷⍨⊂⍋⍵}⊃⍪/{1=≢⍵:⊂⍵,⍪⍺ ⋄ ⊂⍵,⍪⍺,¨'_',∘⍕¨⍳≢⍵}⌸names ⍝ add nr suffix for duplicates r←names ⍝ diff --git a/APLSource/Core/Tools/execute.aplf b/APLSource/Core/Tools/execute.aplf index 604e389..c757d4f 100644 --- a/APLSource/Core/Tools/execute.aplf +++ b/APLSource/Core/Tools/execute.aplf @@ -1,20 +1,18 @@ -r←clt execute(command cmdObj args);qp;qpmask;urlmask;mask;res;paramscnt;paramnames;hasParams;hasReqBody;in;rc;resp;csrf;etag;payload;hasSharedParams;paramobjs;msg;explode;vals +r←clt execute(command cmdObj args);qp;qpmask;urlmask;mask;res;paramscnt;paramnames;hasParams;hasReqBody;in;rc;resp;csrf;etag;payload;msg;explode;vals ⍝clt: obj, HttpClient instance clt.Command←command clt.BaseURL{0=≢⍺:⍵ ⋄ ⍺}←∆baseurl clt.URL←∆path clt.Params←'' - hasSharedParams←⊃0≠cmdObj.##.⎕NC'parameters' hasParams hasReqBody←0≠cmdObj.⎕NC'parameters' 'requestBody' - :If (hasParams∨hasSharedParams)