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

Arrays support #11

Merged
merged 67 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
8931cff
Some readme.
Jul 26, 2024
4e8552a
Adjust TODOs
Jul 26, 2024
49477c1
Some more readme fixes.
Jul 26, 2024
ead5ab5
Adding arrays parsing schema.
Jul 26, 2024
6c97093
Cleanup schema.
Jul 26, 2024
7b05ac3
TODOs.
Jul 26, 2024
a283497
Fixing templates.
Jul 27, 2024
351c60e
Disable arrays parsing first.
Jul 28, 2024
3696c55
Some notes.
Aug 4, 2024
8ea3919
Simplifying templates.
Aug 4, 2024
c5101a3
Removing unneeded stuff.
Aug 6, 2024
ca6c57c
Simplifying templates.
Aug 7, 2024
73cba40
Preparing array parser.
Aug 7, 2024
a2a60d0
Move model validator to a separate template for a reuse.
Aug 9, 2024
4f53e61
Temporary fix params.
Aug 9, 2024
ee6a645
Proper indent.
Aug 11, 2024
a590ffe
Extract and simplify model validators inclusion.
Aug 11, 2024
2130273
Iterating on parsers simplification.
Aug 12, 2024
01a9b34
Iterating on parsers simplification.
Aug 14, 2024
ec9bcc0
Building string types arrays parsing.
Aug 14, 2024
c41c579
Initial arrays parsing test.
Aug 14, 2024
f9c51d5
Bad values parsing.
Aug 14, 2024
9e9d9ae
More informative errors.
Aug 14, 2024
16909a2
Generating array item ranges validation routes.
Aug 14, 2024
79edf74
Range validation happy path.
Aug 14, 2024
ff3af5f
Simplify tests.
Aug 14, 2024
3f7ba45
Adding min length validation.
Aug 14, 2024
8f7d05d
Validating field.
Aug 14, 2024
49457b4
Prettify templates.
Aug 16, 2024
17624b2
Extending bidning context to handle path instead of statically linked…
Aug 16, 2024
6bc9b0c
Doing proper path validation.
Aug 16, 2024
4e5e787
Some TODOs.
Aug 16, 2024
30fa67d
Remove unused stuff.
Aug 16, 2024
15453a4
Another round of simplification.
Aug 16, 2024
248ebac
Go 1.23 upgrade.
Aug 16, 2024
bd6e57a
Lint fixes.
Aug 16, 2024
8fe8a94
More tests.
Aug 16, 2024
9bf9b1e
Adding routes to test nullable array items validation.
Aug 18, 2024
28e5154
Initial happy path test.
Aug 18, 2024
2dabe11
Improve coverage.
Aug 18, 2024
2742af3
Initial arrays parsing.
Aug 19, 2024
ef5f8eb
Parsing tests.
Aug 19, 2024
9a8e872
Lint.
Aug 19, 2024
db99234
Make route more generic.
Aug 19, 2024
8b06551
Adding validation.
Aug 19, 2024
dcf7c2e
Validation tests.
Aug 19, 2024
04608e9
Adding nullable numeric items test.
Aug 19, 2024
44a9c53
Boolean array items.
Aug 19, 2024
b7969e1
Initial boolean test.
Aug 19, 2024
3dbb7b1
Nullable array items test.
Aug 19, 2024
e43b7f7
Nullable array items test.
Aug 19, 2024
4f775d8
Object arrays parsing.
Aug 19, 2024
ee214d2
Bump coverage.
Aug 19, 2024
14b4ec5
Naming fixes.
Aug 19, 2024
b264814
Adding validation.
Aug 20, 2024
10db248
Arrays body validation.
Aug 20, 2024
e0ee1ea
Some more readme points.
Aug 20, 2024
2431aa2
Generating routes.
Aug 20, 2024
6dcbb89
Adding arrays range validation.
Aug 20, 2024
ff6f6ad
Fix controller name.
Aug 20, 2024
b601609
Some more readme.
Aug 20, 2024
66b95a1
Adding array validation.
Aug 20, 2024
a8893e9
Adding arrays required validation.
Aug 20, 2024
b6e621f
Nullable validation.
Aug 20, 2024
59ee570
Adding arrays validation.
Aug 21, 2024
15683a1
Array range validation.
Aug 21, 2024
8a36d64
Bump coverage.
Aug 21, 2024
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
2 changes: 1 addition & 1 deletion .golangci-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.59.1
v1.60.1
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ linters-settings:
# Default: false
all: true

