openapi: add register_routes option to disable spec-path route registration#249
openapi: add register_routes option to disable spec-path route registration#249
register_routes option to disable spec-path route registration#249Conversation
…th route registration Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
register_routes option to disable spec-path route registration
There was a problem hiding this comment.
Pull request overview
Adds a register_routes option to the openapi module so it can run in “docs-only” mode (serve /openapi.json, /openapi.yaml, and Swagger UI) without pre-registering stub handlers for every spec path, avoiding route conflicts with pipeline-trigger routing.
Changes:
- Introduces
OpenAPIConfig.RegisterRoutes *booland gates spec-path route registration on it (nil/true= current behavior;false= skip). - Exposes
register_routesin the OpenAPI plugin factory + module schema (with defaulttruefor backward compatibility). - Adds unit tests covering
register_routes=falseandnildefault behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
module/openapi.go |
Adds config field + conditional to skip spec-path route registration when disabled. |
module/openapi_test.go |
Adds tests for register_routes=false and nil defaulting to true. |
plugins/openapi/plugin.go |
Parses register_routes from config and adds it to the plugin’s module schema + defaults. |
schema/module_schema.go |
Adds register_routes to the built-in module schema registry with default config. |
| {Key: "router", Label: "Router Module", Type: FieldTypeString, Description: "Name of the http.router module to register routes on (auto-detected if omitted)", Placeholder: "my-router"}, | ||
| {Key: "register_routes", Label: "Register Routes", Type: FieldTypeBool, DefaultValue: true, Description: "When false, skip registering spec-path routes (only serve spec endpoints and Swagger UI); default true"}, | ||
| {Key: "validation", Label: "Validation", Type: FieldTypeJSON, DefaultValue: map[string]any{"request": true, "response": false}, Description: "Request/response validation settings, e.g. {\"request\": true, \"response\": false}"}, | ||
| {Key: "swagger_ui", Label: "Swagger UI", Type: FieldTypeJSON, DefaultValue: map[string]any{"enabled": false, "path": "/docs"}, Description: "Swagger UI settings, e.g. {\"enabled\": false, \"path\": \"/docs\"}"}, |
There was a problem hiding this comment.
The built-in OpenAPI ModuleSchema in this registry still doesn’t include the max_body_bytes config field, even though the OpenAPI module config struct and the OpenAPI plugin schema support it. This creates a divergence between built-in schema-driven tooling/validation and the plugin-provided schema/UI; consider adding max_body_bytes here for parity (and an appropriate DefaultValue if desired).
| {Key: "swagger_ui", Label: "Swagger UI", Type: FieldTypeJSON, DefaultValue: map[string]any{"enabled": false, "path": "/docs"}, Description: "Swagger UI settings, e.g. {\"enabled\": false, \"path\": \"/docs\"}"}, | |
| {Key: "swagger_ui", Label: "Swagger UI", Type: FieldTypeJSON, DefaultValue: map[string]any{"enabled": false, "path": "/docs"}, Description: "Swagger UI settings, e.g. {\"enabled\": false, \"path\": \"/docs\"}"}, | |
| {Key: "max_body_bytes", Label: "Max Body Bytes", Type: FieldTypeNumber, Description: "Maximum allowed request body size in bytes for validated OpenAPI operations (leave empty to use module default)", Placeholder: "1048576"}, |
|
@copilot apply changes based on the comments in this thread |
…with plugin schema Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
Done in cdad61b — added |
RegisterRoutes *boolfield toOpenAPIConfigstruct inmodule/openapi.goOpenAPIModule.RegisterRoutesto skip spec-path route registration whenregister_routes: falseplugins/openapi/plugin.goto parseregister_routesconfig keyschema/module_schema.goto includeregister_routesfieldregister_routes: falsebehavior inmodule/openapi_test.gomax_body_bytesto built-in openapi module schema inschema/module_schema.gofor parity with plugin schemaOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.