Skip to content

Commit

Permalink
- patched e2e test cases
Browse files Browse the repository at this point in the history
- removing Style logic
  • Loading branch information
adranwit committed Nov 11, 2024
1 parent 6a1c64e commit 6ad1765
Show file tree
Hide file tree
Showing 18 changed files with 73 additions and 56 deletions.
3 changes: 3 additions & 0 deletions cmd/command/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ func (s *Service) generate(ctx context.Context, options *options.Options) error
template.BuildInput(spec, resource.State, opts...)

registry := resource.Resource.TypeRegistry()

if parameters := resource.OutputState.FilterByKind(state.KindRequestBody); len(parameters) >= 1 {
parameters[0].Tag += ` typeName:"` + template.Prefix + `"`
cardinality := parameters[0].Schema.Cardinality
parameters[0].Schema = state.NewSchema(template.BodyType)
parameters[0].Schema.Cardinality = cardinality
template.BodyParameter = parameters[0]
}

Expand Down
12 changes: 5 additions & 7 deletions e2e/debug_gen/datly.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ type Gen struct {
func main() {

/*
-N=run_tests_uri_param -X=/Users/awitas/go/src/github.com/viant/datly/e2e/local/regression/cases/002_uri_param/vendor_details.sql
-w=autogen -C='dev|mysql|root:dev@tcp(127.0.0.1:3306)/dev?parseTime=true' -C='dyndb|dynamodb|dynamodb://localhost:8000/us-west-1?key=dummy&secret=dummy' -j='/Users/awitas/go/src/github.com/viant/datly/e2e/local/jwt/public.enc|blowfish://default' -m='/Users/awitas/go/src/github.com/viant/datly/e2e/local/jwt/hmac.enc|blowfish://default'
--partialConfig='/Users/awitas/go/src/github.com/viant/datly/e2e/local/regression/partial_config.json'
*/
019_generate_post_comprehensive_many/post_comprehensive_many.sql */

baseDir := filepath.Join(toolbox.CallerDirectory(3), "..")
fmt.Printf("base: %v\n", baseDir)
caseName := "001_one_to_many"
caseName := "019_generate_post_comprehensive_many"
caseFolder := filepath.Join(baseDir, "local/regression/cases/", caseName)
gen, err := loadGen(caseFolder, caseName)
if err != nil {
Expand All @@ -79,9 +77,9 @@ func main() {
"-N=" + gen.Name,
"-X=" + gen.URL,
"-C=dev|mysql|root:dev@tcp(127.0.0.1:3306)/dev?parseTime=true",
// "-G=post",
"-G=post",
"-C=dyndb|dynamodb|dynamodb://localhost:8000/us-west-1?key=dummy&secret=dummy",
fmt.Sprintf("-j='%v/local/jwt/public.enc|blowfish://default'", baseDir),
// fmt.Sprintf("-j='%v/local/jwt/public.enc|blowfish://default'", baseDir),
"-w=autogen",
}

Expand Down
7 changes: 3 additions & 4 deletions e2e/local/regression/cases/009_apikey/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pipeline:
Expect:
Code: 200

test2:
action: http/runner:send
requests:
- Method: GET
URL: http://127.0.0.1:8080/v1/api/meta/openapi/dev/secured/vendors/2
Expect:
Expand All @@ -42,7 +45,3 @@ pipeline:
Expect:
Code: 200

# - Method: POST
# URL: http://127.0.0.1:8080/v1/api/cache/warmup/dev/secured/vendors/2
# Expect:
# Code: 403
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@


#set($_ = $Events<?>(body/Data).Cardinality('Many'))

#set($_ = $Status<?>(output/status).Tag('anonymous:"true"'))
#set($_ = $Data<?>(state/Events).Output())
#set($_ = $Data<?>(body/Data).Output())


SELECT events.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* {"URI": "basic/events-except", "Method": "POST",
"ResponseBody": {
"From": "Events"
}
} */
/* {"URI": "basic/events-except", "Method": "POST" } */

SELECT events.* EXCEPT NAME /* { "Cardinality": "One" } */
#set($_ = $Events<?>(body/).Cardinality('One').Tag('anonymous:"true"'))
#set($_ = $Events<?>(body/).Output().Tag('anonymous:"true"'))



SELECT events.* EXCEPT NAME
FROM (SELECT * FROM EVENTS) events
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* {"URI": "basic/events-explicit", "Method": "POST",
"ResponseBody": {
"From": "Events"
}
} */
/* {"URI": "basic/events-explicit", "Method": "POST" } */

SELECT events.* /* { "Cardinality": "One" } */
#set($_ = $Events<?>(body/).Cardinality('One').Tag('anonymous:"true"'))
#set($_ = $Events<?>(body/).Output().Tag('anonymous:"true"'))


SELECT events.*
FROM (SELECT ID, QUANTITY FROM EVENTS) events
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* {"URI": "basic/events-one-one", "Method": "POST",
"ResponseBody": {
"From": "Events"
}
} */

SELECT EVENTS.* /* { "Cardinality": "One" } */,
EVENTS_PERFORMANCE.* /* { "Cardinality": "One" } */
/* {"URI": "basic/events-one-one", "Method": "POST" } */


#set($_ = $Events<?>(body/).Cardinality('One').Tag('anonymous:"true"'))
#set($_ = $Events<?>(body/).Output().Tag('anonymous:"true"'))


SELECT EVENTS.*,
EVENTS_PERFORMANCE.*
FROM (SELECT ID, QUANTITY FROM EVENTS) EVENTS
JOIN (SELECT * FROM EVENTS_PERFORMANCE) EVENTS_PERFORMANCE ON EVENTS.ID = EVENTS_PERFORMANCE.EVENT_ID
JOIN (SELECT * FROM EVENTS_PERFORMANCE) EVENTS_PERFORMANCE ON EVENTS.ID = EVENTS_PERFORMANCE.EVENT_ID AND 1=1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* {"URI": "basic/events-one-many", "Method": "POST",
"ResponseBody": {
"From": "Events"
}
} */
/* {"URI": "basic/events-one-many", "Method": "POST" } */

SELECT EVENTS.* /* { "Cardinality": "One" } */,
#set($_ = $Events<?>(body/).Cardinality('One').Tag('anonymous:"true"'))
#set($_ = $Events<?>(body/).Output().Tag('anonymous:"true"'))


SELECT EVENTS.*,
EVENTS_PERFORMANCE.*
FROM (SELECT ID, QUANTITY FROM EVENTS) EVENTS
JOIN (SELECT * FROM EVENTS_PERFORMANCE) EVENTS_PERFORMANCE ON EVENTS.ID = EVENTS_PERFORMANCE.EVENT_ID
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* {
"URI":"basic/events-validator",
"Method":"POST",
"ResponseBody": {"From": "Events" }
"Method":"POST"
} */

import (
Expand All @@ -10,6 +9,8 @@ import (


#set($_ = $Events<*Events>(body/))
#set($_ = $Events<*Events>(body/).Output().Tag('anonymous:"true"'))

#set($_ = $EventTypes<?>(param/Events) /*
SELECT Price, Timestamp FROM `/EventsPerformance`
*/)
Expand Down Expand Up @@ -47,5 +48,5 @@ INSERT INTO EVENTS (
$recEventsPerformance.EventId,
$recEventsPerformance.Timestamp
);

#end
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import(
)

#set($_ = $Events<*Events>(body/))
#set($_ = $Events<*Events>(body/).Output().Tag('anonymous:"true"'))

$sequencer.Allocate("EVENTS", $Events, "Id")
$sequencer.Allocate("EVENTS_PERFORMANCE", $Events, "EventsPerformance/Id")

Expand Down Expand Up @@ -41,5 +43,5 @@ INSERT INTO EVENTS (
$recEventsPerformance.EventId,
$recEventsPerformance.Timestamp
);

#end
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
"TypeSrc":{
"URL":"regression/cases/026_transform_service",
"Types":["PerformanceData", "Events"]
},
"ResponseBody": { "From": "Events" }
}
} */

#set($_ = $Events<*Events>(body/))
#set($_ = $Events<*Events>(body/).Output().Tag('anonymous:"true"'))


$sequencer.Allocate("EVENTS", $Events, "Id")
$sequencer.Allocate("EVENTS_PERFORMANCE", $Events, "EventsPerformance/Id")
Expand Down Expand Up @@ -40,5 +42,5 @@ INSERT INTO EVENTS (
$recEventsPerformance.EventId,
$recEventsPerformance.Timestamp
);

#end
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/* {
"URI": "basic/foos", "Method": "PUT", "ResponseBody": {
"From": "Foos"
}
"URI": "basic/foos", "Method": "PUT"
} */

SELECT foos.* /* { "Cardinality": "One" } */

#set($_ = $Foos<?>(body/).Cardinality('One').Tag('anonymous:"true"'))
#set($_ = $Foos<?>(body/).Output().Tag('anonymous:"true"'))


SELECT foos.*
FROM (SELECT * FROM FOOS) foos
2 changes: 1 addition & 1 deletion e2e/local/regression/regression.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pipeline:
'[]gen': '@gen'

subPath: 'cases/${index}_*'
range: 19..019
range: 1..027
template:
checkSkip:
action: nop
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1083,8 +1083,6 @@ github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
github.com/tklauser/go-sysconf v0.3.9/go.mod h1:11DU/5sG7UexIrp/O6g35hrWzu0JxlwQ3LSFUzyeuhs=
github.com/tklauser/numcpus v0.3.0/go.mod h1:yFGUr7TUHQRAhyqBcEg0Ge34zDBAsIvJJcyE6boqnA8=
github.com/viant/aerospike v0.2.11-0.20241107183843-7b13b008c51c h1:0cnMouTRlyHVxaPRWSGkkkW5KWrcHkNXoEScOgH64Ls=
github.com/viant/aerospike v0.2.11-0.20241107183843-7b13b008c51c/go.mod h1:eRBywl0oTDM/oGhGLUeJjnC7XzmkTGuW9/og5YFy0K0=
github.com/viant/aerospike v0.2.11-0.20241108195857-ed524b97800d h1:IRmoMmrWqkHDBy0tk9mbHRDK7+ynn0Gzwl+9WIiAtNs=
github.com/viant/aerospike v0.2.11-0.20241108195857-ed524b97800d/go.mod h1:eRBywl0oTDM/oGhGLUeJjnC7XzmkTGuW9/og5YFy0K0=
github.com/viant/afs v1.25.1-0.20231110184132-877ed98abca1 h1:q83rO9rKNCsT/W9x9EBmCVt24yjFDRmhslLhaL4h7DE=
Expand Down
4 changes: 4 additions & 0 deletions internal/inference/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,10 @@ func (s *State) BodyParameter() *Parameter {
return candidate
}
}

if len(dataFields) == 1 {
return dataFields[0]
}
var fields = []reflect.StructField{}
for _, dataField := range dataFields {
fields = append(fields, reflect.StructField{Name: dataField.In.Name, Type: dataField.Schema.Type(), Tag: reflect.StructTag(dataField.Tag)})
Expand Down
5 changes: 5 additions & 0 deletions internal/translator/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func (s *Service) updateExplicitInputType(resource *Resource, viewlet *Viewlet)
}
registry := resource.typeRegistry
inputState := inference.State{}
rootViewlet := resource.Rule.RootViewlet()

for i, item := range resource.State {
s.updatedNamedType(&item.Parameter, registry)
if strings.Contains(item.Name, ".") {
Expand All @@ -27,6 +29,9 @@ func (s *Service) updateExplicitInputType(resource *Resource, viewlet *Viewlet)
return err
}
inputState.Append(resource.State[i])
if item.In.Kind == state.KindRequestBody {
item.Schema.SetType(rootViewlet.View.Schema.Type())
}
}

inputState.Append(resource.AsyncState...)
Expand Down
4 changes: 2 additions & 2 deletions internal/translator/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ func (s *Service) updateOutputFieldTypes(resource *Resource) {
case state.KindMeta:
contract.UpdateParameterMetaType(&parameter.Parameter)
case state.KindRequestBody:
if baseParameter := resource.State.FilterByKind(state.KindRequestBody); len(baseParameter) > 0 {
if baseParameter[0].In.Name == "" {
if baseParameter := resource.State.FilterByKind(state.KindRequestBody); len(baseParameter) == 1 {
if baseParameter[0].In.Name == parameter.In.Name {
parameter.Schema = baseParameter[0].Schema.Clone()
}
}
Expand Down
1 change: 1 addition & 0 deletions internal/translator/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ func (s *Service) translateReaderDSQL(ctx context.Context, resource *Resource, d
return err
}
s.detectComponentViewType(componentColumns, resource)

if err = s.updateOutputParameters(resource, rootViewlet); err != nil {
return err
}
Expand Down

0 comments on commit 6ad1765

Please sign in to comment.