dupl:
# 150 by default is not enough and leads to false positives
threshold: 200

linters:
disable-all: true
Expand Down Expand Up @@ -353,6 +356,8 @@ issues:
- noctx
- wrapcheck
- gocognit
- gocyclo
- cyclop
- path: "(routes/handlers/(.+)_(controller|params)\\.go)|(routes/models/(.+)\\.go)|(internal/(.+)_validation\\.go)"
linters:
- lll # hard to control line length in generated code
Expand Down
39 changes: 34 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,36 @@ Project status: **pre-alpha**.

## TODOs

### General
* Installation and usage instructions
* Documentation on generated code structure and suggested patterns

### Golang
* enums
* simple types directly in body
* array types directly in body
* allow handling as plain http handler
* authentication
* per route middleware
* allow handling as plain http handler
* nullable types
* polymorphic models
* enums

### Typescript

Set of features compatible with golang

## Supported OpenAPI features

Some language specific features may be challenging (if possible) to implement correctly. The [Language specific caveats](#language-specific-caveats) summarises various implementation details.

### Parameter Serialization

[OpenAPI Spec Reference](https://swagger.io/docs/specification/serialization/)

Supported serialization styles:
|parameter location|style|explode|example primitive type|example array type|object support|
|----|----|----|----|----|----|
|path|simple|false|`/users/5`|`/users/3,4,5`|-|
|query|form|true|`/users?id=5`|`/users?id=3&id=4&id=5`|-|

### Data types

#### All types
Expand All @@ -36,6 +50,7 @@ Some language specific features may be challenging (if possible) to implement co
|number/integer|✓|✓|
|boolean|✓|✓|
|object|✓|✓|
|array|✓|✓|

#### Strings
|format|in|minLength|maxLength|pattern|
Expand All @@ -60,10 +75,20 @@ Some language specific features may be challenging (if possible) to implement co
|----|----|----|
|boolean|query,path,body|✓|

#### Object
#### Objects

Objects are only supported in request body of `application/json` content type.

#### Arrays
|items type|in|minItems|maxItems|
|----|----|----|----|
|string|query,path,body|✓|✓|
|number|query,path,body|✓|✓|
|integer|query,path,body|✓|✓|
|boolean|query,path,body|✓|✓|
|object|body|✓|✓|


### Language specific caveats

Golang:
Expand All @@ -72,6 +97,10 @@ Golang:
* The `required` check on booleans in request body is not performed
* For simple data types - will validate if the field is non default
* For objects - optional and nullable are synonyms. This means that required validation will only work for non nullable fields.
* `array` fields
* `required` is equivalent to `minItems: 1`
* `nullable` arrays are only supported in request body
* nullable and optional array fields are synonyms

## Contributing

Expand Down
4 changes: 2 additions & 2 deletions examples/go-apigen-server/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/gemyago/apigen/examples/go-apigen-server

go 1.22
go 1.23

require golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8
require golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa
2 changes: 2 additions & 0 deletions examples/go-apigen-server/go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 h1:yixxcjnhBmY0nkL253HFVIm0JsFHwrHdT3Yh6szTnfY=
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI=
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa h1:ELnwvuAXPNtPk1TJRuGkI9fDTwym6AYBu0qzT8AcHdI=
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
178 changes: 76 additions & 102 deletions examples/go-apigen-server/pkg/api/http/v1routes/handlers/handlers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading