Type: Package
Title: Dynamically Generates Documentation from a 'Swagger' Compliant API
Version: 5.17.14.1
Suggests: jsonlite, plumber, testthat
Description: A collection of 'HTML', 'JavaScript', and 'CSS' assets that dynamically generate beautiful documentation from a 'Swagger' compliant API: https://swagger.io/specification/.
License: Apache License 2.0 | file LICENSE
Encoding: UTF-8
URL: https://rstudio.github.io/swagger/, https://github.com/rstudio/swagger
BugReports: https://github.com/rstudio/swagger/issues
RoxygenNote: 7.3.1
NeedsCompilation: no
Packaged: 2024-06-28 16:48:07 UTC; tremb
Author: Barret Schloerke ORCID iD [aut], Javier Luraschi [aut], Bruno Tremblay [cre, ctb], RStudio [cph], SmartBear Software [aut, cph]
Maintainer: Bruno Tremblay <cran@neoxone.com>
Repository: CRAN
Date/Publication: 2024-06-28 17:10:02 UTC

swagger: Dynamically Generates Documentation from a Swagger-Compliant API

Description

Swagger is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.

Details

The main purpose of this package is to enable package authors to create APIs that are compatible with https://swagger.io/ and https://www.openapis.org/.

To learn more about Swagger visit: https://swagger.io/swagger-ui/

Author(s)

Maintainer: Bruno Tremblay cran@neoxone.com [contributor]

Authors:

Other contributors:

See Also

Useful links:


Plumber 'register_doc()' information

Description

Normally documentation is registered in the '.onLoad()' method of the package. To avoid a circular dependency with 'swagger' when 'plumber' are starting up, ‘plumber' must retrieve this information manually on it’s startup.

Usage

plumber_docs()

Details

See the examples for how documentation should regularly be registered.

Examples

## Not run: 
## Suggested setup for other packages trying to register visual docs for plumber
.onLoad <- function(...) {
  plumber_register_ui <- function() {
    tryCatch({
      do.call(plumber::register_ui, plumber_docs())
    }, error = function(e) {
      message("Error registering swagger docs. Error: ", e)
    })
  }

  setHook(packageEvent("plumber", "onLoad"), function(...) {
    plumber_register_ui()
  })
  if ("plumber" %in% loadedNamespaces()) {
    plumber_register_ui()
  }
}

## End(Not run)

Path to Swagger Index

Description

Retrieves the path to the swagger index file.

Usage

swagger_index(version = "5")

Arguments

version

Major version number to be used for Swagger UI. Currently version "3" is compatible with OpenAPI spec 2.0, 3.0.

Examples


if (interactive()) {
  browseURL(swagger_index())
} else {
  print(paste("You can use swagger under: ", swagger_index()))
}


Path to Swagger Resources

Description

Retrieves the path to swagger resources.

Usage

swagger_path(version = "5")

Arguments

version

Major version number to be used for Swagger UI. Currently version "3" is compatible with OpenAPI spec 2.0, 3.0.

Examples


if (interactive()) {
  browseURL(swagger_path())
} else {
  print(paste("You can explore swagger resources under: ", swagger_path()))
}


Swagger Index File with OpenAPI Path

Description

Produces the content for a index.html file that will attempt to access a provided API path.

Usage

swagger_spec(
  api_path = "\"http://petstore.swagger.io/v2/swagger.json\"",
  version = "5"
)

Arguments

api_path

Path to paste into the an OpenAPI specification file

version

Major version number to be used for Swagger UI. Currently version "3" is compatible with OpenAPI spec 2.0, 3.0.

Value

large string containing the contents of swagger_index() with the appropriate specification path changed to the api_path value.

Examples

if (interactive()) {
  swagger_spec("https://developer.uspto.gov/ibd-api/swagger.json")
}