Skip to content

Commit fbcb5d8

Browse files
committed
split packages as modules
This PR transforms the "swag" package into a mono repo, which exposes a collection of independant go modules. The objective is to reduce the footprint of required dependencies. To remain fully backward-compatible, the swag module imports all the newly created (sub) modules, for programs that consume its deprecated API. ci: ci automation, test coverage reporting and dependabot configuration have been adapted to support this new mono-repo structure. Signed-off-by: Frederic BIDON <[email protected]>
1 parent f024303 commit fbcb5d8

File tree

29 files changed

+524
-46
lines changed

29 files changed

+524
-46
lines changed

.github/dependabot.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
version: 2
22
updates:
33
- package-ecosystem: "github-actions"
4-
directory: "/"
4+
directories:
5+
- "**/*"
56
schedule:
67
interval: "weekly"
78
day: "friday"

.github/workflows/go-test.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,29 @@ jobs:
4444
cache: true
4545

4646
- uses: actions/checkout@v4
47-
- name: Run unit tests
47+
- name: Run unit tests on all modules in this repo
4848
shell: bash
49-
run: go test -v -race -coverprofile="coverage-${{ matrix.os }}.${{ matrix.go_version }}.out" -covermode=atomic -coverpkg=$(go list)/... ./...
49+
run: |
50+
# This script runs all tests on all modules and their subpackages.
51+
#
52+
# NOTES:
53+
# * git bash on a windows runner should support GNU find. find flags should be supported by find on macos.
54+
# * we don't attempt tricks using go work. Perhaps this will be the official way in future go releases.
55+
set -euxo pipefail
56+
57+
find . -name \*.mod -execdir pwd \; | grep -v "\.git" | sort | uniq | \
58+
while read module_dir ; do
59+
pushd "${module_dir}"
60+
# *.coverage.* pattern is automatically detected by codecov
61+
coverprofile="${module_dir##*/}.coverage.${{ matrix.os }}.${{ matrix.go_version }}.out"
62+
go test -v -race -coverprofile="${coverprofile}" -covermode=atomic -coverpkg=$(go list)/... ./...
63+
popd
64+
done
5065
5166
- name: Upload coverage to codecov
5267
uses: codecov/codecov-action@v5
5368
with:
54-
files: './coverage-${{ matrix.os }}.${{ matrix.go_version }}.out'
69+
name: Multi modules aggregated coverage
5570
flags: '${{ matrix.go_version }}-${{ matrix.os }}'
5671
fail_ci_if_error: false
5772
verbose: true

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ linters:
1414
- gocognit
1515
- godot
1616
- godox
17+
- gomoddirectives
1718
- gosmopolitan
1819
- inamedparam
1920
- ireturn

README.md

Lines changed: 86 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,89 +11,154 @@ You may also use it standalone for your projects.
1111

1212
> `swag` is one of the foundational building blocks of the go-openapi initiative.
1313
>
14-
> Most packages in `github.com/go-openapi/...` depend on it in some way.
14+
> Most repositories in `github.com/go-openapi/...` depend on it in some way.
1515
> So does the CLI tool `github.com/go-swagger/go-swagger`,
1616
> and the code generated by this tool.
1717
1818
## Contents
1919

20+
`go-openapi/swag` now exposes a collection of relatively independent modules.
21+
2022
Here is what is inside:
2123

22-
* Package `conv`
24+
* Module `cmdutils`
25+
26+
* [x] utilities to work with CLIs
27+
28+
* Module `conv`
2329

2430
* [x] convert between values and pointers for any types
2531
* [x] convert from string to builtin types (wraps `strconv`)
32+
* [x] require `./typeutils` (test dependency)
2633

27-
* Package `fileutils`
34+
* Module `fileutils`
2835

2936
* [x] file upload type
3037
* [x] search in path (deprecated)
31-
* Package `jsonname`
38+
39+
* Module `jsonname`
3240

3341
* [x] infer JSON names from go properties
3442

35-
* Package `jsonutils`
43+
* Module `jsonutils`
3644

3745
* [x] fast json concatenation
3846
* [x] read and write JSON from and to dynamic go data structures
47+
* [x] require `github.com/mailru/easyjson`
3948

40-
* Package `loading`
49+
* Module `loading`
4150

