Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
feat(config): declare a templated default server in the OpenAPI spec (#975)
Yudhi Armyndharis14f73b844952
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c0646f40e..6cbdd4809 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -18,6 +18,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0connection. Credentials authenticate on the socket itself, so the Chromium first-CONNECT 407limitation that can bite the wwjs engine's proxy-auth path does not apply to this engine.+- **The OpenAPI spec now declares a templated default server.** `servers` was empty; it now carries+ `http://{host}:{port}` with `localhost`/`2785` defaults, so Swagger UI's "Try it" works out of the+ box and stays usable on real deployments via the host/port variables, and static consumers of the+ published `openapi.json` get a concrete base URL to display.+### Fixed- **A source install without the GNU `patch` binary no longer silently ships an unpatcheddiff --git a/openapi.json b/openapi.jsonindex ba8c7eafb..eb78b9aaf 100644--- a/openapi.json+++ b/openapi.json@@ -5916,7 +5916,21 @@"description": "Health check endpoints"}],- "servers": [],+ "servers": [+ {+ "url": "http://{host}:{port}",+ "description": "OpenWA instance",+ "variables": {+ "host": {+ "default": "localhost"+ },+ "port": {+ "default": "2785",+ "description": "PORT env var"+ }+ }+ }+ ],"components": {"securitySchemes": {"X-API-Key": {diff --git a/src/config/swagger.config.spec.ts b/src/config/swagger.config.spec.tsindex 90369ded7..9f973e4c5 100644--- a/src/config/swagger.config.spec.ts+++ b/src/config/swagger.config.spec.ts@@ -24,6 +24,16 @@ describe('createSwaggerConfig', () => {// requirement would falsely claim every route accepts it.expect(config.security).not.toContainEqual({ [METRICS_BEARER_SCHEME]: [] });});++ it('declares a templated default server so published specs carry a base URL', () => {+ const config = createSwaggerConfig();++ expect(config.servers).toHaveLength(1);+ const [server] = config.servers ?? [];+ expect(server.url).toBe('http://{host}:{port}');+ expect(server.variables?.host.default).toBe('localhost');+ expect(server.variables?.port.default).toBe('2785');+ });});describe('exemptPublicOperations', () => {diff --git a/src/config/swagger.config.ts b/src/config/swagger.config.tsindex fc7747fa3..b308d3e3e 100644--- a/src/config/swagger.config.ts+++ b/src/config/swagger.config.ts@@ -96,6 +96,14 @@ export function createSwaggerConfig(): Omit<OpenAPIObject, 'paths'> {.addTag('audit', 'Audit log').addTag('metrics', 'Prometheus metrics').addTag('health', 'Health check endpoints')+ // Templated server: defaults to the out-of-box local instance, and the {host}/{port}+ // variables keep Swagger UI "Try it" usable on real deployments (a hardcoded+ // localhost URL would break Try-it for anyone serving elsewhere). Static consumers+ // of the spec (the docs site) also get a concrete base URL to display.+ .addServer('http://{host}:{port}', 'OpenWA instance', {+ host: { default: 'localhost' },+ port: { default: '2785', description: 'PORT env var' },+ }).build());}