@cap-js/openapi
Turns a CDS service into an OpenAPI document, derived from the model so the description cannot drift from what is served.
Facts
Where it sits
Who is behind it
In the atlas: maintains 34@cap-jsmaintainerChristian GeorgiContributes to this
In the atlas: maintains 1, contributes to 53@chgeocorporateuserContributes to this
In the atlas: contributes to 3@corporateusercronossclkContributes to this
In the atlas: contributes to 1@cronossclkChristian SchüringsContributes to this
In the atlas: contributes to 25@cschueringsDaniel O'GradyContributes to this
In the atlas: contributes to 10@daogradyGuilherme DellagustinContributes to this
In the atlas: contributes to 27@dellagustin-sapDiptoContributes to this
In the atlas: contributes to 2@Dipto-at-sapGeethika PulaContributes to this
In the atlas: contributes to 2@Geethika-PulaHeiko TheißenContributes to this
In the atlas: contributes to 2@HeikoTheissenIsaac PalomeroContributes to this
In the atlas: contributes to 1@isaacpalomero20 contributors
Before choosing this
Conditions
LicenceSAP Developer License Agreement 3.2 CAP§ 1, 2, 3A cds-plugin is used with SAP CAP materials, or an artifact is explicitly identified as a CAP plugin or application.
- § 1 License. Productive customer applications are limited to SAP BTP or another SAP-licensed platform, and mass extraction to a non-SAP product is restricted except where solely required for SAP interoperability.
- § 2 Intellectual Property. The agreement retains SAP's rights in the covered materials and limits making APIs, tools or software available to third parties, while preserving ownership of customer applications subject to SAP's underlying rights.
- § 3 Artificial Intelligence Training. The agreement prohibits use of the covered materials and customer applications for training artificial-intelligence models or systems.
What it declares
Every artifact
- Type
- CDS plugin
- Origin
- By SAP
As a CDS plugin
- Declared for
- >=7.6
- Distributed through
- npm
Connections
Handing a service description to clients and tools
Download
Install
npm add @cap-js/openapiDerived from the package name. No recipe recorded; the README has the configuration.
README
quoted from cap-js/openapi under Apache-2.0, readOpenAPI
About this project
The @cap-js/openapi is a package that provides support for OpenAPI document compilation.
Table of Contents
Requirements and Setup
Installation
$ npm install @cap-js/openapi
Usage
const cds = require('@sap/cds')
const { compile } = require('@cap-js/openapi')
const csn = await cds.load(cds.env.folders.srv)
const openapiDocument = compile(csn)
Customizing OpenAPI Output
You can synchronously hook into the compilation process using the after:compile.to.openapi event to modify the generated OpenAPI document:
cds.on('after:compile.to.openapi', ({ csn, options, result }) => {
// Add custom vendor extensions
result['x-api-id'] = 'my-api-id'
// Enhance the info section
result.info.contact = {
name: 'API Support',
email: 'support@example.com'
}
result.info.license = {
name: 'Apache 2.0',
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
}
// Add additional servers for different environments
result.servers.push({
url: 'https://api-dev.example.com',
description: 'Development server'
})
})
The event handler receives an object with:
csn- The input CSN modeloptions- The compilation options usedresult- The generated OpenAPI document (can be modified by reference)
In the same vein, you can also subscribe to compile.to.openapi, to modify the incoming CSN before it is converted:
cds.on('compile.to.openapi', ({ csn, options }) => {
// exclude MySecretEntity from output
delete csn.definitions.MySecretEntity
})
The handler for events should never be async to avoid race conditions between the handler and the conversion process!
Contributing
This project is open to feature requests/suggestions, bug reports etc. via GitHub issues. Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our Contribution Guidelines.
Code of Conduct
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. By participating in this project, you agree to abide by its Code of Conduct at all times.
Licensing
Copyright 2023 SAP SE or an SAP affiliate company and contributors. Please see our LICENSE for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available via the REUSE tool.
History
Removed, Deprecated, Security, Features 2, Changed 2, Fixes 6
Notes
Added
- Added
defaultProtocolconfiguration option as fallback if no config is provided. - Collection responses now include the optional
@odata.nextLink/@nextLinkproperty in their schema, documenting server-driven paging as per the OData specification.
Changed
- set
odataas the service protocol if no protocol is set to match the default behavior of@sap/cds. Providecds.env.openapi.defaultProtocol = "rest"to restore old behavior. - ER diagrams are now rendered using the yuml.me v1 API (
app.yuml.me), avoiding the 'please migrate' image. The diagram and legend are displayed as clickable SVG images.
Deprecated
Removed
Fixed
@Common.Labelvalues containing i18n placeholders (e.g.{i18n>TasksPlural}) are no longer corrupted by camelCase word-splitting in tag names- Entities that are transitively autoexposed and should still be considered readonly, do not generate documentation for write endpoints anymore
- Back-reference navigation properties on child entities in compositions (the generated
parentnav pointing back up) are no longer emitted in the OpenAPI read schema - Implicitly auto-exposed composition targets (annotated
@cds.autoexposedby the CDS compiler) no longer generate top-level GET paths that CAP would reject with 405 - OpenAPI compilation is now pure: the input CSN is no longer mutated during compilation
- Services annotated with
@protocol: 'rest'no longer include a/$batchpath in the generated OpenAPI document
Security
Removed, Deprecated, Security, Features 1, Changed, Fixes 1
Notes
Added
- Support
@Validation.MinItemsand@Validation.MaxItemsannotations on collection-typed properties and action parameters to emitminItems/maxItemsin the generated OpenAPI schema
Changed
Deprecated
Removed
Fixed
@assert.range(and@Validation.Minimum/@Validation.Maximum) on properties and action parameters of typeEdm.Int32,Edm.Int16,Edm.SByte, andEdm.Bytenow correctly producesminimum/maximumin the generated OpenAPI schema
Security
- Support
Removed, Deprecated, Security, Features 1, Changed, Fixes 3
Notes
Added
- Generate media stream paths (GET and PUT) for media entities and
Edm.Streamproperties
Changed
Deprecated
Removed
Fixed
- Restore bound actions/functions on containment navigation paths (regression since v1.2.0)
- Function parameters annotated with
@mandatoryno longer lead to "Unexpected mandatory after optional parameter" error GET,PATCH, andDELETEendpoints are now exposed as navigation paths for*_textsentities
Security
- Generate media stream paths (GET and PUT) for media entities and
Security 1
Notes
Security
- Replaced unauthorized release 1.4.1 — this version is identical to 1.4.0
Security, Features 1, Changed 1, Fixes 2
Notes
Added
- Opt-in option
shortActionPathsto use simplified bound action paths (e.g.,.../Discountinstead of.../ODataDemo.Discount). Enable via{ "cds": { "openapi": { "shortActionPaths": true } } }inpackage.json.
Changed
- Removed special characters from placeholders for fields like short text, description, etc.
Fixed
- Autoexposed
.textsentities are now excluded from OpenAPI document - Generate navigation paths to CRUD-disabled entities
Security
- Opt-in option
Security, Fixes 1
Notes
Fixed
- Properties marked with
@Capabilities.ExpandRestrictions.NonExpandablePropertiesare now excluded from OpenAPI schemas
Security
- Properties marked with
Features 2, Changed 5, Fixes 3
Notes
Added
- Util to regenerate OpenAPI test snapshots
- Calling
cds compile -2 openapinow emits events:compile.to.openapiwith an object parameter, containing the source model and the compilation options before the compilation takes place.after:compile.to.openapicarries the same parameter with an additionalresultproperty, containing the output of the compilation process.
Changed
- Operations:
@Core.Descriptionmaps tosummary,@Core.LongDescriptionmaps todescription - Parameters and schema properties: use
@Core.LongDescriptionwith fallback to@Core.Description - Service info: use
@Core.LongDescriptionwith fallback to@Core.Description - Acronyms in names are now preserved and not split in description fields.
- Tags now display with spaces instead of underscores, and camelCase tags are automatically converted to space-separated words (e.g., "camelCase" becomes "camel Case").
Fixed
- Reading json from project root
- Correctly handle
@Core.Immutableproperties in PATCH requests. - Actions without parameters now include
requestBodywithContent-Type: application/jsonin OpenAPI spec to prevent 415 errors
Fixes 1
Notes
Fixed
- Upgraded qs dependency to 6.14.1 to fix security issue (missing check for array bounds)
Features 1, Changed 1, Fixes 1
Notes
Added
- Now writes config file path in case of errors.
Changed
- Allow array of objects for
@protocolannotation
Fixed
- Properly consume
@Capabilities.UpdateRestrictions.UpdateMethod
Changed 1
Notes
Changed
- Replaced
console.warnstatements withcds.debuglogs for warning messages.
- Replaced
Features 1, Fixes 2
Notes
Added
- Now supports
@EntityRelationshipannotations.
Fixed
- Parameter aliases conflict with system query options.
- Fixed action/function invocation on navigation path to align with CAP runtime.
- Now supports
Features 1, Fixes 1
Notes
Added
- Now supports
odata-v4protocol in the@protocolallowed values in CDS along withodataandrest.
Fixed
- Fixed the filename issue: when there is only one service in the CDL source, the OpenAPI document is now generated with the filename corresponding to the service name rather than the CDL source filename.
- Now supports
Features 1, Fixes 3
Notes
Added
- Now supports
x-sapextensions using@OpenAPI.Extensionsannotations in service, entity and function/action level.
Fixed
- Fixed allowedValues on all primitive types.
- Removed duplicates in
tags. - No longer append protocol and service name information to the server URL incase of
openapi:serversoption.
- Now supports
Features 3, Changed 1, Fixes 3
Notes
Fixed
- Multiple protocols for a service now renders multiple openapi documents.
- Format and type are now preserved for function parameters.
- Fixed allowedValues on all primitive types.
Changed
- Using
@title,@Core.Descriptionand@Core.LongDescriptionfor titles and descriptions for improving the default texts ininfoobject andx-sap-shortText.
Added
- OpenAPI documents can now have
externalDocsobject provided through@OpenAPI.externalDocsannotation in the service level of CDS. - OpenAPI documents now throws warning if
securitySchemasare not found. - Introduced
--openapi:config-fileoption to incorporate all the options for cds compile command in a JSON configuration file, inline options take precedence over those defined in the configuration file.
Changed 1, Fixes 3
Notes
Fixed
- Entities annotated with
@cds.autoexpose[d]but explicitly exposed in the service are now made read-write. - Added a wrapper
propertiesobject for primitive return types. - Adding protocol and service name information to the server URL incase of
openapi:serversoption.
Changed
- Using
@title,@Core.Descriptionand@Core.LongDescriptionfor titles and descriptions for improving the default texts ininfoobject andx-sap-shortText.
- Entities annotated with
Changed 1, Fixes 1
Notes
Changed
- UUID type elements are not going to have the property of required.
Fixed
- properties with
@mandatoryannotation is not added torequiredarray.
Others providing
Compare all 5 on the OpenAPI page →- abap-openapiabap-openapiGenerates ABAP client classes and ICF server stubs from an OpenAPI v3 document, one self-contained global class and interface per definition, through a web client, a Node.js command line or ABAP itself.independent, abapGenerates ABAP client classes and server stubs from OpenAPIfrom ABAP
- cds-swagger-ui-expresscds-swagger-ui-expressServes a CAP service's OpenAPI definition as a browsable Swagger UI, which is the page @cap-js/openapi's document does not come with.independent, capSwagger UI for a CAP service's OpenAPI definitionfrom CAP
- ABAP OpenAPI UIABAP OpenAPI UIAn ABAP app that puts a Swagger UI in front of SAP NetWeaver Gateway services, built on Swagger UI and Odata-OpenAPI, installed through abapGit and opened from transaction ZGW_OPENAPI.independent, abapSwagger UI for SAP NetWeaver Gateway servicesfrom ABAP
- ABAP-SwaggerABAP-SwaggerAn ABAP library that exposes a class's public methods as REST services, registered through the ZIF_SWAG_HANDLER interface, with a Swagger UI on the same base path describing them.independent, abapExposes ABAP class methods as REST services with Swagger UIfrom ABAP
Details
Sources
Sources are graph entities: the same page may back several entries, and an unreachable source flags every row that rests on it.
Compatibility and provenance
Flavors
“const cds = require('@sap/cds')” — cap-js/openapi — README
Contributors
History in the atlas
- Turns a CDS service into an OpenAPI document, derived from the model so the description cannot drift from what is served.
- First seen.
For your agent
- Ref
artifact:cap-js-openapi- JSON
- /artifacts/cap-js-openapi.json
- MCP
- Connecting an agent