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

Sprint 22 #131

Merged
merged 144 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
144 commits
Select commit Hold shift + click to select a range
04134ef
docs: WEOS-1343 Start working on security schema spec
akeemphilbert Feb 8, 2022
87a9af3
docs: WEOS-1343 Continued work on security schema open id connect spec
akeemphilbert Feb 8, 2022
30b2fcb
docs: WEOS-1343 Continued work on security schema open id connect spec
akeemphilbert Feb 8, 2022
1a5b302
Merge branch 'feature/WEOS-1343' of github.com:wepala/weos into featu…
shaniah868 Feb 14, 2022
387bece
feature: WEOS-1343 Create middleware for handling JWT in the incoming…
shaniah868 Feb 15, 2022
1622a9d
feature:WEOS-1116
RandyDeo Feb 15, 2022
d8a0af9
feature: WEOS-1343 Create middleware for handling JWT in the incoming…
shaniah868 Feb 15, 2022
f7a756d
feature/WEOS-1247 - Add get api bdd test
atoniaw Feb 15, 2022
f042c72
feature: WEOS-1349 Rough Implementation of oidc lib
akeemphilbert Feb 15, 2022
9509938
feature/WEOS-1247 set expected response content type in context
atoniaw Feb 16, 2022
52165ef
feature/WEOS-1247 set expected response content type in context
atoniaw Feb 16, 2022
bca49c5
feature/WEOS-1247 set expected response content type in context
atoniaw Feb 16, 2022
e62d342
feature:WEOS-1116
RandyDeo Feb 16, 2022
88c536b
Merge pull request #98 from wepala/WEOS-1247
shaniah868 Feb 16, 2022
da17a9b
feature/WEOS-1249 added functionality for viewin swagger ui
atoniaw Feb 16, 2022
7d2c634
feature/WEOS-1249 regenerated swaggerui file
atoniaw Feb 16, 2022
82063c9
feature: WEOS-1343 Create middleware for handling JWT in the incoming…
shaniah868 Feb 16, 2022
190eaa3
feature: WEOS-1343 Create an operation initializer for setting middle…
shaniah868 Feb 16, 2022
0b2c18f
feature: WEOS-1343 Create an operation initializer for setting middle…
shaniah868 Feb 16, 2022
6202269
feature: WEOS-1343 Create an operation initializer for setting middle…
shaniah868 Feb 17, 2022
a5d1ed9
feature: WEOS-1343 Create an operation initializer for setting middle…
shaniah868 Feb 17, 2022
4708e5d
feature/WEOS-1249 added static binary for returning swagger ui
atoniaw Feb 17, 2022
6bc3d91
Merge pull request #99 from wepala/WEOS-1349
atoniaw Feb 17, 2022
d14f4ed
Merge branch 'dev' into feature/WEOS-1343
shaniah868 Feb 17, 2022
e1e4085
Merge branch 'feature/WEOS-1343' of github.com:wepala/weos into featu…
shaniah868 Feb 17, 2022
c378e08
Merge branch 'feature/WEOS-1343' into WEOS-1351
shaniah868 Feb 17, 2022
1f08655
feature: WEOS-1343 Create a global initializer for setting the middle…
shaniah868 Feb 17, 2022
69d783f
WEOS-1249 finalized bdd test
atoniaw Feb 17, 2022
c306977
feature:WEOS-1116
RandyDeo Feb 17, 2022
247367f
Merge remote-tracking branch 'origin/dev' into WEOS-1249
atoniaw Feb 17, 2022
3ceec72
Merge branch 'dev' into feature/WEOS-1116
RandyDeo Feb 17, 2022
0da6bdc
feature:WEOS-1116
RandyDeo Feb 17, 2022
00a9b7b
Merge branch 'feature/WEOS-1116' into WEOS-1276
RandyDeo Feb 17, 2022
72d0532
Merge remote-tracking branch 'origin/dev' into feature/WEOS-1127
atoniaw Feb 17, 2022
74142d8
Merge branch 'feature/WEOS-1127' into WEOS-1249
atoniaw Feb 17, 2022
14362fa
feature: WEOS-1343 Generate and Ensure BDD Test is passing
shaniah868 Feb 17, 2022
a59efe3
Merge pull request #100 from wepala/WEOS-1351
RandyDeo Feb 17, 2022
c0154df
Merge pull request #101 from wepala/WEOS-1249
shaniah868 Feb 17, 2022
2678dc1
feature:WEOS-1116
RandyDeo Feb 18, 2022
5c04e6c
feature/WEOS-1250 - review changes
atoniaw Feb 18, 2022
dff1a02
Merge pull request #106 from wepala/WEOS-1250
shaniah868 Feb 18, 2022
b8b22fd
Merge pull request #102 from wepala/WEOS-1276
shaniah868 Feb 18, 2022
ff4a33e
Merge branch 'dev' into feature/WEOS-1116
RandyDeo Feb 18, 2022
9209604
WEOS-1355 added functionality to get entity by identifiers in project…
atoniaw Feb 18, 2022
9aeef7d
WEOS-1355 Added x-unique functionality in projections and controllers
atoniaw Feb 18, 2022
fbc0cdd
feature: WEOS-1343 Generate and Ensure BDD Test is passing
shaniah868 Feb 21, 2022
438c6cc
Merge branch 'feature/WEOS-1343' into WEOS-1353
shaniah868 Feb 21, 2022
6937607
feature: WEOS-1343 Generate and Ensure BDD Test is passing
shaniah868 Feb 21, 2022
fb3959e
WEOS-1355 added scopes to query in order to pull associations
atoniaw Feb 21, 2022
d40cfbf
feature: WEOS-1343 Generate and Ensure BDD Test is passing
shaniah868 Feb 21, 2022
76daf87
Merge pull request #109 from wepala/WEOS-1353
atoniaw Feb 21, 2022
c1b2fba
Merge pull request #108 from wepala/WeoS-1355
RandyDeo Feb 21, 2022
a964da6
Merge branch 'dev' into feature/WEOS-1343
shaniah868 Feb 21, 2022
884118b
feature: WEOS-1343 As a developer I should be able to setup an OpenID…
shaniah868 Feb 21, 2022
0913890
feature: WEOS-1343 As a developer I should be able to setup an OpenID…
shaniah868 Feb 21, 2022
b03b465
feature:WEOS-1362
RandyDeo Feb 21, 2022
70001d7
WEOS-1358 - added unique validation in domain service
atoniaw Feb 21, 2022
08a3b47
WEOS-1358 added more domain tests
atoniaw Feb 21, 2022
2c280b2
Merge pull request #103 from wepala/feature/WEOS-1127
akeemphilbert Feb 21, 2022
effb183
Merge pull request #111 from wepala/WEOS-1368
shaniah868 Feb 21, 2022
b422d8f
Merge branch 'dev' into feature/WEOS-1362
RandyDeo Feb 21, 2022
cf99b35
doc: WEOS-1116 Updated spec to show that enumeration values should ma…
akeemphilbert Feb 21, 2022
ce914d6
Merge branch 'feature/WEOS-1343' of https://github.com/wepala/weos in…
akeemphilbert Feb 21, 2022
0345716
Merge branch 'dev' into feature/WEOS-1343
shaniah868 Feb 21, 2022
45d32be
feature: WEOS-1343 As a developer I should be able to setup an OpenID…
shaniah868 Feb 21, 2022
fe89af5
feature: WEOS-1343 As a developer I should be able to setup an OpenID…
shaniah868 Feb 22, 2022
e61d0b6
feature: WEOS-1343 As a developer I should be able to setup an OpenID…
shaniah868 Feb 22, 2022
c0db77c
feature:WEOS-1116
RandyDeo Feb 22, 2022
5314120
WEOS-1358 Added integration test for unique constraint
atoniaw Feb 22, 2022
ac3e8e1
WEOS-1358 update unique key error message
atoniaw Feb 22, 2022
543e218
WEOS-1358 updated unique error response
atoniaw Feb 22, 2022
63bbc92
feature:WEOS-1116
RandyDeo Feb 22, 2022
cc6c06b
WEOS-1358 minor refactor
atoniaw Feb 22, 2022
9938f81
Merge pull request #115 from wepala/WEOS-1358
RandyDeo Feb 23, 2022
361bfbb
feature:WEOS-1116
RandyDeo Feb 23, 2022
d7fbee7
feature:WEOS-1116
RandyDeo Feb 23, 2022
f2e175d
Merge pull request #112 from wepala/feature/WEOS-1362
akeemphilbert Feb 23, 2022
9c74761
feature: WEOS-1343 As a developer I should be able to setup an OpenID…
shaniah868 Feb 23, 2022
6093e7b
WEOS-1358 changed unique error level to debug
atoniaw Feb 23, 2022
4f5bd70
WEOS-1358 updated model test fixtures
atoniaw Feb 23, 2022
7419af1
Merge pull request #118 from wepala/WEOS-1358
RandyDeo Feb 23, 2022
c70ca1f
Merge branches 'feature/WEOS-1341' and 'dev' of github.com:wepala/weo…
atoniaw Feb 23, 2022
e34cb84
feature:WEOS-1116
RandyDeo Feb 23, 2022
c0fecda
feature: WEOS-1365 Add default handler returned content type based on…
shaniah868 Feb 23, 2022
62e284d
feature: WEOS-1365 Add default handler returned content type based on…
shaniah868 Feb 23, 2022
fa0af43
Merge branch 'feature/WEOS-1343' of https://github.com/wepala/weos in…
akeemphilbert Feb 23, 2022
a625310
feature:WEOS-1116
RandyDeo Feb 23, 2022
b6e3f51
feature: WEOS-1365 Add default handler returned content type based on…
shaniah868 Feb 23, 2022
6098bc0
feature:WEOS-1116
RandyDeo Feb 24, 2022
50b9fe7
Merge branch 'dev' into feature/WEOS-1116
RandyDeo Feb 24, 2022
cea85f9
feature:WEOS-1116
RandyDeo Feb 24, 2022
b47a430
doc: WEOS-1365 Added spec
akeemphilbert Feb 24, 2022
01e2aab
feature/WEOS-1341 add unique fields to swagger file
atoniaw Feb 24, 2022
99e2560
Merge pull request #119 from wepala/WEOS-1373
atoniaw Feb 24, 2022
2227f56
feature:WEOS-1116
RandyDeo Feb 24, 2022
29349c8
feature:WEOS-1116
RandyDeo Feb 24, 2022
4c24b2c
feature: WEOS-1365 Update standard operation initializer to parse con…
shaniah868 Feb 24, 2022
a7ac473
feature: WEOS-1343 Update the Default Discovery endpoint to use Autho…
shaniah868 Feb 24, 2022
3c3fab3
Merge pull request #121 from wepala/WEOS-1372
atoniaw Feb 24, 2022
3183ea3
feature: WEOS-1343 Update the Default Discovery endpoint to use Autho…
shaniah868 Feb 24, 2022
4f478ec
Merge pull request #122 from wepala/WEOS-1375
atoniaw Feb 24, 2022
c63503c
feature: WEOS-1308 Update standard operation initializer to parse con…
shaniah868 Feb 24, 2022
302224f
feature: WEOS-13065 Generate and Ensure Bdd Test is passing
shaniah868 Feb 24, 2022
606a934
feature: WEOS-13065 Generate and Ensure Bdd Test is passing
shaniah868 Feb 24, 2022
0883b97
feature: WEOS-13065 Generate and Ensure Bdd Test is passing
shaniah868 Feb 25, 2022
018cd6f
feature: WEOS-1365 Generate and Ensure Bdd Test is passing
shaniah868 Feb 25, 2022
d4e7127
Merge pull request #123 from wepala/WEOS-1374
atoniaw Feb 25, 2022
c73a614
Merge branch 'feature/WEOS-1343' of https://github.com/wepala/weos in…
akeemphilbert Feb 26, 2022
843efd2
doc: WEOS-1343 Added scenario to deal with undefined security schemes
akeemphilbert Feb 26, 2022
a30ee4e
doc: WEOS-1116 Updated the spect to show that the integer can have a …
akeemphilbert Feb 26, 2022
213c4d8
feature: WEOS-1343 Generate and Ensure BDD Test is passing
shaniah868 Feb 28, 2022
38a0a39
Merge pull request #126 from wepala/WEOS-1353
RandyDeo Feb 28, 2022
9a531d8
fix: WEOS-1365 Can't omit 200 response on GET response && Cannot hav…
shaniah868 Feb 28, 2022
db4da4f
feature: WEOS-1343 As a developer I should be able to setup an OpenID…
shaniah868 Feb 28, 2022
2089b7e
feature: WEOS-1365 Cannot have endpoint that does not have a response…
shaniah868 Feb 28, 2022
fd7d737
feature: WEOS-1365 Cannot have endpoint that does not have a response…
shaniah868 Feb 28, 2022
209d260
feature: WEOS-1343 As a developer I should be able to setup an OpenID…
shaniah868 Feb 28, 2022
0c030e8
Merge pull request #117 from wepala/feature/WEOS-1341
akeemphilbert Feb 28, 2022
529dd05
feature:WEOS-1116
RandyDeo Feb 28, 2022
7e1fea6
feature: WEOS-1343 As a developer I should be able to setup an OpenID…
shaniah868 Feb 28, 2022
9d878ba
Merge branch 'dev' into feature/WEOS-1343
shaniah868 Feb 28, 2022
453a7b3
Merge branch 'dev' into feature/WEOS-1365
shaniah868 Feb 28, 2022
e253bb8
feature: WEOS-1343 As a developer I should be able to setup an OpenID…
shaniah868 Feb 28, 2022
eace2a6
feature: WEOS-1343 As a developer I should be able to setup an OpenID…
shaniah868 Feb 28, 2022
ad06720
feature: WEOS-1343 As a developer I should be able to setup an OpenID…
shaniah868 Feb 28, 2022
678d1e9
feature:WEOS-1116
RandyDeo Feb 28, 2022
436c0ec
feature:WEOS-1116
RandyDeo Feb 28, 2022
12c43ed
feature:WEOS-1116
RandyDeo Feb 28, 2022
2360a22
feature:WEOS-1116
RandyDeo Feb 28, 2022
aabd57b
feature:WEOS-1116
RandyDeo Feb 28, 2022
9001256
Merge pull request #107 from wepala/feature/WEOS-1116
akeemphilbert Mar 1, 2022
0eb0b13
Updated null declaration in enumeration
RandyDeo Mar 1, 2022
66b1a7d
feature:WEOS-1116
RandyDeo Mar 1, 2022
b28cc5a
Merge pull request #129 from wepala/Fix-1116toDev
akeemphilbert Mar 1, 2022
c9048ee
feature: WEOS-1365 As a developer I should be able set an example to …
shaniah868 Mar 2, 2022
ebaf128
feature: WEOS-1365 As a developer I should be able set an example to …
shaniah868 Mar 2, 2022
4441c83
feature: WEOS-1365 As a developer I should be able set an example to …
shaniah868 Mar 2, 2022
bd44361
Merge branch 'dev' into feature/WEOS-1365
shaniah868 Mar 2, 2022
57e31ba
Merge branch 'dev' into feature/WEOS-1343
shaniah868 Mar 2, 2022
4362398
feature: WEOS-1365 As a developer I should be able set an example to …
shaniah868 Mar 2, 2022
c6a953e
feature: WEOS-1365 As a developer I should be able set an example to …
shaniah868 Mar 2, 2022
f49bc18
Merge pull request #110 from wepala/feature/WEOS-1343
akeemphilbert Mar 2, 2022
0b5598f
Merge branch 'dev' into feature/WEOS-1365
shaniah868 Mar 2, 2022
723c832
Merge pull request #124 from wepala/feature/WEOS-1365
akeemphilbert Mar 2, 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
1 change: 1 addition & 0 deletions .github/workflows/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ env:
SLACK_ICON: https://github.com/wepala.png?size=48
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_FOOTER: copyright 2022 Wepala
OAUTH_TEST_KEY: ${{ secrets.OAUTH_TEST_KEY }}

