dernasherbrezon / jsp-openapi

JSP tag for rendering openapi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jsp-openapi Build Status Quality Gate Status

Tag lib for rendering openapi specification. CSS and javascript libraries are not included.

  • "bootstrap4-openapi". Render using bootstrap4.

Usage

For a complete reference see the test.

Step by step guide

Include dependency:

<dependency>
	<groupId>ru.r2cloud.openapi</groupId>
	<artifactId>jsp-openapi</artifactId>
	<version>1.0</version>
</dependency>

Setup controller (for example Spring MVC):

@RequestMapping("/api")
public ModelAndView load() throws Exception {
	OpenAPI openapi = new OpenAPIV3Parser().read(LoadApi.class.getClassLoader().getResource("openapi.json").getFile());
	Map<String, Object> model = new HashMap<String, Object>();
	model.put("entity", openapi);
	return new ModelAndView("api", model);
}

Note: if API specification cannot be changed in runtime, then it is better to cache it on startup.

Note: io.swagger.v3.parser.OpenAPIV3Parser is a swagger parser for v3 specification. You can implement your own parser or use any compatible. Parser should be able to construct io.swagger.v3.oas.models.OpenAPI model.

Configure taglib:

<%@ taglib prefix="openapi" uri="https://github.com/dernasherbrezon/jsp-openapi" %>

Use on the page:

<body>
	<div class="container">
		<openapi:bootstrap4-openapi openapi="${entity}"/>
	</div>
</body>

About

JSP tag for rendering openapi

License:Apache License 2.0


Languages

Language:HTML 71.0%Language:Java 29.0%Language:Shell 0.1%