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
18 changes: 18 additions & 0 deletions plugins/pacto-plugin-openapi-infer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ pacto generate openapi-infer . --option output=interfaces/openapi.json
pacto generate openapi-infer . --option output=api/spec.yaml
```

### `source` (optional)

Path to the directory containing the source code to scan. This is useful when
the source code lives outside the bundle directory (e.g., the Go source is at
the repository root while the bundle is in `pactos/my-service/`).

- **Default**: the bundle directory itself
- Relative paths are resolved relative to the bundle directory
- Absolute paths are used as-is

```bash
# Source code is two levels up from the bundle directory
pacto generate openapi-infer pactos/my-service --option source=../..

# Absolute path
pacto generate openapi-infer pactos/my-service --option source=/path/to/repo
```

### `framework` (optional)

Override automatic framework detection. Useful when the project has
Expand Down
16 changes: 14 additions & 2 deletions plugins/pacto-plugin-openapi-infer/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,28 @@ func main() {
format = infer.FormatJSON
}

// Allow overriding the source directory via --option source=DIR.
// This is useful when the Go/Python source lives outside the bundle
// directory (e.g., repo root vs pactos/my-bundle/).
sourceDir := req.BundleDir
if src, _ := req.Options["source"].(string); src != "" {
if filepath.IsAbs(src) {
sourceDir = src
} else {
sourceDir = filepath.Join(req.BundleDir, src)
}
}

var spec string
var fw infer.Framework
var err error

// Allow explicit framework override via --option framework=X.
if fwStr, _ := req.Options["framework"].(string); fwStr != "" {
fw = infer.Framework(strings.ToLower(fwStr))
spec, err = infer.InferWithFramework(req.BundleDir, fw, format)
spec, err = infer.InferWithFramework(sourceDir, fw, format)
} else {
spec, fw, err = infer.Infer(req.BundleDir, format)
spec, fw, err = infer.Infer(sourceDir, format)
}

if err != nil {
Expand Down
Loading