jobs:
build-api:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ env:
SLACK_ICON: https://github.com/wepala.png?size=48
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_FOOTER: copyright 2022 Wepala
OAUTH_TEST_KEY: ${{ secrets.OAUTH_TEST_KEY }}

jobs:
build-api:
Expand Down
78 changes: 75 additions & 3 deletions api.yaml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ components:
url:
type: string
format: uri
x-unique: true
title:
type: string
description:
Expand All @@ -76,9 +77,9 @@ components:
type: string
nullable: true
enum:
- null
- unpublished
- published
- "null"
- one
- two
image:
type: string
format: byte
Expand Down Expand Up @@ -116,6 +117,55 @@ components:
type: string
format: date-time
paths:
/:
get:
operationId: Homepage
responses:
200:
description: Application Homepage
content:
text/html:
example: |
<html>
<head>
<title>Health</title>
</head>
<body>
This is a landing page
</body>
</html>
/page:
get:
summary: Test
parameters:
- in: header
name: Accept
schema:
type: string
responses:
'200':
description: Test Page
content:
text/html:
example: |
<html>
<head>
<title>Test Page</title>
</head>
<body>
This is a test page
</body>
</html>
schema:
type: string
application/json:
example:
blog:
value: {
"title": "API Testing",
"url": "www.example.com",
"email": "[email protected]"
}
/health:
summary: Health Check
get:
Expand All @@ -125,6 +175,28 @@ paths:
description: Health Response
500:
description: API Internal Error
/api/json:
get:
operationId: Get API Details
x-controller: APIDiscovery
responses:
200:
description: API Details
content:
application/json:
schema:
type: string
/api/html:
get:
operationId: Get API Details
x-controller: APIDiscovery
responses:
200:
description: API Details
content:
application/html:
schema:
type: string
/blogs:
post:
operationId: Add Blog
Expand Down
64 changes: 64 additions & 0 deletions conf/tasks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
openapi: 3.0.3
info:
title: Tasks API
description: Tasks API
version: 1.0.0
servers:
- url: 'http://localhost:8681'
x-weos-config:
database:
driver: sqlite3
database: e2e.db
components:
securitySchemes:
Auth0:
type: openIdConnect
openIdConnectUrl: https://samples.auth0.com/.well-known/openid-configuration
schemas:
Task:
type: object
properties:
title:
type: string
security:
- Auth0: ["email","name"]
paths:
/tasks:
get:
description: Get a list of tasks
operationId: getTasks
security:
- Auth0: []
responses:
200:
description: List of tasks
content:
application/json:
schema:
type: object
properties:
total:
type: integer
page:
type: integer
items:
$ref: "#/components/schemas/Task"

