npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cds-swagger-ui-express

v0.9.0

Published

Swagger UI for CAP Services

Downloads

17,152

Readme

cds-swagger-ui-express

An CAP plugin to serve OpenAPI definitions for CAP services in Swagger UI. Builds on top of swagger-ui-express.

Preview

Setup

In your project, just add a dependency like so:

npm add --save-dev cds-swagger-ui-express

Once loaded by CAP, the package registers itself as a middleware with a default configuration.

Run

After starting the app with cds watch or so, Swagger UI is served at /$api-docs/<service-path>, like http://localhost:4004/$api-docs/browse/

Configuration

You can set the most prominent options in package.json or cds-rc.json, as in other CAP apps:

"cds": {
  "swagger": {
    "basePath": "/$api-docs", // the root path to mount the middleware on
    "apiPath": "", // the root path for the services (useful if behind a reverse proxy)
    "diagram": true, // whether to render the YUML diagram
    "odataVersion": "4.0" // the OData Version to compile the OpenAPI specs. Defaults to 4.01
  }
}

To disable the plugin, set this:

"cds": {
  "swagger": false
}

Note that you can also set environment variables for each option, like CDS_SWAGGER=false. See the cds.env docs for more.

Programmatic Usage (advanced)

If you need to register the plugin programmatically, e.g. in certain conditions only, you can do so in your server.js:

const cds = require ('@sap/cds')
const cds_swagger = require ('cds-swagger-ui-express')
cds.on ('bootstrap', app =>
  app.use (cds_swagger ())
)

In this case, the default 'auto registration' as plugin is disabled automatically to avoid conflicts.

Programmatic Configuration

If the middleware is registered programmatically, you need to pass in the options through the API as well. No configuration from package.json is used here.

Call cds_swagger ({...}) with the following object as first parameter:

{
  "basePath": ...,
  // see section above for more
}

Swagger UI Options

Call cds_swagger ({...}, {...}) with an additional object as second parameter. This object is passed to swagger-ui-express as custom options.

Example:

{
  "customSiteTitle": "My Custom Title",
  "swaggerOptions": {
    "requestInterceptor": ...
  }
}

See the list of all options. For questions to specific properties, contact the maintainers of swagger-ui-express or swagger-ui.

Notes

If you call cds.serve on your own in your server.js, make sure to install this middleware before, as it relies on CDS' serving events.