Skip to content

Commit 475de78

Browse files
Copilotintel352
andauthored
fix(openapi): address remaining unresolved review comments on OpenAPI module (#149)
* Initial plan * fix(openapi): document deferred spec_file validation and add enum scalar tests Co-authored-by: intel352 <77607+intel352@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
1 parent 6f5d7ee commit 475de78

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

module/openapi_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,12 @@ func TestValidateScalarValue(t *testing.T) {
516516
{"string too long", "toolongstring", &openAPISchema{Type: "string", MaxLength: &maxLen}, true},
517517
{"enum match", "cat", &openAPISchema{Type: "string", Enum: []any{"cat", "dog"}}, false},
518518
{"enum mismatch", "fish", &openAPISchema{Type: "string", Enum: []any{"cat", "dog"}}, true},
519+
// Query/path parameters are always strings; integer enum values from YAML
520+
// (e.g. enum: [1, 2, 3]) are compared as their string representation.
521+
// This is intentional: the parameter "1" should match the YAML integer 1.
522+
{"enum integer yaml matches string param", "1", &openAPISchema{Type: "integer", Enum: []any{1, 2, 3}}, false},
523+
{"enum integer yaml no match", "4", &openAPISchema{Type: "integer", Enum: []any{1, 2, 3}}, true},
524+
{"enum nil values skipped", "a", &openAPISchema{Enum: []any{nil, "a", nil}}, false},
519525
}
520526

521527
for _, tt := range tests {

plugins/openapi/plugin.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ func (p *Plugin) ModuleFactories() map[string]plugin.ModuleFactory {
5858
"openapi": func(name string, cfg map[string]any) modular.Module {
5959
oacfg := module.OpenAPIConfig{}
6060

61+
// NOTE: spec_file existence is not validated here at configuration time.
62+
// Path resolution is performed by ResolvePathInConfig (relative to the
63+
// config file directory via the _config_dir key), but file existence and
64+
// readability are checked lazily during Init(). Errors will surface at
65+
// engine startup, after all modules have been constructed.
6166
if v, ok := cfg["spec_file"].(string); ok {
6267
oacfg.SpecFile = config.ResolvePathInConfig(cfg, v)
6368
}

0 commit comments

Comments
 (0)