post:
description: Create task
operationId: createTask
requestBody:
description: Task
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/Task"
application/x-www-form-urlencoded:
schema:
$ref: "#/components/schemas/Task"
responses:
201:
description: Created task


3 changes: 3 additions & 0 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const FILTERS ContextKey = "_filters"
const SORTS ContextKey = "_sorts"
const PAYLOAD ContextKey = "_payload"
const SEQUENCE_NO string = "sequence_no"
const RESPONSE_PREFIX string = "_httpstatus"
const AUTHORIZATION string = "Authorization"
const ACCEPT string = "Accept"

//Path initializers are run per path and can be used to configure routes that are not defined in the open api spec
const METHODS_FOUND ContextKey = "_methods_found"
Expand Down
106 changes: 101 additions & 5 deletions controllers/rest/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strings"
"time"

"github.com/rakyll/statik/fs"
weoscontext "github.com/wepala/weos/context"
"github.com/wepala/weos/projections/dialects"
"gorm.io/driver/clickhouse"
Expand Down Expand Up @@ -47,6 +48,7 @@ type RESTAPI struct {
eventStores map[string]model.EventRepository
commandDispatchers map[string]model.CommandDispatcher
projections map[string]projections.Projection
globalInitializers []GlobalInitializer
operationInitializers []OperationInitializer
registeredInitializers map[reflect.Value]int
prePathInitializers []PathInitializer
Expand Down Expand Up @@ -120,6 +122,20 @@ func (p *RESTAPI) RegisterEventStore(name string, repository model.EventReposito
p.eventStores[name] = repository
}

//RegisterGlobalInitializer add global initializer if it's not already there
func (p *RESTAPI) RegisterGlobalInitializer(initializer GlobalInitializer) {
if p.registeredInitializers == nil {
p.registeredInitializers = make(map[reflect.Value]int)
}
//only add initializer if it doesn't already exist
tpoint := reflect.ValueOf(initializer)
if _, ok := p.registeredInitializers[tpoint]; !ok {
p.globalInitializers = append(p.globalInitializers, initializer)
p.registeredInitializers[tpoint] = len(p.globalInitializers)
}

}

//RegisterOperationInitializer add operation initializer if it's not already there
func (p *RESTAPI) RegisterOperationInitializer(initializer OperationInitializer) {
if p.registeredInitializers == nil {
Expand Down Expand Up @@ -244,6 +260,11 @@ func (p *RESTAPI) GetProjection(name string) (projections.Projection, error) {
return nil, fmt.Errorf("projection '%s' not found", name)
}

//GetGlobalInitializers get global intializers in the order they were registered
func (p *RESTAPI) GetGlobalInitializers() []GlobalInitializer {
return p.globalInitializers
}

//GetOperationInitializers get operation intializers in the order they were registered
func (p *RESTAPI) GetOperationInitializers() []OperationInitializer {
return p.operationInitializers
Expand Down Expand Up @@ -272,6 +293,31 @@ func (p *RESTAPI) GetEntityFactories() map[string]model.EntityFactory {
return p.entityFactories
}

const SWAGGERUIENDPOINT = "/_discover/"
const SWAGGERJSONENDPOINT = "/_discover_json"

//RegisterSwaggerAPI creates default swagger api from binary
func (p *RESTAPI) RegisterDefaultSwaggerAPI(pathMiddleware []echo.MiddlewareFunc) error {
statikFS, err := fs.New()
if err != nil {
return NewControllerError("Got an error formatting response", err, http.StatusInternalServerError)
}
static := http.FileServer(statikFS)
sh := http.StripPrefix(SWAGGERUIENDPOINT, static)
handler := echo.WrapHandler(sh)
p.e.GET(SWAGGERUIENDPOINT+"*", handler, pathMiddleware...)

return nil
}

//RegisterDefaultSwaggerJson registers a default swagger json response
func (p *RESTAPI) RegisterDefaultSwaggerJSON(pathMiddleware []echo.MiddlewareFunc) error {
p.e.GET(SWAGGERJSONENDPOINT, func(c echo.Context) error {
return c.JSON(http.StatusOK, p.Swagger)
}, pathMiddleware...)
return nil
}

//Initialize and setup configurations for RESTAPI
func (p *RESTAPI) Initialize(ctxt context.Context) error {
//register standard controllers
Expand All @@ -282,15 +328,22 @@ func (p *RESTAPI) Initialize(ctxt context.Context) error {
p.RegisterController("DeleteController", DeleteController)
p.RegisterController("HealthCheck", HealthCheck)
p.RegisterController("CreateBatchController", CreateBatchController)
p.RegisterController("APIDiscovery", APIDiscovery)
p.RegisterController("DefaultResponseController", DefaultResponseController)

//register standard middleware
p.RegisterMiddleware("Context", Context)
p.RegisterMiddleware("OpenIDMiddleware", OpenIDMiddleware)
p.RegisterMiddleware("CreateMiddleware", CreateMiddleware)
p.RegisterMiddleware("CreateBatchMiddleware", CreateBatchMiddleware)
p.RegisterMiddleware("UpdateMiddleware", UpdateMiddleware)
p.RegisterMiddleware("ListMiddleware", ListMiddleware)
p.RegisterMiddleware("ViewMiddleware", ViewMiddleware)
p.RegisterMiddleware("DeleteMiddleware", DeleteMiddleware)
p.RegisterMiddleware("Recover", Recover)
//register standard global initializers
p.RegisterGlobalInitializer(Security)
p.RegisterMiddleware("DefaultResponseMiddleware", DefaultResponseMiddleware)
//register standard operation initializers
p.RegisterOperationInitializer(ContextInitializer)
p.RegisterOperationInitializer(EntityFactoryInitializer)
Expand All @@ -299,6 +352,7 @@ func (p *RESTAPI) Initialize(ctxt context.Context) error {
p.RegisterOperationInitializer(RouteInitializer)
//register standard post path initializers
p.RegisterPostPathInitializer(CORsInitializer)

//these are the dynamic struct builders for the schemas in the OpenAPI
var schemas map[string]ds.Builder

Expand All @@ -323,6 +377,40 @@ func (p *RESTAPI) Initialize(ctxt context.Context) error {
}
p.RegisterProjection("Default", defaultProjection)
}

//This will check the enum types on run and output an error
for _, scheme := range p.Swagger.Components.Schemas {
for pName, prop := range scheme.Value.Properties {
if prop.Value.Enum != nil {
t := prop.Value.Type
for _, v := range prop.Value.Enum {
switch t {
case "string":
if reflect.TypeOf(v).String() != "string" {
return fmt.Errorf("Expected field: %s, of type %s, to have enum options of the same type", pName, t)
}
case "integer":
if reflect.TypeOf(v).String() != "float64" {
if v.(string) == "null" {
continue
} else {
return fmt.Errorf("Expected field: %s, of type %s, to have enum options of the same type", pName, t)
}
}
case "number":
if reflect.TypeOf(v).String() != "float64" {
if v.(string) == "null" {
continue
} else {
return fmt.Errorf("Expected field: %s, of type %s, to have enum options of the same type", pName, t)
}
}
}
}
}
}
}

//get the database schema
schemas = CreateSchema(ctxt, p.EchoInstance(), p.Swagger)
p.Schemas = schemas
Expand Down Expand Up @@ -417,12 +505,20 @@ func (p *RESTAPI) Initialize(ctxt context.Context) error {
//setup routes
knownActions := []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS", "TRACE", "CONNECT"}
var err error
globalContext := context.Background()
//run global initializers
for _, initializer := range p.GetGlobalInitializers() {
globalContext, err = initializer(globalContext, p, p.Swagger)
if err != nil {
return err
}
}
for path, pathData := range p.Swagger.Paths {
var methodsFound []string
pathContext := context.Background()

//run pre path initializers
for _, initializer := range p.GetPrePathInitializers() {
pathContext, err = initializer(pathContext, p, path, p.Swagger, pathData)
globalContext, err = initializer(globalContext, p, path, p.Swagger, pathData)
if err != nil {
return err
}
Expand All @@ -432,7 +528,7 @@ func (p *RESTAPI) Initialize(ctxt context.Context) error {
operationData := pathData.GetOperation(strings.ToUpper(method))
if operationData != nil {
methodsFound = append(methodsFound, strings.ToUpper(method))
operationContext := context.WithValue(context.Background(), weoscontext.SCHEMA_BUILDERS, schemas) //TODO fix this because this feels hacky
operationContext := context.WithValue(globalContext, weoscontext.SCHEMA_BUILDERS, schemas) //TODO fix this because this feels hacky
for _, initializer := range p.GetOperationInitializers() {
operationContext, err = initializer(operationContext, p, path, method, p.Swagger, pathData, operationData)
if err != nil {
Expand All @@ -443,9 +539,9 @@ func (p *RESTAPI) Initialize(ctxt context.Context) error {
}

//run post path initializers
pathContext = context.WithValue(pathContext, weoscontext.METHODS_FOUND, methodsFound)
globalContext = context.WithValue(globalContext, weoscontext.METHODS_FOUND, methodsFound)
for _, initializer := range p.GetPostPathInitializers() {
pathContext, err = initializer(pathContext, p, path, p.Swagger, pathData)
globalContext, err = initializer(globalContext, p, path, p.Swagger, pathData)
}
//output registered endpoints for debugging purposes
for _, route := range p.EchoInstance().Routes() {
Expand Down
Loading