Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion APLSource/Core/CompileObject.aplf
Original file line number Diff line number Diff line change
@@ -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,←⊂''
Expand Down
74 changes: 74 additions & 0 deletions APLSource/Core/CompileOperation.aplf
Original file line number Diff line number Diff line change
@@ -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
25 changes: 16 additions & 9 deletions APLSource/Core/CompilePaths.aplf
Original file line number Diff line number Diff line change
@@ -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
76 changes: 0 additions & 76 deletions APLSource/Core/CompileService.aplf

This file was deleted.

3 changes: 2 additions & 1 deletion APLSource/Core/GenerateNamesFromPath.aplf
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 7 additions & 9 deletions APLSource/Core/Tools/execute.aplf
Original file line number Diff line number Diff line change
@@ -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)<hasReqBody
:If hasParams<hasReqBody
clt.Params←checkPayload args
:ElseIf hasParams∨hasSharedParams
paramobjs←∊(hasParams hasSharedParams/cmdObj cmdObj.##).parameters
paramscnt←hasReqBody+≢paramobjs
:ElseIf hasParams
paramscnt←hasReqBody+≢cmdObj.parameters
qp←paramscnt↑args,paramscnt⍴⊂''
paramnames←paramobjs.name,hasReqBody/⊂'requestBody'
in←paramobjs.in,hasReqBody/⊂'body'
explode←({0::1 ⋄ ⍵.explode≢⊂'false'}¨paramobjs),hasReqBody/1
paramnames←cmdObj.parameters.name,hasReqBody/⊂'requestBody'
in←cmdObj.parameters.in,hasReqBody/⊂'body'
explode←({0::1 ⋄ ⍵.explode≢⊂'false'}¨cmdObj.parameters),hasReqBody/1
qpmask←in∊⊂'query'
urlmask←in∊⊂'path'
:If ∨/urlmask
Expand Down
8 changes: 3 additions & 5 deletions APLSource/Core/Tools/getComponent.aplf
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
r←getComponent content;comppath;ref;root
r←getComponent content;comppath;ref
ref←{
2=⍵.⎕NC'⍙⍙36⍙ref':⍵.⍙⍙36⍙ref
⍵.(⍎⊃⎕NL ¯9).schema.⍙⍙36⍙ref
}content
comppath←translatePath ref
:If '#.'≡2↑comppath
root←⊃'^(.+\.)(?:components|paths)'⎕S'\1'⊢⍕(⊃⊃⎕CLASS ⎕THIS)
:AndIf 0≠≢root
r←⍎root,2↓comppath
:If '#.components'(⊃⍷)comppath
r←⍎'∆',2↓comppath
:EndIf

2 changes: 1 addition & 1 deletion APLSource/Tests/UnitTests/ClassConstructor_test.aplf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
classfolder←TestClasses.PetstoreExpanded
⍝ Can the constructors be called without errors.
(0 Try ⎕NEW)¨classfolder.components.schemas.(⍎¨⎕NL ¯9)
(0 Try ⎕NEW)¨classfolder.paths.(⍎¨⎕NL ¯9)
(0 Try ⎕NEW)¨classfolder.(⍎¨⎕NL ¯9.4)
2 changes: 1 addition & 1 deletion APLSource/Tests/UnitTests/Compile_test.aplf
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
⍝ Test if all components and paths were compiled into classes
schema←⎕JSON⊃⎕NGET openapidir,'/','petstore-expanded.json'
Assert(≢TestClasses.PetstoreExpanded.components.schemas.⎕NL ¯9.4)=≢schema.components.schemas.⎕NL ¯9
Assert(≢TestClasses.PetstoreExpanded.paths.⎕NL ¯9)=≢schema.paths.⎕NL ¯9
Assert(≢TestClasses.PetstoreExpanded.⎕NL ¯9.4)=+/schema.paths.(⍎¨⎕NL ¯9).(≢⎕NL ¯9)
6 changes: 3 additions & 3 deletions APLSource/Tests/UnitTests/RequestBody_nstobj_test.aplf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RequestBody_nstobj_test;inst;rqb
inst←⎕NEW TestClasses.TestODA.paths.Nestrqbody
rqb←inst.NewPostRequestBody
Assert #.Papi.Tests.UnitTests.TestClasses.TestODA.paths.Nestrqbody.PostRequestBodyClass.objectClass≡rqb.object.(⊃⊃⎕CLASS ⎕THIS)
inst←⎕NEW TestClasses.TestODA.CreateNestrqbody
rqb←inst.NewRequestBody
Assert #.Papi.Tests.UnitTests.TestClasses.TestODA.CreateNestrqbody.RequestBodyClass.objectClass≡rqb.object.(⊃⊃⎕CLASS ⎕THIS)
Assert∧/'description' 'name' 'summary'∊rqb.object.⎕NL ¯2
20 changes: 9 additions & 11 deletions APLSource/Tests/UnitTests/commandRequestBody_test.aplf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
commandRequestBody_test;oaddir;schemaFiles;schemaFile;nsname;schema;count_reqbods;count_functions;namespaces;ns;endpoints;ep;inst;reqbody;compinst;funcs
commandRequestBody_test;oaddir;schemaFiles;schemaFile;nsname;schema;count_reqbods;count_functions;namespaces;ns;endpoints;ep;reqbody;compinst;funcs

⍝ Compare count of request bodies in OAD with count of functions to get a request body in generated classes.
oaddir←'./Testdata'
Expand All @@ -7,15 +7,15 @@
nsname←'-(.)'⎕R'\u1'⊢'-',2⊃⎕NPARTS schemaFile
schema←⎕JSON⊃⎕NGET schemaFile
count_reqbods←+⌿∊{6::0 ⋄ ⍵.paths.(⍎¨⎕NL ¯9).(⍎¨⎕NL ¯9).(0≠⎕NC'requestBody')}schema
count_functions←+⌿{6::0 ⋄ ⍵.paths.(⍎¨⎕NL ¯9).(≢'RequestBody$'⎕S'%'⊢⎕NL ¯3)}TestClasses⍎nsname
count_functions←+⌿{6::0 ⋄ ⍵.(⍎¨⎕NL ¯9.4).(≢'RequestBody$'⎕S'%'⊢⎕NL ¯3)}TestClasses⍎nsname
Assert count_reqbods=count_functions
:EndFor

⍝ Can the commandRequestBody functions be called for each endpoint without crashing.
namespaces←TestClasses.(⍎¨⎕NL ¯9)
namespaces/⍨←namespaces.(⊃9=⎕NC'paths')
namespaces/⍨←namespaces.(0<≢⎕NL ¯9.4)
:For ns :In namespaces
endpoints←{0≠≢ep←⍵.paths.(⎕NL ¯9):⍎¨(⊂'⍵.paths.'),¨ep ⋄ ⍬}ns
endpoints←{0≠≢ep←⍵.(⎕NL ¯9.4):⍎¨(⊂'⍵.'),¨ep ⋄ ⍬}ns
:For ep :In endpoints
:If 0<≢funcs←ep.('RequestBody$'⎕S'%'⊢⎕NL ¯3)
inst←⎕NEW ep
Expand All @@ -25,13 +25,11 @@
:EndFor

⍝ Request body with ref
inst←⎕NEW TestClasses.PetstoreExpanded.paths.Pets
reqbody←inst.NewPostRequestBody
reqbody←TestClasses.PetstoreExpanded.AddPet.NewRequestBody
compinst←⎕NEW TestClasses.PetstoreExpanded.components.schemas.NewPet
Assert compinst.(⊃⊃⎕CLASS ⎕THIS)≡reqbody.(⊃⊃⊃⎕CLASS ⎕THIS)
Assert (⎕CLASS compinst)≡(⎕CLASS reqbody)

⍝ Request body with properties
inst←⎕NEW TestClasses.Reqres.paths.Login
reqbody←inst.NewPostRequestBody
compinst←⎕NEW TestClasses.Reqres.paths.Login.PostRequestBodyClass
Assert compinst.(⊃⊃⎕CLASS ⎕THIS)≡reqbody.(⊃⊃⊃⎕CLASS ⎕THIS)
reqbody←TestClasses.Reqres.PostLogin.NewRequestBody
compinst←⎕NEW TestClasses.Reqres.PostLogin.RequestBodyClass
Assert (⎕CLASS compinst)≡(⎕CLASS reqbody)
12 changes: 6 additions & 6 deletions APLSource/Tests/UnitTests/execute_paramplusrqb_test.aplf
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
execute_paramplusrqb_test;hc;inst;rqb;name
execute_paramplusrqb_test;hc;rqb;name;inst

⍝ Post request with two in query parms and a request body
hc←HttpCommand.New''
inst←⎕NEW TestClasses.TestODA.paths.Thing
rqb←inst.NewPostRequestBody
inst←TestClasses.TestODA.AddThing
rqb←inst.NewRequestBody
rqb.name←name←'New'
hc(0 Try inst.Post)'id7' 'Aname'rqb
hc(0 Try inst.Run)'id7' 'Aname'rqb
Assert∨/'/thing?homeId=id7&name=Aname'⍷hc.Show
Assert name≡hc.Params.name

⍝ Get request with one in query parm and no req body
hc←HttpCommand.New''
inst←⎕NEW TestClasses.TestODA.paths.AnotherthingKey
hc(0 Try inst.Get)3
inst←TestClasses.TestODA.FindAnotherthingById
hc(0 Try inst.Run)3
Assert∨/'/anotherthing/?limit=3'⍷hc.Show