Skip to content

Commit 82bb425

Browse files
committed
refactor!: move generated plugin clients to top-level plugins/
Delete the hand-written v4 plugins/{ism,security} clients and promote the spec-generated tree from opensearchapi/plugins/ to top-level plugins/ (import path .../v5/plugins/<name>). The generated clients cover all 25 plugins and supersede the 2 hand-written ones. Retarget cmd/osgen (DefaultPluginsImportBase, importPathForGroup) and the Makefile to emit at plugins/, and add plugins/ to the check-gen diff. BREAKING CHANGE: plugin import paths move from github.com/opensearch-project/opensearch-go/v4/plugins/{ism,security} to github.com/opensearch-project/opensearch-go/v5/plugins/<name>. Signed-off-by: Sean Chittenden <sean.chittenden@crowdstrike.com>
1 parent 45eb5f2 commit 82bb425

1,186 files changed

Lines changed: 1690 additions & 8685 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/check-gen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
run: make -j gen
1818
- name: Check for diff
1919
run: |
20-
if ! git diff --exit-code internal/path/builders_gen.go internal/path/builders_gen_test.go opensearchapi/; then
20+
if ! git diff --exit-code internal/path/builders_gen.go internal/path/builders_gen_test.go opensearchapi/ plugins/; then
2121
echo "::warning::Generated code is out of date. Run 'make gen' and commit the result."
2222
exit 1
2323
fi

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ linters:
162162
path: opensearchtransport/opensearchtransport.go
163163
- linters:
164164
- dupl
165-
path: (-params\.go|api_indices|api_dangling\.go|api_point_in_time\.go|rethrottle\.go|api_cat-.*\.go|plugins/security/api_\w+.go|plugins/security/api_.*-patch.go|_gen\.go)
165+
path: (-params\.go|api_indices|api_dangling\.go|api_point_in_time\.go|rethrottle\.go|api_cat-.*\.go|_gen\.go)
166166
# Generated code emits long lines from upstream spec descriptions, table
167167
# rows, and inline struct literals that lose readability if wrapped at the
168168
# template level.

DEVELOPER_GUIDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ make gh.checks.failed # Only failed checks
385385

386386
## Code Generation
387387