4251
* [x] load from file or http
52+
* [x] require `./yamlutils`
4353

44-
* Package `mangling`
54+
* Module `mangling`
4555

4656
* [x] name mangling for go
4757

48-
* Package `netutils`
58+
* Module `netutils`
4959

5060
* [x] host, port from address
5161

52-
* Package `stringutils`
62+
* Module `stringutils`
5363

5464
* [x] search in slice (with case-insensitive)
55-
* [x] slit/join query parameters as arrays
65+
* [x] split/join query parameters as arrays
5666

57-
* Package `typeutils`
67+
* Module `typeutils`
5868

5969
* [x] check the zero value for any type
6070

61-
* Package `yamlutils`
71+
* Module `yamlutils`
6272

6373
* [x] converting YAML to JSON
6474
* [x] loading YAML into a dynamic YAML document
75+
* [x] require `./jsonutils`
76+
* [x] require `github.com/mailru/easyjson`
77+
* [x] require `gopkg.in/yaml.v3`
6578

6679
---
6780

68-
This repo has a few dependencies outside of the standard library:
81+
The root module `github.com/go-openapi/swag` at the repo level maintains a few
82+
dependencies outside of the standard library:
6983

7084
* YAML utilities depend on `gopkg.in/yaml.v3`
7185
* JSON utilities `github.com/mailru/easyjson`
7286

87+
This is not necessarily the case for all sub-modules.
88+
7389
## Release notes
7490

75-
### v0.24.0
91+
### v0.24.0 [Unreleased]
7692

7793
With this release, we have largely modernized the API of `swag`:
78-
* The traditional `swag` API still works the same: code that imports `swag` will still
94+
95+
* The traditional `swag` API is still supported: code that imports `swag` will still
7996
compile and work the same.
8097
* A deprecation notice is published to encourage consumers of this library to adopt
81-
the newer API:
98+
the newer API
99+
* **Deprecation notice**
82100
* configuration through global variables is now deprecated, in favor of options passed as parameters
83-
* helper functions are moved to more specialized packages, which are exposed as
101+
* all helper functions are moved to more specialized packages, which are exposed as
84102
go modules. Importing such a module would reduce the footprint of dependencies.
85-
86-
Moving forward, no additional feature will be added to the `swag` API directly.
87-
However, child modules will continue to evolve or some new ones may be added in the future.
103+
* _all_ functions, variables, constants exposed by the deprecated API have now moved, so
104+
that consumers of the new API no longer need to import github.com/go-openapi/swag, but
105+
should import the desired sub-module(s).
88106

89107
**New with this release**:
90108

