-
Notifications
You must be signed in to change notification settings - Fork 3
chore: refactor package layout #15
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,3 +27,4 @@ profile.cov | |
| # .idea/ | ||
| # .vscode/ | ||
| .mcp.json | ||
| .worktrees | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| all: false | ||
| dir: '{{.InterfaceDir}}' | ||
| filename: mocks_test.go | ||
| force-file-write: true | ||
| formatter: goimports | ||
| include-auto-generated: false | ||
| log-level: info | ||
| structname: '{{.Mock}}{{.InterfaceName}}' | ||
| pkgname: '{{.SrcPackageName}}' | ||
| recursive: false | ||
| require-template-schema-exists: true | ||
| template: matryer | ||
| template-schema: '{{.Template}}.schema.json' | ||
| packages: | ||
| github.com/go-openapi/codescan/internal/ifaces: | ||
| config: | ||
| dir: internal/scantest/mocks | ||
| filename: mocks.go | ||
| pkgname: 'mocks' | ||
| force-file-write: true | ||
| all: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package codescan | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/go-openapi/codescan/internal/builders/spec" | ||
| "github.com/go-openapi/codescan/internal/scanner" | ||
| oaispec "github.com/go-openapi/spec" | ||
| ) | ||
|
|
||
| // Options for the scanner. | ||
| type Options = scanner.Options | ||
|
|
||
| // Run the scanner to produce a swagger spec with the options provided. | ||
| func Run(opts *Options) (*oaispec.Swagger, error) { // TODO(fred/claude): use option functors pattern | ||
| ctx, err := scanner.NewScanCtx(opts) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("could not scan source: %w: %w", err, ErrCodeScan) | ||
| } | ||
|
|
||
| builder := spec.NewBuilder(opts.InputSpec, ctx, opts.ScanModels) // TODO(fred/claude): use option functors pattern | ||
| sp, err := builder.Build() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("could not build spec: %w: %w", err, ErrCodeScan) | ||
| } | ||
|
|
||
| return sp, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package codescan | ||
|
|
||
| import ( | ||
| "flag" | ||
| "io" | ||
| "log" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/go-openapi/testify/v2/require" | ||
| ) | ||
|
|
||
| // Public-API smoke suite. Fixture-heavy tests live in internal/integration. | ||
|
|
||
| var enableDebug bool //nolint:gochecknoglobals // test flag registered in init | ||
|
|
||
| func init() { //nolint:gochecknoinits // registers test flags before TestMain | ||
| flag.BoolVar(&enableDebug, "enable-debug", false, "enable debug output in tests") | ||
| } | ||
|
|
||
| func TestMain(m *testing.M) { | ||
| flag.Parse() | ||
|
|
||
| if !enableDebug { | ||
| log.SetOutput(io.Discard) | ||
| } else { | ||
| log.SetFlags(log.LstdFlags | log.Lshortfile) | ||
| log.SetOutput(os.Stderr) | ||
| } | ||
|
|
||
| os.Exit(m.Run()) | ||
| } | ||
|
|
||
| func TestApplication_DebugLogging(t *testing.T) { | ||
| // Exercises the logger.DebugLogf code path with Debug: true. | ||
| _, err := Run(&Options{ | ||
| Packages: []string{"./goparsing/petstore/..."}, | ||
| WorkDir: "fixtures", | ||
| ScanModels: true, | ||
| Debug: true, | ||
| }) | ||
|
|
||
| require.NoError(t, err) | ||
| } | ||
|
|
||
| func TestRun_InvalidWorkDir(t *testing.T) { | ||
| // Exercises the Run() error path when package loading fails. | ||
| _, err := Run(&Options{ | ||
| Packages: []string{"./..."}, | ||
| WorkDir: "/nonexistent/directory", | ||
| }) | ||
|
|
||
| require.Error(t, err) | ||
| } | ||
|
|
||
| func TestSetEnumDoesNotPanic(t *testing.T) { | ||
| // Regression: ensure Run() does not panic on minimal source with an enum. | ||
| dir := t.TempDir() | ||
|
|
||
| src := ` | ||
| package failure | ||
|
|
||
| // swagger:model Order | ||
| type Order struct { | ||
| State State ` + "`json:\"state\"`" + ` | ||
| } | ||
|
|
||
| // State represents the state of an order. | ||
| // enum: ["created","processed"] | ||
| type State string | ||
| ` | ||
| err := os.WriteFile(filepath.Join(dir, "model.go"), []byte(src), 0o600) | ||
| require.NoError(t, err) | ||
|
|
||
| goMod := ` | ||
| module failure | ||
| go 1.23` | ||
| err = os.WriteFile(filepath.Join(dir, "go.mod"), []byte(goMod), 0o600) | ||
| require.NoError(t, err) | ||
|
|
||
| _, err = Run(&Options{ | ||
| WorkDir: dir, | ||
| ScanModels: true, | ||
| }) | ||
|
|
||
| require.NoError(t, err) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.