388-
The `cmd/osgen` tool generates typed path builder structs (`internal/path/`) and API consumer files (`opensearchapi/`, `opensearchapi/plugins/`) from the published [OpenSearch API specification](https://github.com/opensearch-project/opensearch-api-specification). It reads `x-operation-group`, `x-version-added`, `x-version-deprecated`, `x-version-removed`, and `x-error-responses` extensions from the spec to produce version-aware Go source.
388+
The `cmd/osgen` tool generates typed path builder structs (`internal/path/`) and API consumer files (`opensearchapi/`, `plugins/`) from the published [OpenSearch API specification](https://github.com/opensearch-project/opensearch-api-specification). It reads `x-operation-group`, `x-version-added`, `x-version-deprecated`, `x-version-removed`, and `x-error-responses` extensions from the spec to produce version-aware Go source.
389389

390390
The `opensearchapi/` package is the code-generated v5 API surface, produced by `cmd/osgen` from the spec. See `opensearchapi/README.md` for usage and `UPGRADING.md` for migration guidance.
391391

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ OPENAPI_SPEC_URL := https://github.com/opensearch-project/opensearch-api-specifi
160160
# Generated code output directories.
161161
GEN_PATH_DIR := $(REPO_ROOT)/internal/path
162162
GEN_OSAPI_DIR := $(REPO_ROOT)/opensearchapi
163-
GEN_PLUGINS_DIR := $(GEN_OSAPI_DIR)/plugins
163+
GEN_PLUGINS_DIR := $(REPO_ROOT)/plugins
164164

165165
# Version filtering defaults for code generation.
166166
# Override on the command line to scope generated code to a version window:

UPGRADING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ client, err := opensearchapi.NewClient(opensearchapi.Config{...})
205205
- Optional `Params` are `*Params` pointer fields (nil-safe; pass `&opensearchapi.IndexParams{...}` to set).
206206
- Optional boolean query parameters are `*bool` so a deliberate `false` can be sent over the wire.
207207
- Multi-index `Req` types use `Index []string` (the spec spelling); v4's hand-written `Indices` is renamed.
208-
- Plugin APIs (k-NN, ML, Security, ISM, etc.) live in `opensearchapi/plugins/`.
208+
- Plugin APIs (k-NN, ML, Security, ISM, etc.) live in top-level `plugins/<name>` packages, imported as `github.com/opensearch-project/opensearch-go/v5/plugins/<name>`. v4's hand-written plugin clients (`opensearch-go/v4/plugins/{ism,security}`) are replaced by generated, spec-driven clients covering all 25 plugins; the package qualifier (e.g. `ism.X`) is unchanged.
209209

210210
For the full v4 -> v5 surface delta and the optional forward-compatible `replace` directive, see [`opensearchapi/MIGRATING.md`](opensearchapi/MIGRATING.md). For everyday usage (errors, routing, response handling) see [`opensearchapi/README.md`](opensearchapi/README.md).
211211

cmd/osgen/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Generates API consumer files into `opensearchapi/` and plugin directories.
8989
| `-spec` | required | Path to the combined OpenAPI spec YAML |
9090
| `-out` | required | Output directory for core API files (e.g. `opensearchapi/`) |
9191
| `-pkg` | required | Go package name for generated files (e.g. `opensearchapi`) |
92-
| `-plugins-out` | (none) | Output directory for plugin files (e.g. `opensearchapi/plugins/`) |
92+
| `-plugins-out` | (none) | Output directory for plugin files (e.g. `plugins/`) |
9393
| `-groups` | (all) | Comma-separated `x-operation-group` filter |
9494
| `-min-version` | `epoch` | Minimum OpenSearch version (default operator: `>=`) |
9595
| `-max-version` | `latest` | Maximum OpenSearch version (default operator: `<=`) |
@@ -111,7 +111,7 @@ go run . api \
111111
-spec ../../opensearch-openapi.yaml \
112112
-out ../../opensearchapi \
113113
-pkg opensearchapi \
114-
-plugins-out ../../opensearchapi/plugins
114+
-plugins-out ../../plugins
115115
```
116116

117117
Generate a single operation:

cmd/osgen/api_cmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func runAPI() error {
3636
specPath := fs.String("spec", "", "path to OpenAPI spec YAML (single combined file)")
3737
groups := fs.String("groups", "", "comma-separated x-operation-group names (empty = all)")
3838
outDir := fs.String("out", "", "output directory for core API files (opensearchapi/)")
39-
pluginsDir := fs.String("plugins-out", "", "output directory for plugin files (opensearchapi/plugins/)")
39+
pluginsDir := fs.String("plugins-out", "", "output directory for plugin files (plugins/)")
4040
pkg := fs.String("pkg", opensearchAPIPkgName, "Go package name for core API output")
4141
minVer := fs.String("min-version", versionEpoch, "minimum OpenSearch version (default operator: >=)")
4242
maxVer := fs.String("max-version", versionLatest, "maximum OpenSearch version (default operator: <=)")
@@ -54,7 +54,7 @@ func runAPI() error {
5454
}
5555

5656
if *specPath == "" || *outDir == "" {
57-
return fmt.Errorf("usage: osgen api -spec <openapi-spec.yaml> -out <dir/> [-pkg <name>] -plugins-out <opensearchapi/plugins/>")
57+
return fmt.Errorf("usage: osgen api -spec <openapi-spec.yaml> -out <dir/> [-pkg <name>] -plugins-out <plugins/>")
5858
}
5959

6060
var filter map[string]bool

cmd/osgen/emit/build.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,11 +1350,12 @@ func routeOp(group, outDir, pluginsDir string) (string, string) {
13501350

13511351
func importPathForGroup(group, corePkg, modulePath string) string {
13521352
prefix := groupPrefixIR(group)
1353-
core := coreImportPath(corePkg, modulePath)
13541353
if coreGroupPrefixes[prefix] {
1355-
return core
1354+
return coreImportPath(corePkg, modulePath)
13561355
}
1357-
return core + "/plugins/" + prefix
1356+
// Plugin packages are siblings of the core package at the module root,
1357+
// not nested under it.
1358+
return modulePath + "/" + ir.DefaultPluginsSubpath + "/" + prefix
13581359
}
13591360

13601361
// coreImportPath returns the full import path for the core API package.

cmd/osgen/ir/defaults.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ const (
2323
// DefaultCoreImportPath is the full Go import path for the core API package.
2424
DefaultCoreImportPath = ModulePath + "/" + DefaultCoreSubpath
2525

26+
// DefaultPluginsSubpath is the relative path (within the module) where the
27+
// generated plugin packages live. Plugins are siblings of the core package
28+
// at the module root, not nested under it.
29+
DefaultPluginsSubpath = "plugins"
30+
2631
// DefaultPluginsImportBase is the import-path prefix for plugin packages.
27-
DefaultPluginsImportBase = DefaultCoreImportPath + "/plugins"
32+
DefaultPluginsImportBase = ModulePath + "/" + DefaultPluginsSubpath
2833
)

cmd/osgen/naming_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestTitleSegment(t *testing.T) {
5858

5959
// TestPathBuilderName verifies the mapping from x-operation-group to path
6060
// builder struct name. These struct names appear in internal/path/builders_gen.go
61-
// and are referenced by consumer files in opensearchapi/ and opensearchapi/plugins/ via their
61+
// and are referenced by consumer files in opensearchapi/ and plugins/ via their
6262
// GetRequest() methods. The naming must stay deterministic across regeneration.
6363
func TestPathBuilderName(t *testing.T) {
6464
t.Parallel()
@@ -198,19 +198,19 @@ func TestOperationFilename(t *testing.T) {
198198
{name: "core leaf", group: "search", want: "opensearchapi/search_gen.go"},
199199
{name: "core dotted", group: "indices.create", want: "opensearchapi/indices-create_gen.go"},
200200
{name: "_core stripped", group: "_core.search", want: "opensearchapi/search_gen.go"},
201-
{name: "plugin leaf", group: "knn.stats", want: "opensearchapi/plugins/knn/stats_gen.go"},
202-
{name: "plugin underscore", group: "ism.add_policy", want: "opensearchapi/plugins/ism/add_policy_gen.go"},
201+
{name: "plugin leaf", group: "knn.stats", want: "plugins/knn/stats_gen.go"},
202+
{name: "plugin underscore", group: "ism.add_policy", want: "plugins/ism/add_policy_gen.go"},
203203
{
204204
name: "plugin multi word",
205205
group: "security.reload_http_certificates",
206-
want: "opensearchapi/plugins/security/reload_http_certificates_gen.go",
206+
want: "plugins/security/reload_http_certificates_gen.go",
207207
},
208208
}
209209

210210
for _, tt := range tests {
211211
t.Run(tt.name, func(t *testing.T) {
212212
t.Parallel()
213-
_, dir := routeOperation(tt.group, ir.DefaultCoreSubpath, ir.DefaultCoreSubpath+"/plugins")
213+
_, dir := routeOperation(tt.group, ir.DefaultCoreSubpath, ir.DefaultPluginsSubpath)
214214
got := dir + "/" + operationFilename(tt.group) + genFileSuffix
215215
require.Equal(t, tt.want, got)
216216
})

0 commit comments

Comments
 (0)