Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/HEAD' into defect/embedded-spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Tanna committed Oct 10, 2022
2 parents 1633023 + 45eb6bd commit b765380
Show file tree
Hide file tree
Showing 20 changed files with 180 additions and 393 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
with:
go-version-file: 'go.mod'

- name: Run `make tidy`
run: make tidy
- name: Install `tidied`
run: go install gitlab.com/jamietanna/tidied@latest

- name: Check for no untracked files
run: git diff-index --quiet HEAD --
run: tidied -verbose
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ which help you to use the various OpenAPI 3 Authentication mechanism.
will override any default value. This extended property isn't supported in all parts of
OpenAPI, so please refer to the spec as to where it's allowed. Swagger validation tools will
flag incorrect usage of this property.
- `x-go-json-ignore`: sets tag to `-` to ignore the field in json completely.
- `x-oapi-codegen-extra-tags`: adds extra Go field tags to the generated struct field. This is
useful for interfacing with tag based ORM or validation libraries. The extra tags that
are added are in addition to the regular json tags that are generated. If you specify your
Expand Down Expand Up @@ -687,8 +688,6 @@ package: externalref
generate:
models: true
embedded-spec: true
output-options:
skip-prune: true
import-mapping:
./packageA/spec.yaml: github.com/deepmap/oapi-codegen/internal/test/externalref/packageA
./packageB/spec.yaml: github.com/deepmap/oapi-codegen/internal/test/externalref/packageB
Expand Down
31 changes: 15 additions & 16 deletions cmd/oapi-codegen/oapi-codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"path"
"runtime/debug"
Expand Down Expand Up @@ -126,7 +125,7 @@ func main() {
if oldConfigStyle == nil && (flagConfigFile != "") {
configFile, err := os.ReadFile(flagConfigFile)
if err != nil {
errExit("error reading config file '%s': %v", flagConfigFile, err)
errExit("error reading config file '%s': %v\n", flagConfigFile, err)
}
var oldConfig oldConfiguration
oldErr := yaml.UnmarshalStrict(configFile, &oldConfig)
Expand All @@ -143,7 +142,7 @@ func main() {
t := true
oldConfigStyle = &t
} else if oldErr != nil && newErr != nil {
errExit("error parsing configuration style as old version or new version: %v", err)
errExit("error parsing configuration style as old version or new version: %v\n", err)
}
// Else we fall through, and we still don't know, so we need to infer it from flags.
}
Expand Down Expand Up @@ -182,30 +181,30 @@ func main() {
if !*oldConfigStyle {
// We simply read the configuration from disk.
if flagConfigFile != "" {
buf, err := ioutil.ReadFile(flagConfigFile)
buf, err := os.ReadFile(flagConfigFile)
if err != nil {
errExit("error reading config file '%s': %v", flagConfigFile, err)
errExit("error reading config file '%s': %v\n", flagConfigFile, err)
}
err = yaml.Unmarshal(buf, &opts)
if err != nil {
errExit("error parsing'%s' as YAML: %v", flagConfigFile, err)
errExit("error parsing'%s' as YAML: %v\n", flagConfigFile, err)
}
}
var err error
opts, err = updateConfigFromFlags(opts)
if err != nil {
errExit("error processing flags: %v", err)
errExit("error processing flags: %v\n", err)
}
} else {
var oldConfig oldConfiguration
if flagConfigFile != "" {
buf, err := ioutil.ReadFile(flagConfigFile)
buf, err := os.ReadFile(flagConfigFile)
if err != nil {
errExit("error reading config file '%s': %v", flagConfigFile, err)
errExit("error reading config file '%s': %v\n", flagConfigFile, err)
}
err = yaml.Unmarshal(buf, &oldConfig)
if err != nil {
errExit("error parsing'%s' as YAML: %v", flagConfigFile, err)
errExit("error parsing'%s' as YAML: %v\n", flagConfigFile, err)
}
}
opts = newConfigFromOldConfig(oldConfig)
Expand All @@ -217,14 +216,14 @@ func main() {

// Now, ensure that the config options are valid.
if err := opts.Validate(); err != nil {
errExit("configuration error: %v", err)
errExit("configuration error: %v\n", err)
}

// If the user asked to output configuration, output it to stdout and exit
if flagOutputConfig {
buf, err := yaml.Marshal(opts)
if err != nil {
errExit("error YAML marshaling configuration: %v", err)
errExit("error YAML marshaling configuration: %v\n", err)
}
fmt.Print(string(buf))
return
Expand All @@ -241,9 +240,9 @@ func main() {
}

if opts.OutputFile != "" {
err = ioutil.WriteFile(opts.OutputFile, []byte(code), 0644)
err = os.WriteFile(opts.OutputFile, []byte(code), 0644)
if err != nil {
errExit("error writing generated code to file: %s", err)
errExit("error writing generated code to file: %s\n", err)
}
} else {
fmt.Print(code)
Expand All @@ -257,7 +256,7 @@ func loadTemplateOverrides(templatesDir string) (map[string]string, error) {
return templates, nil
}

files, err := ioutil.ReadDir(templatesDir)
files, err := os.ReadDir(templatesDir)
if err != nil {
return nil, err
}
Expand All @@ -276,7 +275,7 @@ func loadTemplateOverrides(templatesDir string) (map[string]string, error) {
}
continue
}
data, err := ioutil.ReadFile(path.Join(templatesDir, f.Name()))
data, err := os.ReadFile(path.Join(templatesDir, f.Name()))
if err != nil {
return nil, err
}
Expand Down
65 changes: 46 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,64 @@ module github.com/deepmap/oapi-codegen

require (
github.com/apapsch/go-jsonmerge/v2 v2.0.0
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/getkin/kin-openapi v0.94.0
github.com/gin-gonic/gin v1.7.7
github.com/cyberdelia/templates v1.0.0
github.com/getkin/kin-openapi v0.104.0
github.com/gin-gonic/gin v1.8.1
github.com/go-chi/chi/v5 v5.0.7
github.com/go-openapi/swag v0.21.1 // indirect
github.com/go-playground/validator/v10 v10.11.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golangci/lint-1 v0.0.0-20181222135242-d2cdd8c08219
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0
github.com/json-iterator/go v1.1.12 // indirect
github.com/labstack/echo/v4 v4.9.0
github.com/lestrrat-go/blackmagic v1.0.1 // indirect
github.com/lestrrat-go/iter v1.0.2 // indirect
github.com/lestrrat-go/jwx v1.2.24
github.com/mailru/easyjson v0.7.7 // indirect
github.com/lestrrat-go/jwx v1.2.25
github.com/matryer/moq v0.2.7
github.com/stretchr/testify v1.8.0
golang.org/x/tools v0.1.12
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/swag v0.21.1 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.11.0 // indirect
github.com/goccy/go-json v0.9.7 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/invopop/yaml v0.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/labstack/gommon v0.3.1 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lestrrat-go/backoff/v2 v2.0.8 // indirect
github.com/lestrrat-go/blackmagic v1.0.0 // indirect
github.com/lestrrat-go/httpcc v1.0.1 // indirect
github.com/lestrrat-go/iter v1.0.1 // indirect
github.com/lestrrat-go/option v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/stretchr/testify v1.7.1
github.com/ugorji/go v1.2.7 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
golang.org/x/crypto v0.0.0-20220513210258-46612604a0f9 // indirect
golang.org/x/net v0.0.0-20220513224357-95641704303c // indirect
golang.org/x/sys v0.0.0-20220513210249-45d2b4557a2a // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
golang.org/x/tools v0.1.10
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1 // indirect
)

go 1.16
go 1.18

0 comments on commit b765380

Please sign in to comment.