Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use @cap-js/openapi instead of @sap/cds-dk #134

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
node-version: [20.x, 18.x]
node-version: [22.x, 20.x, 18.x]

steps:
- uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
registry=https://registry.npmjs.org/
@sap:registry=https://registry.npmjs.org/
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).

The format is based on [Keep a Changelog](http://keepachangelog.com/).

## Version 0.9.0 - 2024-07-15

### Changed

- Use `@cap-js/openapi` instead of `@sap/cds-dk`, leading to lighter dependencies

## Version 0.8.0 - 2024-01-18

### Added
Expand Down
23 changes: 3 additions & 20 deletions lib/middleware.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const cds = requireCdsOpenAPI()
const cds = require('@sap/cds')
const openapi = require('@cap-js/openapi')
const debug = cds.debug('swagger')

const swaggerUi = require('swagger-ui-express')
Expand Down Expand Up @@ -36,7 +37,7 @@ module.exports = (options={}, swaggerUiOptions={}) => {
const cache = {}
function toOpenApiDoc (service, options = {}) {
if (!cache[service.name]) {
cache[service.name] = cds.compile.to.openapi(service.model, {
cache[service.name] = openapi.compile(service.model, {
service: service.name,
'odata-version': options.odataVersion,
'openapi:url': join('/', options.apiPath, service.path),
Expand All @@ -56,24 +57,6 @@ function addLinkToIndexHtml (service, apiPath) {
service.$linkProviders ? service.$linkProviders.push(provider) : service.$linkProviders = [provider]
}

/**
* Loads the compile.to.openapi function from @sap/cds-dk or throws an error if not installed.
* Will get simpler in the future when we have a dedicated openapi plugin.
*
* @returns { import('@sap/cds-dk') }
*/
function requireCdsOpenAPI () {
try {
return require('@sap/cds-dk')
} catch (err) {
const cds = require('@sap/cds')
if (!cds.compile.to.openapi) {
throw new Error(`'@sap/cds-dk' is not installed. Add it as a (dev) dependency to use this plugin`, { cause: err })
}
return cds
}
}

/**
* @typedef {Object} CdsSwaggerOptions
* @property {string} basePath - the root path to mount the middleware on
Expand Down
Loading