build openapi endpoint
This commit is contained in:
40
Ui/build.gradle
Normal file
40
Ui/build.gradle
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*
|
||||
*/
|
||||
|
||||
plugins {
|
||||
// Apply the application plugin to add support for building a CLI application in Java.
|
||||
id 'java'
|
||||
id 'application'
|
||||
}
|
||||
|
||||
// Apply a specific Java toolchain to ease working on different environments.
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(25)
|
||||
}
|
||||
|
||||
sourceCompatibility = JavaVersion.toVersion("25")
|
||||
targetCompatibility = JavaVersion.toVersion("25")
|
||||
}
|
||||
|
||||
application {
|
||||
// Define the main class for the application.
|
||||
mainClass = 'edu.inventorym.Ui'
|
||||
}
|
||||
|
||||
repositories {
|
||||
// Use Maven Central for resolving dependencies.
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'io.netty:netty-common:4.2.8.Final'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-webflux:4.0.0'
|
||||
implementation 'org.springdoc:springdoc-openapi-starter-webflux-api:3.0.0'
|
||||
implementation 'org.springdoc:springdoc-openapi-starter-webflux-ui:3.0.0'
|
||||
implementation 'jakarta.json.bind:jakarta.json.bind-api:3.0.1'
|
||||
implementation project(':Model')
|
||||
}
|
||||
|
||||
36
Ui/src/main/java/edu/inventorym/Application.java
Normal file
36
Ui/src/main/java/edu/inventorym/Application.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* license: GPLv3
|
||||
edu.inventorym
|
||||
*/
|
||||
package edu.inventorym;
|
||||
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.reactor.netty.NettyReactiveWebServerFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.reactive.config.EnableWebFlux;
|
||||
|
||||
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
|
||||
import io.swagger.v3.oas.annotations.info.Info;
|
||||
|
||||
@EnableWebFlux
|
||||
@SpringBootApplication
|
||||
@OpenAPIDefinition(info = @Info(title = "Model API", version = "3.0.0", description = "Documentation Model API v1.0"))
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder()
|
||||
.profiles("dev")
|
||||
.web(WebApplicationType.REACTIVE)
|
||||
.sources(Application.class, Controller.class)
|
||||
.run(args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public NettyReactiveWebServerFactory nettyServerFactory() {
|
||||
NettyReactiveWebServerFactory factory = new NettyReactiveWebServerFactory();
|
||||
return factory;
|
||||
}
|
||||
|
||||
}
|
||||
37
Ui/src/main/java/edu/inventorym/Controller.java
Normal file
37
Ui/src/main/java/edu/inventorym/Controller.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package edu.inventorym;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/events")
|
||||
public class Controller {
|
||||
|
||||
@Operation(summary = "Get all events", description = "Returns a list of all events.")
|
||||
@ApiResponse(responseCode = "200", description = "Events found")
|
||||
@GetMapping
|
||||
public List<String> getAllEvents() {
|
||||
return List.of("Event 1", "Event 2");
|
||||
}
|
||||
|
||||
@GetMapping(value = "/event-details", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||
public Flux<String> streamDetails() {
|
||||
// Flux.interval emits a Long every 1 second
|
||||
return Flux.interval(Duration.ofSeconds(1))
|
||||
.map(sequence -> "Current Stock Price at " + LocalDateTime.now());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
7
Ui/src/resources/application.properties
Normal file
7
Ui/src/resources/application.properties
Normal file
@@ -0,0 +1,7 @@
|
||||
spring.profiles.active=dev
|
||||
|
||||
springdoc.packages-to-scan=edu.inventorym,
|
||||
|
||||
springdoc.swagger-ui.path=/api-docs
|
||||
springdoc.api-docs.path=/v3/api-docs.json
|
||||
springdoc.version=3.0.0
|
||||
Reference in New Issue
Block a user