diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d9ed33..1fc6cc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ 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"` - Added `defaultProtocol` configuration option as fallback if no config is provided. + ### Changed - set `odata` as the service protocol if no protocol is set to match the default behavior of `@sap/cds`. Provide `cds.env.openapi.defaultProtocol = "rest"` to restore old behavior. ### Deprecated 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",