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

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