Skip to content

Commit

Permalink
refactor and lint spec
Browse files Browse the repository at this point in the history
  • Loading branch information
danicc097 committed Aug 30, 2024
1 parent 3fa1bd1 commit 1fb869b
Show file tree
Hide file tree
Showing 9 changed files with 268 additions and 274 deletions.
12 changes: 6 additions & 6 deletions bin/project
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ x.gen.pregen() {
echo "Running generation"

# NOTE: swaggest won't generate for arrays of structs. use a struct with array fields instead.
generate_structs_map # structs might have been removed in the meantime
generate_structs_map # xo gen will create/update model structs

go build -o $BUILD_DIR/codegen cmd/codegen/main.go || mark_failed_tool_build # xo gen may create/update models.
go build -o $BUILD_DIR/codegen cmd/codegen/main.go || mark_failed_tool_build

local rest_structs=() refs=() spec_schemas=()
declare -A rest_schema_lookup spec_schema_lookup
Expand Down Expand Up @@ -1088,7 +1088,7 @@ x.gen.frontend() {
mkdir -p frontend/src/types
rm -rf $FRONTEND_GEN

yq 'explode(.)' $SPEC_PATH >$exploded_spec # js-lib won't support anchors - used by most gen libs
yq 'explode(.)' $SPEC_PATH >$exploded_spec # js-yaml wont support explicit tags - used by most gen libs

{
node frontend/scripts/generate-client-validator.js
Expand Down Expand Up @@ -1162,8 +1162,6 @@ x.gen() {

wait_without_error || err Failed jobs

x.test.xo

{
x.gen.pregen
x.gen.client-server
Expand Down Expand Up @@ -1191,7 +1189,9 @@ x.gen() {
# Build code generation custom tools.
x.gen.build-tools() {
{ { {
generate_structs_map # openapi-go requires structs already compiled
# openapi-go via codegen cli requires structs already compiled, but we will rebuild
# right before codegen gen-schema since PublicStructs is not used anywhere else inside codegen
# generate_structs_map

out_dir=$BUILD_DIR

Expand Down
8 changes: 4 additions & 4 deletions frontend/src/client-validator/gen/dereferenced-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2704,12 +2704,12 @@
"firstName": {
"description": "originally from auth server but updatable",
"type": "string",
"pattern": "^[\\p{L} '-]+$"
"pattern": "^[a-zA-Z \\'-]+$"
},
"lastName": {
"description": "originally from auth server but updatable",
"type": "string",
"pattern": "^[\\p{L} '-]+$"
"pattern": "^[a-zA-Z \\'-]+$"
}
},
"type": "object"
Expand Down Expand Up @@ -10135,12 +10135,12 @@
"firstName": {
"description": "originally from auth server but updatable",
"type": "string",
"pattern": "^[\\p{L} '-]+$"
"pattern": "^[a-zA-Z \\'-]+$"
},
"lastName": {
"description": "originally from auth server but updatable",
"type": "string",
"pattern": "^[\\p{L} '-]+$"
"pattern": "^[a-zA-Z \\'-]+$"
}
},
"type": "object"
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/client-validator/gen/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1392,12 +1392,12 @@
"firstName": {
"description": "originally from auth server but updatable",
"type": "string",
"pattern": "^[\\p{L} '-]+$"
"pattern": "^[a-zA-Z \\'-]+$"
},
"lastName": {
"description": "originally from auth server but updatable",
"type": "string",
"pattern": "^[\\p{L} '-]+$"
"pattern": "^[a-zA-Z \\'-]+$"
}
},
"type": "object"
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/gen/model/updateUserRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import type * as EntityIDs from 'src/gen/entity-ids'
export interface UpdateUserRequest {
/**
* originally from auth server but updatable
* @pattern ^[\p{L} '-]+$
* @pattern ^[a-zA-Z \'-]+$
*/
firstName?: string;
/**
* originally from auth server but updatable
* @pattern ^[\p{L} '-]+$
* @pattern ^[a-zA-Z \'-]+$
*/
lastName?: string;
}
7 changes: 0 additions & 7 deletions internal/codegen/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,6 @@ func (o *CodeGen) generateOpIDAuthMiddlewares() error {

funcs := template.FuncMap{
"stringsJoin": strings.Join,
"stringsJoinSlice": func(elems []string, prefix string, suffix string, sep string) string {
for i, e := range elems {
elems[i] = prefix + e + suffix
}

return strings.Join(elems, sep)
},
}

tmpl := "templates/api_auth_middlewares.tmpl"
Expand Down
6 changes: 4 additions & 2 deletions internal/codegen/templates/api_auth_middlewares.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ func (h *StrictHandlers) authMiddlewares(opID OperationID) []gin.HandlerFunc {
{{- if $authInfo.Role }}
MinimumRole: models.Role("{{$authInfo.Role}}"),
{{- end }}
{{- if $authInfo.Scopes }}
{{- if (gt (len $authInfo.Scopes) 0) }}
RequiredScopes: models.Scopes{
{{ stringsJoinSlice $authInfo.Scopes "models.Scope(\"" "\")" ",\n" -}}
{{range $authInfo.Scopes -}}
models.Scope("{{.}}"),
{{end -}}
},
{{- end }}
}),
Expand Down
248 changes: 124 additions & 124 deletions internal/repos/postgresql/gen/models/openapi_types.gen.go

Large diffs are not rendered by default.

248 changes: 124 additions & 124 deletions internal/rest/openapi_server.gen.go

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2196,11 +2196,11 @@ components:
firstName:
description: originally from auth server but updatable
type: string
pattern: ^[\p{L} '-]+$
pattern: ^[a-zA-Z \'-]+$
lastName:
description: originally from auth server but updatable
type: string
pattern: ^[\p{L} '-]+$
pattern: ^[a-zA-Z \'-]+$
type: object
UpdateUserAuthRequest:
description: represents User authorization data to update
Expand All @@ -2220,7 +2220,6 @@ components:
- loc
- msg
- detail
- type
type: object
properties:
loc:
Expand Down

0 comments on commit 1fb869b

Please sign in to comment.