Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/microfocus/swagger-ui

https://microfocus.github.io/swagger-ui/
https://github.com/microfocus/swagger-ui

openapi rest swagger-ui

Last synced: 6 days ago
JSON representation

https://microfocus.github.io/swagger-ui/

Awesome Lists containing this project

README

        

# Open Text Swagger UI

This project is an Open Text branded version of the [Swagger UI](https://github.com/swagger-api/swagger-ui).

## Usage

It can be used from another Java project by including the following dependency:

```xml

com.microfocus.webjars
swagger-ui-dist

```

To override swagger configuration params include a **opentext-config.js** file, similar to the one [here](./src/main/resources/opentext-config.js):

Swagger configuration params that can be set in opentext-config.js:
- url: "api-docs/swagger.yaml"
- dom_id: "#swagger-ui
- operationsSorter: "alpha"
- tagsSorter: "alpha"
- docExpansion: "none"
- defaultModelsExpandDepth: -1
- deepLinking: true

For a complete list of swagger configuration params refer [Swagger configuration params](https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md#core).

## Using this module in Spring Boot

1. Add the module as a `runtime` dependency.
2. Include a resource file called **opentext-config.js** with the swagger configuration overrides, similar to the one [here](./src/main/resources/opentext-config.js).
Make sure to overide the "url" param to point to your swagger contract.
3. To facilitate [serving static resources](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.html) in Spring Boot override the `addResourceHandlers` function in

```java
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {

// Configure the external-facing URI path by adding a resource handler
final ResourceHandlerRegistration resourceHandlerRegistration = registry.addResourceHandler("/swagger/**");

// Map that external-facing URI path internally to the physical path where the resources are actually located
resourceHandlerRegistration.addResourceLocations(
"classpath:/swagger/",
swaggerContractPath,
"classpath:/META-INF/resources/webjars/opentext-swagger-ui-dist/2.0.0/");

final ResourceChainRegistration resourceChainRegistration = resourceRegistration.resourceChain(true);
resourceChainRegistration.addResolver(new PathResourceResolver());
}
```

## Using this module in Dropwizard

1. Add the module as a `runtime` dependency.
2. Include a resource file called **swagger-ui-config.js** to override the swagger configuration, similar to the one [here](./src/main/resources/opentext-config.js).
Make sure to overide the "url" param to point to your swagger contract.
3. To facilitate serving static resources in Dropwizard add [AssetBundles](https://www.dropwizard.io/en/latest/manual/core.html#bundles)

```java
@Override
public void initialize(Bootstrap bootstrap) {
bootstrap.addBundle(new AssetsBundle(
"/META-INF/resources/webjars/opentext-swagger-ui-dist/2.0.0/", "/swagger/", "index.html", "swagger-ui"));
bootstrap.addBundle(new AssetsBundle(
"/swagger-ui-config.js", "/swagger/opentext-config.js", null, "swagger-ui-config"));

super.initialize(bootstrap);
}
```

## Using this module in Tomcat
1. Include a resource file called **opentext-config.js** with the swagger configuration overrides, similar to the one [here](./src/main/resources/opentext-config.js).
Make sure to overide the "url" param to point to your swagger contract.
2. Repackage the swagger assets into the war file to be deployed in Tomcat.

**Unpack the swagger-ui artifact excluding the default configuration file**
```xml

org.apache.maven.plugins
maven-dependency-plugin



unpack




com.github.microfocus
swagger-ui-dist
1.0.0
${project.build.directory}/swagger-ui

META-INF/resources/webjars/opentext-swagger-ui-dist/2.0.0/opentext-config.js





```

**Package the war file with the swagger-ui assets and the swagger-ui configuration overide file**
```xml

org.apache.maven.plugins
maven-war-plugin

false




${project.build.directory}/swagger-ui/META-INF/resources/webjars/opentext-swagger-ui-dist/2.0.0

.



src/main/html
.




${project.build.directory}/swagger-contract/com/hpe/darwin/tag/service/contract

api-docs


```

## Using as an NPM package
This module, `opentext-swagger-ui-dist`, is a dependency-free module that includes everything required to serve OpenText-branded Swagger UI in a server-side project, or a single-page application that can't resolve npm module dependencies.

npm install git+ssh://[email protected]/MicroFocus/swagger-ui.git#v2.0.0-dist

Or alternatively if you prefer not to use a **git** url:

npm install https://github.com/MicroFocus/swagger-ui/archive/v2.0.0-dist.tar.gz