Skip to content

Commit 7ca0317

Browse files
authored
Dev (#289)
* row action menu exmaple * operation authorization helper * css * traefikless setup for oidc - useful for broken wsl2 with wifi + acrylic dns setups * dont fix via golangci-lint * refactor mrt custom filters * css and refactoring * date input * proper components * fix oapi template gen * notes to fix oapi-codegen mapping gen upstream * fix oapi codegen upstream * orval also broken for shared schemas * orval update * update filters * add filter tests * filter tests * refactor filter tests * update filter tests * squash migrations due to slow golang-migrate * null filters * update pagination and filters representation * update tests
1 parent e26b6bc commit 7ca0317

File tree

199 files changed

+3741
-1779
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+3741
-1779
lines changed

.env.ci

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ FRONTEND_PORT=80
2323
OIDC_CLIENT_ID=web
2424
OIDC_CLIENT_SECRET=secret
2525
AUTH_SERVER_UI_PROFILE="https://authserver.local.localhost/oidc/profile"
26+
MOCK_OIDC_SERVER_PATH_PREFIX="/oidc"
2627
OIDC_DOMAIN="authserver.local.localhost"
2728
OIDC_ISSUER="https://authserver.local.localhost/oidc"
2829
OIDC_SCOPES="openid profile email auth"

.env.template

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,19 @@ REDIS_HOST=
2020
REDIS_DB=
2121
API_PORT=
2222
FRONTEND_PORT=
23+
# for traefikless setup:
24+
# AUTH_SERVER_UI_PROFILE="http://localhost:$MOCK_OIDC_SERVER_PORT/profile"
25+
# OIDC_DOMAIN="localhost:$MOCK_OIDC_SERVER_PORT"
26+
# OIDC_ISSUER="http://localhost:$MOCK_OIDC_SERVER_PORT"
2327
AUTH_SERVER_UI_PROFILE=
24-
OIDC_CLIENT_ID=
25-
OIDC_CLIENT_SECRET=
28+
OIDC_DOMAIN=
2629
OIDC_ISSUER=
2730
OIDC_SCOPES=
28-
OIDC_DOMAIN=
31+
OIDC_CLIENT_ID=
32+
OIDC_CLIENT_SECRET=
33+
# if using localhost:$MOCK_OIDC_SERVER_PORT, then leave empty,
34+
# else set to traefik label's PathPrefix
35+
MOCK_OIDC_SERVER_PATH_PREFIX=
2936
MOCK_OIDC_SERVER_PORT=
3037
MOCK_OIDC_SERVER_DATA_DIR=
3138
SIGNING_KEY=

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"go.lintFlags": [
55
"--config=${workspaceFolder}/.golangci.yml",
66
"--issues-exit-code=0",
7-
"--fix",
7+
// golangci possibly broke generated code skipping in recent releases
8+
// "--fix",
89
"--fast" // breaks some linters like errcheck, if its too slow then enable back
910
],
1011
"go.lintOnSave": "package",

bin/project

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -851,9 +851,9 @@ x.gen.client-server() {
851851
# yq e 'del(.components)' -i "$paths_file" # dont delete since recent oapi-codegen does some checks even if we are not generating types
852852
go build -o $BUILD_DIR/oapi-codegen cmd/oapi-codegen/main.go || mark_failed_tool_build # templates are embedded, required rebuild
853853

854-
oapi-codegen --config internal/models/oapi-codegen-types.yaml "$SPEC_PATH" || err "Failed types generation" &
855-
oapi-codegen --config internal/rest/oapi-codegen-server.yaml --models-pkg models --server-types "$server_types_list" --types "$types_list" "$paths_file" || err "Failed server generation" &
856-
oapi-codegen --config internal/rest/oapi-codegen-test-client.yaml "$SPEC_PATH" || err "Failed client generation" &
854+
oapi-codegen --config internal/models/oapi-codegen-types.yaml "$SPEC_PATH" || err "Failed types generation"
855+
oapi-codegen --config internal/rest/oapi-codegen-server.yaml --models-pkg models --server-types "$server_types_list" --types "$types_list" "$paths_file" || err "Failed server generation"
856+
oapi-codegen --config internal/rest/oapi-codegen-test-client.yaml "$SPEC_PATH" || err "Failed client generation"
857857
# not used now. may be useful for a cli at some point
858858
# oapi-codegen --config internal/client/oapi-codegen-client.yaml "$SPEC_PATH" || err "Failed client generation" &
859859

@@ -1128,7 +1128,8 @@ x.lint.go() {
11281128
-name "*.go")
11291129
goimports -w $files || err "Linting failed"
11301130
gofumpt -w $files || err "Linting failed"
1131-
golangci-lint run --config=.golangci.yml --allow-parallel-runners --fast --fix &>/dev/null || true
1131+
# recent releases possibly broke generated code detection
1132+
# golangci-lint run --config=.golangci.yml --allow-parallel-runners --fast --fix &>/dev/null || true
11321133
}
11331134

11341135
exhaustruct_lint() {
@@ -1225,7 +1226,7 @@ x.test.backend.setup() {
12251226
{ { {
12261227
# NOTE: tests run independently in Go so we can't have a function be called and run
12271228
# only once before any test starts
1228-
run_shared_services up -d --build --remove-orphans --wait
1229+
run_shared_services up -d --build --remove-orphans --force-recreate --wait
12291230
x.gen
12301231
# no need to migrate, done on every test run internally
12311232
docker.postgres.drop_and_recreate_db $POSTGRES_TEST_DB
@@ -1384,8 +1385,13 @@ x.test.backend.watch-for() {
13841385

13851386
test_backend_watch -run "^($fns)$" "$GOMOD_PKG/$dir" "${gotest_args[@]}"
13861387
}
1388+
1389+
pre_build_cmd="project setup-swagger-ui"
1390+
13871391
# Run backend.
13881392
x.run.backend() {
1393+
$pre_build_cmd
1394+
run_shared_services up -d --build --remove-orphans --force-recreate --wait
13891395
go run ./cmd/rest-server/main.go -env=.env.$X_ENV
13901396
}
13911397

@@ -1394,11 +1400,10 @@ x.run.backend-hr() {
13941400
# TODO replace healthcheck with adhoc calls and bring services up in btaches
13951401
# to prevent either bombarding with req or having to wait too long at startup.
13961402
# see https://github.com/moby/moby/issues/33410
1397-
run_shared_services up -d --build --remove-orphans --wait
1403+
run_shared_services up -d --build --remove-orphans --force-recreate --wait
13981404

13991405
# https://github.com/cosmtrek/air/blob/master/air_example.toml
14001406
# NOTE: building binary unreliable, leads to bin not found.
1401-
local pre_build_cmd="project setup-swagger-ui"
14021407
air \
14031408
--build.pre_cmd "$pre_build_cmd" \
14041409
--build.cmd "" \

cmd/oapi-codegen/oapi-templates/union.tmpl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
{{$properties := .Schema.Properties -}}
55
{{range .Schema.UnionElements}}
66
{{ $element := printf "%v" . -}}
7-
{{ $name := $element -}}
8-
{{ if (is_rest_type $element) -}}
9-
{{ $name = (printf "%v" (rest_type $element)) -}}
10-
{{ end -}}
7+
{{ $name := (printf "%v" (rest_type $element)) -}}
118
// As{{$name}} returns the union data inside the {{$typeName}} as a {{$name}}
129
func (t {{$typeName}}) As{{$name}}() ({{$name}}, error) {
1310
var body {{$name}}
@@ -74,7 +71,7 @@
7471
return discriminator.Discriminator, err
7572
}
7673
{{/* TODO: can use is_rest_type here too. */}}
77-
{{if ne 0 (len $discriminator.Mapping)}}
74+
{{ if ne 0 (len $discriminator.Mapping)}}
7875
func (t {{.TypeName}}) ValueByDiscriminator() (interface{}, error) {
7976
discriminator, err := t.Discriminator()
8077
if err != nil {

db/migrations/0000002_init.down.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ drop schema if exists v;
22

33
drop schema if exists "cache";
44

5+
drop schema if exists extra_schema cascade;
6+
57
do $$
68
declare
79
table_rec RECORD;

0 commit comments

Comments
 (0)