How do document Apache Camel Rest Endpoints using OpenApi or Swagger specification?

Code

Step-by-Step guide

Add dependnacy in pom.xml

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-openapi-java</artifactId>
<version>3.14.0</version> <!-- Same as Camel Core -->
</dependency>

Java

@Component
public class RestDsl extends RouteBuilder {
@Override
public void configure() throws Exception {
restConfiguration()
.component("servlet")
.bindingMode(RestBindingMode.json)
.dataFormatProperty("prettyPrint", "true")
.apiContextPath("/api-doc")
.apiProperty("api.title", "Saggu.UK Camel Rest APIs")
.apiProperty("api.version", "1.0")
.apiContextListing(true)
;

rest()
.consumes("application/json").produces("application/json")
.get("/weather/{city}")
.responseMessage("200", "On good request")
.responseMessage("404", "For invalid city name")
.description("Get weather data for a given city")
.param()
.name("city").type(path).description("The name of the city e.g. London").dataType("string")
.endParam()
.outType(WeatherDto.class).to("direct:get-weather-data")
}
}

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to connect multiple Docker Containers?

Finale: The Beginning

YoungInnovations Weekly #201

Lever Weekly Report May 19 — May 26

HTML BASICS

Pulse and Node

Agave Development Update #4

READ/DOWNLOAD$# Arduino Sketches: Tools and Techniques for Programming Wizardry FULL BOOK PDF &…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jasvinder S Saggu

Jasvinder S Saggu

More from Medium

Sample code for IBM Event Streams Coding Challenge

Basic OOP for shavetail Louies — PART III [Inheritance | Composition | Encapsulation]

Evolve Database Using Liquibase

Encrypting and Decrypting a message using Symmetric Keys with Java, explained step-by-step with…