Skip to content

codecentric/reedelk-openapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reedelk OpenAPI v3 serializer / deserializer

License Twitter

This project refers to the OpenAPI Specification project from the OpenAPI initiative.

Overview

The Reedelk OpenAPI v3.x serializer/deserializer library is a lightweight library to serialize/deserialize OpenAPI v3.x model to/from JSON and to/from YAML.

The library uses only JSON-java (org.json) and SnakeYAML as dependencies making it the perfect choice if you are just looking for a very lightweight solution to serialize/deserialize OpenAPI v3.x definitions.

Features

  • Serialize OpenAPI v3.x model to JSON
  • Serialize OpenAPI v3.x model to YAML
  • Deserialize OpenAPI v3.x model from JSON
  • Deserialize OpenAPI v3.x model from YAML

Maven

Add the Reedelk Repository to your pom.xml:

<repositories>
    <repository>
        <id>reedelk-repository</id>
        <name>Reedelk Repository</name>
        <url>http://repository.reedelk.com/release/</url>
    </repository>
</repositories>

Add the following dependency to your pom.xml file:

<dependency>
    <groupId>com.reedelk</groupId>
    <artifactId>reedelk-openapi</artifactId>
    <version>X.Y.Z</version>
</dependency>

Usage

Serialize

To JSON or YAML:

InfoObject infoModel = new InfoObject();
infoModel.setDescription("This is a sample API.");
infoModel.setVersion("1.0.2");

OpenApiObject openApiModel = new OpenApiObject();
openApiModel.setInfo(info);

// to JSON string
String openApiAsJson = OpenApi.toJson(openApiModel);

// to YAML string
String openApiAsYaml = OpenApi.toYaml(openApiModel);

Deserialize

From JSON or YAML:

// from JSON string
String openApiAsJson = "{"openapi": "3.0.3","info": {"title": "API","version": "v1" }}";
OpenApiObject openApiModel = OpenApi.from(openApiAsJson);
InfoObject infoModel = actual.getInfo();
...

// from YAML string
String openApiAsYaml = "openapi: 3.0.0
                        info:
                          version: 1.0.2
                          title: Petstore API";
OpenApiObject openApiModel = OpenApi.from(openApiAsYaml);
InfoObject infoModel = actual.getInfo();
...

Contribute