KituraOpenAPI
public class KituraOpenAPI
KituraOpenAPI contains helper functions for the addition of endpoints to a Kitura Router
for serving:
- an OpenAPI definition of its routes and their associated data types,
- the SwaggerUI tool, that allows exploration and testing of the API via a web browser.
Usage Example:
import Kitura
import KituraOpenAPI
let router = Router()
KituraOpenAPI.addEndpoints(to: router) // Register default endpoints
The endpoints have default values defined by the defaultConfig
property. You can customize
the endpoints by supplying a KituraOpenAPIConfig
:
let config = KituraOpenAPIConfig(apiPath: "/swagger", swaggerUIPath: "/swagger/ui")
KituraOpenAPI.addEndpoints(to: router, with: config)
-
The default endpoints registered by
KituraOpenAPI.addEndpoints
to serve the OpenAPI definition and the SwaggerUI tool. These values are/openapi
andopenapi/ui
, respectively.Declaration
Swift
public static var defaultConfig: KituraOpenAPIConfig
-
Add endpoints to a Kitura
Router
, to serve the OpenAPI document and SwaggerUI.Declaration
Swift
public static func addEndpoints(to router: Router, with config: KituraOpenAPIConfig = KituraOpenAPI.defaultConfig)
Parameters
router
The
Router
whose routes should be described.config
Optionally specify the paths to register. If not specified, the values described in
defaultConfig
will be used. -
Write Kitura’s OpenAPI definition to a file, describing all Codable routes that have been registered with the given
Router
.Throws
NSError if the file cannot be written.Declaration
Swift
public static func writeOpenAPI(from router: Router, to filePath: String) throws
Parameters
router
The Router whose routes should be described.
filePath
The path to a file that should be written.