build openapi endpoint
This commit is contained in:
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