Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 1 addition & 20 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,6 @@ jobs:
go-version: stable
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v8.0.0
uses: golangci/golangci-lint-action@v9.2.0
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v2.11.3
Comment on lines 26 to 29

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 | Confidence: High

The PR removes long-commented optional configuration lines from the CI workflow, updates the golangci/golangci-lint-action from v8.0.0 to v9.2.0, and updates several dependency versions in go.mod and example/go.mod. The lint configuration .golangci.yml also disables two linters (embeddedstructfieldcheck, nilnil) and adds a complexity limit. These changes reduce technical debt but are not directly related to the bug fix. The dependency bumps may introduce slight behavioural changes in downstream libraries; however, all CI checks pass, so they are safe. No functional impact is expected.


# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the action will use pre-installed Go.
# skip-go-installation: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
7 changes: 7 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ run:
linters:
default: all
disable:
- embeddedstructfieldcheck
- nilnil
- noinlineerr
- wsl_v5
- funcorder
Expand Down Expand Up @@ -37,6 +39,8 @@ linters:
check-blank: true
gocyclo:
min-complexity: 20
cyclop:
max-complexity: 15
misspell:
locale: US
unparam:
Expand All @@ -58,6 +62,9 @@ linters:
- errcheck
- gosec
path: example_
- linters:
- revive
text: 'unused-parameter: parameter'
- linters:
- revive
text: 'var-naming: struct field'
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GOLANGCI_LINT_VERSION := "v2.11.3" # Optional configuration to pinpoint golangci-lint version.
#GOLANGCI_LINT_VERSION := "v2.11.3" # Optional configuration to pinpoint golangci-lint version.

# The head of Makefile determines location of dev-go to include standard targets.
GO ?= go
Expand Down
8 changes: 4 additions & 4 deletions example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ replace github.com/swaggest/jsonform-go => ../

require (
github.com/swaggest/jsonform-go v0.1.0
github.com/swaggest/openapi-go v0.2.58
github.com/swaggest/rest v0.2.74
github.com/swaggest/openapi-go v0.2.60
github.com/swaggest/rest v0.2.75
github.com/swaggest/swgui v1.8.4
github.com/swaggest/usecase v1.3.1
)

