build openapi endpoint

This commit is contained in:
2025-12-13 19:30:33 -05:00
parent 5afc80cbfd
commit 84d228eb7c
5 changed files with 120 additions and 0 deletions

40
Ui/build.gradle Normal file
View 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')
}

View 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;
}
}

View 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());
}
}

View 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