Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: WEOS-1382 As a developer I should be able to set the type of id that I want auto generated #140

Merged
merged 32 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4ca68b3
feature: WEOS-1382 Auto generate id
akeemphilbert Mar 4, 2022
0ab931f
feature: WEOS-1382 Auto generate id
akeemphilbert Mar 4, 2022
46a5eb1
Merge branch 'feature/WEOS-1382' into WEOS-1392
shaniah868 Mar 7, 2022
ab7a1f6
feature: WEOS-1392 Generate and ensure bdd test passes
shaniah868 Mar 7, 2022
b294eba
feature: WEOS-1382 As a developer I should be able to set the type of…
shaniah868 Mar 9, 2022
a92575c
Merge branch 'WEOS-1391' into WEOS-1392
shaniah868 Mar 9, 2022
81e38b3
feature: WEOS-1382 As a developer I should be able to set the type of…
shaniah868 Mar 9, 2022
5295657
feature: WEOS-1382 As a developer I should be able to set the type of…
shaniah868 Mar 9, 2022
af4e8e1
doc: WEOS-1382 Update spec to make it that format needs to be specifi…
akeemphilbert Mar 9, 2022
627054a
Merge branch 'feature/WEOS-1382' into WEOS-1392
shaniah868 Mar 9, 2022
7c20720
feature: WEOS-1382 As a developer I should be able to set the type of…
shaniah868 Mar 9, 2022
89f6e71
feature: WEOS-1382 As a developer I should be able to set the type of…
shaniah868 Mar 9, 2022
901d16a
Merge branch 'WEOS-1391' into WEOS-1392
shaniah868 Mar 9, 2022
5ebe680
feature: WEOS-1382 As a developer I should be able to set the type of…
shaniah868 Mar 9, 2022
5e169e9
feature: WEOS-1382 As a developer I should be able to set the type of…
shaniah868 Mar 9, 2022
c374436
Merge pull request #138 from wepala/WEOS-1391
RandyDeo Mar 9, 2022
d67df67
Merge branch 'feature/WEOS-1382' into WEOS-1392
shaniah868 Mar 9, 2022
8fb13eb
Merge branch 'dev' into feature/WEOS-1382
shaniah868 Mar 9, 2022
d4b81d2
Merge branch 'feature/WEOS-1382' into WEOS-1392
shaniah868 Mar 9, 2022
8406285
Merge pull request #139 from wepala/WEOS-1392
RandyDeo Mar 9, 2022
0d919d8
doc: WEOS-1392 removed the erroneous bdd test step
akeemphilbert Mar 11, 2022
23f454f
feature: WEOS-1382 As a developer I should be able to set the type of…
shaniah868 Mar 11, 2022
5791590
Merge branch 'dev' into feature/WEOS-1382
shaniah868 Mar 11, 2022
83c5c63
feature: WEOS-1382 As a developer I should be able to set the type of…
shaniah868 Mar 11, 2022
9483996
feature: WEOS-1382 Auto generate id
akeemphilbert Mar 11, 2022
4515aaa
feature: WEOS-1382 Fixed a few more tests
akeemphilbert Mar 11, 2022
70c846c
Merge pull request #141 from wepala/feature/WEOS-1382-akeem
shaniah868 Mar 14, 2022
c836a62
feature: WEOS-1382 As a developer I should be able to set the type of…
shaniah868 Mar 14, 2022
5cec397
feature: WEOS-1382 As a developer I should be able to set the type of…
shaniah868 Mar 14, 2022
24aaa24
feature: WEOS-1382 As a developer I should be able to set the type of…
shaniah868 Mar 14, 2022
939ab8f
Merge branch 'dev' into feature/WEOS-1382
shaniah868 Mar 14, 2022
5da3f2b
Merge branch 'dev' into feature/WEOS-1382
shaniah868 Mar 16, 2022
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
5 changes: 2 additions & 3 deletions api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ components:
type: object
properties:
id:
type: string
format: ksuid
type: integer
format: uint
firstName:
type: string
lastName:
Expand All @@ -60,7 +60,6 @@ components:
- lastName
x-identifier:
- id
- email
Blog:
type: object
properties:
Expand Down
19 changes: 14 additions & 5 deletions controllers/rest/fixtures/blog-x-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ components:
Category:
type: object
properties:
title:
id:
type: string
format: uuid
description:
type: string
required:
- title
- id
x-identifier:
- title
- id
Author:
type: object
properties:
Expand All @@ -58,7 +59,6 @@ components:
- lastName
x-identifier:
- id
- email
Blog:
type: object
properties:
Expand Down Expand Up @@ -115,6 +115,15 @@ components:
created:
type: string
format: date-time
Archives:
type: object
properties:
id:
type: integer
title:
type: string
x-identifier:
- id
paths:
/health:
summary: Health Check
Expand Down Expand Up @@ -605,4 +614,4 @@ paths:
summary: Delete author
responses:
200:
description: Delete author
description: Delete author
17 changes: 14 additions & 3 deletions controllers/rest/middleware_initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func newSchema(ref *openapi3.Schema, logger echo.Logger) (ds.Builder, map[string
relations[name] = strings.TrimPrefix(p.Ref, "#/components/schemas/")
} else {
t := p.Value.Type
f := p.Value.Format
if strings.EqualFold(t, "array") {
t2 := p.Value.Items.Value.Type
if t2 != "object" {
Expand All @@ -133,7 +134,12 @@ func newSchema(ref *openapi3.Schema, logger echo.Logger) (ds.Builder, map[string
} else if t2 == "number" {
instance.AddField(name, []float64{}, tagString)
} else if t == "integer" {
instance.AddField(name, []int{}, tagString)
if f == "uint" {
instance.AddField(name, []uint{}, tagString)
} else {
instance.AddField(name, []int{}, tagString)
}

} else if t == "boolean" {
instance.AddField(name, []bool{}, tagString)
}
Expand Down Expand Up @@ -166,8 +172,13 @@ func newSchema(ref *openapi3.Schema, logger echo.Logger) (ds.Builder, map[string
var numbers *float32
defaultValue = numbers
case "integer":
var integers *int
defaultValue = integers
if f == "uint" {
defaultValue = uint(0)
} else {
var integers *int
defaultValue = integers
}

case "boolean":
var boolean *bool
defaultValue = boolean
Expand Down
52 changes: 39 additions & 13 deletions end2end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"github.com/google/uuid"
"github.com/segmentio/ksuid"
weosContext "github.com/wepala/weos/context"
"io"
"mime/multipart"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -72,6 +74,7 @@ var filters string
var enumErr error
var token string
var contextWithValues context.Context
var contentEntity map[string]interface{}

type FilterProperties struct {
Operator string
Expand Down Expand Up @@ -107,6 +110,7 @@ func InitializeSuite(ctx *godog.TestSuiteContext) {
page = 0
limit = 0
token = ""
contentEntity = map[string]interface{}{}
result = api.ListApiResponse{}
blogfixtures = []interface{}{}
total, success, failed = 0, 0, 0
Expand Down Expand Up @@ -164,6 +168,7 @@ func reset(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
token = ""
result = api.ListApiResponse{}
errs = nil
contentEntity = map[string]interface{}{}
header = make(http.Header)
rec = httptest.NewRecorder()
resp = nil
Expand Down Expand Up @@ -460,6 +465,8 @@ func theIsCreated(contentType string, details *godog.Table) error {
if rec.Result().StatusCode != http.StatusCreated {
return fmt.Errorf("expected the status code to be '%d', got '%d'", http.StatusCreated, rec.Result().StatusCode)
}
etag := rec.Header().Get("Etag")
weosID, _ := api.SplitEtag(etag)

head := details.Rows[0].Cells
compare := map[string]interface{}{}
Expand All @@ -470,26 +477,23 @@ func theIsCreated(contentType string, details *godog.Table) error {
}
}

contentEntity := map[string]interface{}{}
var result *gorm.DB
//ETag would help with this
for key, value := range compare {
result = gormDB.Table(strings.Title(contentType)).Find(&contentEntity, key+" = ?", value)
if contentEntity != nil {
break
}
}

contentEntity = map[string]interface{}{}
var resultdb *gorm.DB
resultdb = gormDB.Table(strings.Title(contentType)).Find(&contentEntity, "weos_id = ?", weosID)
if contentEntity == nil {
return fmt.Errorf("unexpected error finding content type in db")
}

if result.Error != nil {
return fmt.Errorf("unexpected error finding content type: %s", result.Error)
if resultdb.Error != nil {
return fmt.Errorf("unexpected error finding content type: %s", resultdb.Error)
}

for key, value := range compare {
if contentEntity[key] != value {
v, ok := value.(string)
if ok && v == "<Generated>" && contentEntity[key] != nil {
continue
}
return fmt.Errorf("expected %s %s %s, got %s", contentType, key, value, contentEntity[key])
}
}
Expand Down Expand Up @@ -1588,6 +1592,27 @@ func thereShouldBeAKeyInTheRequestContextWithValue(key, value string) error {
return nil
}

func theIdShouldBeA(arg1, format string) error {
switch format {
case "uuid":
_, err := uuid.Parse(contentEntity["id"].(string))
if err != nil {
fmt.Errorf("unexpected error parsing id as uuid: %s", err)
}
case "integer":
_, ok := contentEntity["id"].(int)
if !ok {
fmt.Errorf("unexpected error parsing id as int")
}
case "ksuid":
_, err := ksuid.Parse(contentEntity["id"].(string))
if err != nil {
fmt.Errorf("unexpected error parsing id as ksuid: %s", err)
}
}
return nil
}

func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Before(reset)
ctx.After(func(ctx context.Context, sc *godog.Scenario, err error) (context.Context, error) {
Expand Down Expand Up @@ -1680,6 +1705,7 @@ func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^the response body should be$`, theResponseBodyShouldBe)
ctx.Step(`^there should be a key "([^"]*)" in the request context with object$`, thereShouldBeAKeyInTheRequestContextWithObject)
ctx.Step(`^there should be a key "([^"]*)" in the request context with value "([^"]*)"$`, thereShouldBeAKeyInTheRequestContextWithValue)
ctx.Step(`^the "([^"]*)" id should be a "([^"]*)"$`, theIdShouldBeA)

}

Expand Down
Loading