require (
github.com/go-chi/chi/v5 v5.2.1 // indirect
github.com/go-chi/chi/v5 v5.2.2 // indirect
github.com/santhosh-tekuri/jsonschema/v3 v3.1.0 // indirect
github.com/swaggest/form/v5 v5.1.1 // indirect
github.com/swaggest/jsonschema-go v0.3.78 // indirect
github.com/swaggest/jsonschema-go v0.3.79 // indirect
github.com/swaggest/refl v1.4.0 // indirect
github.com/vearutop/statigz v1.5.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
36 changes: 18 additions & 18 deletions example/go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
github.com/bool64/dev v0.2.25/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg=
github.com/bool64/dev v0.2.40 h1:LUSD+Aq+WB3KwVntqXstevJ0wB12ig1bEgoG8ZafsZU=
github.com/bool64/dev v0.2.40/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg=
github.com/bool64/shared v0.1.5 h1:fp3eUhBsrSjNCQPcSdQqZxxh9bBwrYiZ+zOKFkM0/2E=
github.com/bool64/shared v0.1.5/go.mod h1:081yz68YC9jeFB3+Bbmno2RFWvGKv1lPKkMP6MHJlPs=
github.com/bool64/dev v0.2.43 h1:yQ7qiZVef6WtCl2vDYU0Y+qSq+0aBrQzY8KXkklk9cQ=
github.com/bool64/dev v0.2.43/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg=
github.com/bool64/shared v0.1.6 h1:1u1IfTU84pZU285Mf1kQC5wX/VzSRE5E/+4KgFRGQ6o=
github.com/bool64/shared v0.1.6/go.mod h1:AByMlOFBjavJDk8VdFBH/atMgv1q7qrKXD1XLAQTgZA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-chi/chi/v5 v5.2.1 h1:KOIHODQj58PmL80G2Eak4WdvUzjSJSm0vG72crDCqb8=
github.com/go-chi/chi/v5 v5.2.1/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
github.com/go-chi/chi/v5 v5.2.2 h1:CMwsvRVTbXVytCk1Wd72Zy1LAsAh9GxMmSNWLHCG618=
github.com/go-chi/chi/v5 v5.2.2/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc=
github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE=
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
Expand All @@ -18,24 +18,24 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/santhosh-tekuri/jsonschema/v3 v3.1.0 h1:levPcBfnazlA1CyCMC3asL/QLZkq9pa8tQZOH513zQw=
github.com/santhosh-tekuri/jsonschema/v3 v3.1.0/go.mod h1:8kzK2TC0k0YjOForaAHdNEa7ik0fokNa2k30BKJ/W7Y=
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw=
github.com/sergi/go-diff v1.4.0/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ=
github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/swaggest/assertjson v1.10.0 h1:OYIx29UbgqjwAekKbeIO8T0XbAMyViJ8qqrVj2GQY2M=
github.com/swaggest/assertjson v1.10.0/go.mod h1:31+ufMpzrCO/daIRZ4s1UZAA1R2q9EEUfJaoczgAty8=
github.com/swaggest/form/v5 v5.1.1 h1:ct6/rOQBGrqWUQ0FUv3vW5sHvTUb31AwTUWj947N6cY=
github.com/swaggest/form/v5 v5.1.1/go.mod h1:X1hraaoONee20PMnGNLQpO32f9zbQ0Czfm7iZThuEKg=
github.com/swaggest/jsonschema-go v0.3.78 h1:5+YFQrLxOR8z6CHvgtZc42WRy/Q9zRQQ4HoAxlinlHw=
github.com/swaggest/jsonschema-go v0.3.78/go.mod h1:4nniXBuE+FIGkOGuidjOINMH7OEqZK3HCSbfDuLRI0g=
github.com/swaggest/openapi-go v0.2.58 h1:H9Nu9+XWGE1ZGU410iCg27R+d3Fhi9r3sOz1BCm5W/E=
github.com/swaggest/openapi-go v0.2.58/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk=
github.com/swaggest/jsonschema-go v0.3.79 h1:0TOShCbAJ9Xjt1e2W83l+QtMQSG2pbun2EkiYTyafCs=
github.com/swaggest/jsonschema-go v0.3.79/go.mod h1:GqVmJ+XNLeUHhFIhHNKc+C68euxfrl3a3aoZH4vTRl0=
github.com/swaggest/openapi-go v0.2.60 h1:kglHH/WIfqAglfuWL4tu0LPakqNYySzklUWx06SjSKo=
github.com/swaggest/openapi-go v0.2.60/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk=
github.com/swaggest/refl v1.4.0 h1:CftOSdTqRqs100xpFOT/Rifss5xBV/CT0S/FN60Xe9k=
github.com/swaggest/refl v1.4.0/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA=
github.com/swaggest/rest v0.2.74 h1:YyRg7pGMcOP0cvG/Wye2w/41V67pnGYREYhDzcfj+TQ=
github.com/swaggest/rest v0.2.74/go.mod h1:W4whAyygOA2vDifm3SUareWtrKeDe2XlfKsOndF8cIo=
github.com/swaggest/rest v0.2.75 h1:MW9zZ3d0kduJ2KdWnSYZIIrZJ1v3Kg+S7QZrDCZcXws=
github.com/swaggest/rest v0.2.75/go.mod h1:yw+PNgpNSdD6W46r60keVXdsBB+7SKt64i2qpeuBsq4=
github.com/swaggest/swgui v1.8.4 h1:iYxPCG69hLajio0/6vey0245AM+fvpT4ENhiFXb+KMU=
github.com/swaggest/swgui v1.8.4/go.mod h1:ct+lyINt6I70raCWwmqfgZ0ZMu3OAF4DRwrg32DDwJY=
github.com/swaggest/usecase v1.3.1 h1:JdKV30MTSsDxAXxkldLNcEn8O2uf565khyo6gr5sS+w=
Expand Down
4 changes: 4 additions & 0 deletions example/handler.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

import (
Expand All @@ -11,6 +11,10 @@
<a href="/json-form/form.html?title=Create%20user&amp;schemaName=` + r.schemaName + `&amp;submitUrl=/users&amp;submitMethod=POST&amp;successStatus=201">Create user with dynamic form</a>
<br />
<a href="/create-user">Create user with static form</a>
<br />
<a href="/nested-image">Nested object reproducer</a>
<br />
<a href="/nested-image-schema.json">Nested object raw schema JSON</a>
</div>

<ul>
Expand Down
3 changes: 3 additions & 0 deletions example/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

import (
Expand Down Expand Up @@ -30,6 +30,7 @@

jf := jsonform.NewRepository(s.OpenAPIReflector().JSONSchemaReflector())
_ = jf.Add(User{})
_ = jf.Add(Image{})
ur.schemaName = jf.Name(User{})

// Add use case handler to router.
Expand All @@ -41,6 +42,8 @@
// Static forms.
s.Get("/create-user", createUserForm(jf))
s.Get("/edit-user/{id}", editUserForm(jf, ur))
s.Get("/nested-image", nestedImageForm(jf))
s.Get("/nested-image-schema.json", nestedImageSchema(jf))

// Swagger UI endpoint at /docs.
s.Docs("/docs", swgui.New)
Expand Down
58 changes: 58 additions & 0 deletions example/usecase.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package main

import (
"context"
"encoding/json"
"log"
"net/http"
"strconv"
Expand Down Expand Up @@ -90,6 +91,63 @@
return u
}

func nestedImageForm(r *jsonform.Repository) usecase.Interactor {
u := usecase.NewInteractor(func(ctx context.Context, input struct{}, output *usecase.OutputWithEmbeddedWriter) error {
img := Image{
Path: "album/demo/sample.jpg",
Width: 2629,
Height: 1351,
Settings: ImageSettings{
Description: "Canal Saint-Martin",
HTTPSources: []string{"https://example.com/sample.jpg"},
},
}

return r.Render(output.Writer, jsonform.Page{
Title: "Nested Object Reproducer",
PrependHTML: `<div style="margin:2em">
<p>This form reproduces nested object rendering. With the fix, only nested fields such as <code>settings.description</code> should be rendered, and there should be no extra plain <code>settings</code> input.</p>
<p><a href="/nested-image-schema.json">Open raw generated form schema JSON</a></p>
</div>`,
}, jsonform.Form{
Title: "Edit Image",
SubmitMethod: http.MethodPut,
SubmitURL: "/nowhere",
Value: img,
SuccessStatus: http.StatusNoContent,
})
})

return u
}

func nestedImageSchema(r *jsonform.Repository) usecase.Interactor {
u := usecase.NewInteractor(func(ctx context.Context, input struct{}, output *json.RawMessage) error {
s := r.Schema(Image{})
if s == nil {
if err := r.Add(Image{}); err != nil {
return err
}

s = r.Schema(Image{})
}

b, err := json.MarshalIndent(s, "", " ")
if err != nil {
return err
}

raw := json.RawMessage(b)
*output = raw

return nil
})

u.SetTitle("Nested Image Schema")

return u
}

func createUser(ur *userRepo) usecase.Interactor {
u := usecase.NewInteractor(func(ctx context.Context, input User, output *struct{}) error {
ur.create(input)
Expand Down
13 changes: 13 additions & 0 deletions example/user.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

import (
Expand Down Expand Up @@ -38,6 +38,19 @@
return "User is a sample entity."
}

type ImageSettings struct {
Description string `json:"description,omitempty" formType:"textarea" title:"Description"`
HTTPSources []string `json:"http_sources,omitempty" title:"HTTP Sources"`
Rotate int `json:"rotate,omitempty" title:"Rotate"`
}

type Image struct {
Path string `json:"path" readOnly:"true" title:"Path"`
Width int `json:"width" readOnly:"true" title:"Width"`
Height int `json:"height" readOnly:"true" title:"Height"`
Settings ImageSettings `json:"settings" title:"Settings" description:"Nested image settings."`
}

type userRepo struct {
st []User
schemaName string
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/swaggest/jsonform-go
go 1.22

require (
github.com/bool64/dev v0.2.43
github.com/bool64/dev v0.2.45
github.com/stretchr/testify v1.11.1
github.com/swaggest/assertjson v1.10.0
github.com/swaggest/jsonschema-go v0.3.79
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
github.com/bool64/dev v0.2.25/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg=
github.com/bool64/dev v0.2.43 h1:yQ7qiZVef6WtCl2vDYU0Y+qSq+0aBrQzY8KXkklk9cQ=
github.com/bool64/dev v0.2.43/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg=
github.com/bool64/dev v0.2.45 h1:3nLKhAS/6Oklk3Mt2lHYSN/Cb4tdAD77KLwzeP+6eYE=
github.com/bool64/dev v0.2.45/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg=
github.com/bool64/shared v0.1.6 h1:1u1IfTU84pZU285Mf1kQC5wX/VzSRE5E/+4KgFRGQ6o=
github.com/bool64/shared v0.1.6/go.mod h1:AByMlOFBjavJDk8VdFBH/atMgv1q7qrKXD1XLAQTgZA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
2 changes: 1 addition & 1 deletion schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (r *Repository) reflect(value any, name string) (fs FormSchema, err error)

schema, err := r.reflector.Reflect(value, jsonschema.InlineRefs, jsonschema.InterceptProp(
func(params jsonschema.InterceptPropParams) error {
if !params.Processed {
if !params.Processed || params.PropertySchema.HasType(jsonschema.Object) {
return nil
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Contextual Comment]
This comment refers to code near real line 127. Anchored to nearest_changed(125) line 125.


P1 | Confidence: High

The core logic change prevents object-typed properties from being added as a whole FormItem. Previously, the condition !params.Processed added a FormItem for every property, including those with type object. Because object properties are also recursively expanded into their sub-fields, this resulted in duplicate form entries (e.g., both {"key":"user.counters"} and the expanded sub-fields of counters appeared). The fix adds an explicit check for params.PropertySchema.HasType(jsonschema.Object), causing object-typed properties to be skipped. The test file schema_test.go confirms this by removing the expected duplicates {"key":"user.counters"}, {"key":"user"}, and {"key":"neighbors[].counters"} from the golden assertion. The example code introduces an Image type with nested ImageSettings to manually verify correct rendering with nested objects. The change is correct and passes all CI checks.

Expand Down
4 changes: 1 addition & 3 deletions schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func TestRepository_AddSchema(t *testing.T) {
"html":"Arbitrary HTML code <button onclick=\"alert('hello world!');return false\">Hi</button>"
},
{"key":"user.code","type":"ace","aceMode":"ace/mode/sql"},
{"key":"user.counters"},{"key":"user"},
{
"type":"fieldhtml",
Comment on lines 64 to 66

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 | Confidence: High

The test expectations are updated to remove the duplicate items that were previously generated for object-typed properties. This correctly aligns the test with the fixed behaviour. However, the test coverage for nested objects is limited to the User struct's counters field and the Neighbors array items. The PR adds an Image struct with a nested Settings object as an example, but no dedicated unit test validates this scenario. Adding a test case that explicitly verifies the form output for a type like Image would provide stronger regression protection.

Code Suggestion:

Consider adding a test case using the `Image` type (similar to how the existing example harness works) to assert that no duplicate items appear and that all subfields are correctly listed.

"html":"Arbitrary HTML code <button onclick=\"alert('hello world!');return false\">Hi</button>"
Expand All @@ -78,8 +77,7 @@ func TestRepository_AddSchema(t *testing.T) {
{"key":"neighbors[].age","optionalToggle":true},
{"key":"neighbors[].status"},
{"key":"neighbors[].bio","type":"textarea"},
{"key":"neighbors[].code","type":"ace","aceMode":"ace/mode/sql"},
{"key":"neighbors[].counters"}
{"key":"neighbors[].code","type":"ace","aceMode":"ace/mode/sql"}
]
}
]
Expand Down
Loading