91109
* [x] type converters and pointer to value helpers now support generic types
92110
* [x] name mangling now support pluralized initialisms (issue #46)
93-
Strings like "contact IDs" are now recognized as such a plural form and
111+
Strings like "contact IDs" are now recognized as such a plural form and mangled as a linter would expect.
94112
* [x] performance: small improvements to reduce the overhead of convert/format wrappers (see issues #110, or PR #108)
95113
* [x] performance: name mangling utilities run ~ 10% faster (PR #115)
96114

115+
---
116+
117+
Moving forward, no additional feature will be added to the `swag` API directly.
118+
119+
However, child modules will continue to evolve or some new ones may be added in the future.
120+
121+
122+
#### Note to contributors
123+
124+
The mono-repo structure comes with some unavoidable extra pains...
125+
126+
* Testing
127+
128+
> The usual `go test ./...` command, run from the root of this repo won't work any longer to test all submodules.
129+
>
130+
> Each module constitutes an independant unit of test. So you have to run `go test` inside each module.
131+
> Or you may take a look at how this is achieved by CI
132+
> [here] https://github.com/go-openapi/swag/blob/master/.github/workflows/go-test.yml).
133+
>
134+
> There are also some alternative tricks using `go work`, for local development, if you feel comfortable with
135+
> go workspaces. Perhaps some day, we'll have a `go work test` to run all tests without any hack.
136+
137+
* Releasing
138+
139+
> Each module follows its own independant module versioning.
140+
>
141+
> So you have tags like `mangling/v0.24.0`, `fileutils/v0.24.0` etc that are used by `go mod` and `go get`
142+
> to refer to the tagged version of each module specifically.
143+
>
144+
> This means we may release patches etc to each module independently.
145+
>
146+
> We'd like to adopt the rule that modules in this repo would only differ by a patch version
147+
> (e.g. `v0.24.5` vs `v0.24.3`), and we'll level all modules whenever a minor version is introduced.
148+
>
149+
> A script in `./hack` is provided to tag all modules in one go at the same level in one go.
150+
97151
## Todos, suggestions and plans
98152

99153
All kinds of contributions are welcome.
154+
155+
A few ideas:
156+
157+
* [ ] Complete the split of dependencies to isolate easyjson from the rest
158+
* [ ] Improve mangling utilities (improve readability, support for capitalized words,
159+
better word substitution for non-letter symbols...)
160+
* [ ] Move back to this common shared pot a few of the technical features introduced by go-swagger independently
161+
(e.g. mangle go package names, search package with go modules support, ...)
162+
* [ ] Apply a similar mono-repo approach to go-openapi/strfmt which suffer from similar woes: bloated API,
163+
imposed dependency to some database driver.
164+

cmdutils/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/go-openapi/swag/cmdutils
2+
3+
go 1.20.0

conv/go.mod

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module github.com/go-openapi/swag/conv
2+
3+
require (
4+
github.com/go-openapi/swag/typeutils v0.0.0-00010101000000-000000000000
5+
github.com/stretchr/testify v1.10.0
6+
)
7+
8+
require (
9+
github.com/davecgh/go-spew v1.1.1 // indirect
10+
github.com/kr/pretty v0.2.1 // indirect
11+
github.com/pmezard/go-difflib v1.0.0 // indirect
12+
gopkg.in/yaml.v3 v3.0.1 // indirect
13+
)
14+
15+
go 1.20.0
16+
17+
replace github.com/go-openapi/swag/typeutils => ../typeutils

conv/go.sum

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
4+
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
5+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
6+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
7+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
8+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
9+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
10+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
11+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
12+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
13+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
14+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
15+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

doc.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,47 +22,51 @@
2222
//
2323
// Here is what is inside:
2424
//
25-
// Package [conv]:
25+
// Module [cmdutils]:
26+
//
27+
// - utilities to work with CLIs
28+
//
29+
// Module [conv]:
2630
//
2731
// - convert between value and pointers for builtin types
2832
// - convert from string to builtin types (wraps strconv)
2933
//
30-
// Package [fileutils]:
34+
// Module [fileutils]:
3135
//
3236
// - file upload type
3337
// - search in path
3438
//
35-
// Package [jsonname]:
39+
// Module [jsonname]:
3640
//
3741
// - json names for go properties
3842
//
39-
// Package [jsonutils]:
43+
// Module [jsonutils]:
4044
//
4145
// - fast json concatenation
4246
// - read and write JSON from and to dynamic go data structures
4347
//
44-
// Package [loading]:
48+
// Module [loading]:
4549
//
4650
// - load from file or http
4751
//
48-
// Package [mangling]:
52+
// Module [mangling]:
4953
//
5054
// - name mangling to generate clean identifiers
5155
//
52-
// Package [netutils]:
56+
// Module [netutils]:
5357
//
5458
// - host, port from address
5559
//
56-
// Package [stringutils]:
60+
// Module [stringutils]:
5761
//
5862
// - find string in list
5963
// - join/split arrays of query parameters
6064
//
61-
// Package [typeutils]:
65+
// Module [typeutils]:
6266
//
6367
// - check the zero value of any type
6468
//
65-
// Package [yamlutils]:
69+
// Module [yamlutils]:
6670
//
6771
// - converting YAML to JSON
6872
// - loading YAML into a dynamic YAML document

fileutils/go.mod

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module github.com/go-openapi/swag/fileutils
2+
3+
require github.com/stretchr/testify v1.10.0
4+
5+
require (
6+
github.com/davecgh/go-spew v1.1.1 // indirect
7+
github.com/kr/text v0.2.0 // indirect
8+
github.com/pmezard/go-difflib v1.0.0 // indirect
9+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
10+
gopkg.in/yaml.v3 v3.0.1 // indirect
11+
)
12+
13+
go 1.20.0

fileutils/go.sum

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
2+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
5+
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
6+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
7+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
8+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
9+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
10+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
11+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
12+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
13+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
14+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
15+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
16+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
17+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
18+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)