Skip to content

Fork of the Swagger2PUML project to generate Class Diagrams (Plant UML) for a given OpenAPI (a.k.a Swagger) Definition

License

Notifications You must be signed in to change notification settings

openapi2puml/openapi2puml

Repository files navigation

OpenAPI2Puml

Build Status codecov Gitpod ready-to-code

OpenApi to Plant UML conversion tool generates UML Class Diagrams from an Open API definition.

This is a fork of the original project Swagger2puml (https://github.com/kicksolutions/swagger2puml) which seems to have been dormant for some time.

The original developers of Swagger2puml are:

This project is based on Maven. Following are modules we currently have

  • openapi2puml-core

Following are the tools which this project internally uses:

How does it work

  • Input: Openapi2Puml parses the swagger definition from input using Swagger Parser
  • Transform: The swagger definition is built into an object model
  • Output: The object model is transformed into a Plant UML file using a Mustache template. Optionally a .svg image can be generated also.

openapi2puml-core:

This utility takes OpenAPI Yaml or JSON as input generates swagger.puml and swagger.svg files as output.

Below is the Sample Class Diagram generated by the application. To see the generated PUML file, please click here

Swagger-Class-Diagram-Sample

Building:

mvn package

The jar is built with dependencies and placed in the root of the project.

Usage:

java -jar openapi2puml.jar [options]

-i {Path of Swagger Definition (Can be either Yaml or json)}
-o {Target location where Puml File and Image should generated}
-generateDefinitionModelOnly {true/flase Defult False (Optional)}
-includeCardinality {true/flase Defult true (Optional)}
-generateSvg true/false; Default=true

Dockerized version of OpenAPI2Puml

It is also to use a docker container to run the tool. Simply mount a directory and add command line options by using docker run, e.g.

# Run a docker container
$ sudo docker run --rm -it --name openapi2puml \
    -v $PWD/examples:/specs \
    openapi2puml/openapi2puml -i /specs/swagger.yaml -o /specs

A dockerhub repo exists here: https://hub.docker.com/r/openapi2puml/openapi2puml

To build and run a local copy, do the following:

# Obtain base image for build
$ sudo docker pull maven:3-jdk-11  # needed since docker-hub pull restrictions

# Build the image from the project
$ sudo docker build -t openapi2puml .

# Run a docker container
$ sudo docker run --rm -it --name openapi2puml \
    -v $PWD/examples:/specs \
    openapi2puml -i /specs/swagger.yaml -o /specs

Running in GitPod

You can directly run this code in GitPod by clicking this link and Running

and then using this command line:

java -cp /workspace/openapi2puml/openapi2puml-core/target/dependency/*:/workspace/openapi2puml/openapi2puml-core/target/openapi-plantuml-core-0.0.1-SNAPSHOT.jar org.openapi2puml.openapi.OpenApi2PlantUML -i /workspace/openapi2puml/examples/swagger.yaml -o /workspace/openapi2puml/examples

License

Apacahe 2.0