From 9482e71546566b31a9469228e48fb9658189f291 Mon Sep 17 00:00:00 2001 From: Daniel O'Grady Date: Thu, 3 Sep 2026 09:59:03 +0200 Subject: [PATCH] feat: support @openapi.type and @openapi.default on custom parameters --- CHANGELOG.md | 1 + lib/compile/csdl2openapi.js | 3 ++- test/lib/compile/data/custom-parameters.json | 13 +++++++++++++ .../data/custom-parameters.openapi3.json | 19 +++++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7be42e..50068e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). ## [Unreleased] ### Added +- Support `@openapi.type` and `@openapi.default` annotations on `CustomParameter` records (`CustomHeaders`/`CustomQueryOptions`) to emit the correct schema type and default value instead of always defaulting to `schema.type: "string"` ### Changed ### Deprecated ### Removed diff --git a/lib/compile/csdl2openapi.js b/lib/compile/csdl2openapi.js index 2fddefd..c1dc213 100644 --- a/lib/compile/csdl2openapi.js +++ b/lib/compile/csdl2openapi.js @@ -844,7 +844,8 @@ module.exports.csdl2openapi = function ( required: custom.Required || false, ...(custom.Description && { description: custom.Description }), schema: { - type: "string", + type: custom['@openapi.type'] || "string", + ...(custom['@openapi.default'] !== undefined && { default: custom['@openapi.default'] }), ...(custom.DocumentationURL && { externalDocs: { url: custom.DocumentationURL }, }), diff --git a/test/lib/compile/data/custom-parameters.json b/test/lib/compile/data/custom-parameters.json index b6792fd..01fb608 100644 --- a/test/lib/compile/data/custom-parameters.json +++ b/test/lib/compile/data/custom-parameters.json @@ -194,6 +194,19 @@ "Value": "example" } ] + }, + { + "Name": "custom-insert-typed", + "Description": "Custom Header with explicit boolean type and default", + "Required": false, + "@openapi.type": "boolean", + "@openapi.default": true + }, + { + "Name": "custom-insert-integer", + "Description": "Custom Header with explicit integer type", + "Required": false, + "@openapi.type": "integer" } ], "CustomQueryOptions": [ diff --git a/test/lib/compile/data/custom-parameters.openapi3.json b/test/lib/compile/data/custom-parameters.openapi3.json index a194804..42ad6db 100644 --- a/test/lib/compile/data/custom-parameters.openapi3.json +++ b/test/lib/compile/data/custom-parameters.openapi3.json @@ -283,6 +283,25 @@ } } }, + { + "name": "custom-insert-typed", + "in": "header", + "required": false, + "description": "Custom Header with explicit boolean type and default", + "schema": { + "type": "boolean", + "default": true + } + }, + { + "name": "custom-insert-integer", + "in": "header", + "required": false, + "description": "Custom Header with explicit integer type", + "schema": { + "type": "integer" + } + }, { "name": "customInsert", "in": "query",