Skip to content

Commit

Permalink
Merge pull request #58 from justin-tay/openapi3_elide-7.x
Browse files Browse the repository at this point in the history
Update to use OpenAPI 3 and refactor
  • Loading branch information
aklish authored Jul 1, 2023
2 parents ab24665 + 77b4179 commit 3d25a4d
Show file tree
Hide file tree
Showing 26 changed files with 324 additions and 84 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ An archetype Elide project using Spring Boot.

## Background

This project is the sample code for [Elide's Getting Started documentation](https://elide.io/pages/guide/01-start.html).
This project is the sample code for [Elide's Getting Started documentation](https://elide.io/pages/guide/v7/01-start.html).

## Install

To build and run:

1. mvn clean install
2. java -jar target/elide-spring-boot-1.0.jar
2. java -jar target/elide-spring-boot-1.0.0.jar
3. Browse http://localhost:8080/

Springdoc is accessible at http://localhost:8080/swagger-ui/index.html.

## Docker and Containerize

To containerize and run elide project locally
Expand Down Expand Up @@ -71,10 +73,10 @@ To containerize and run elide project locally

## Usage

See [Elide's Getting Started documentation](https://elide.io/pages/guide/v5/01-start.html).
See [Elide's Getting Started documentation](https://elide.io/pages/guide/v7/01-start.html).

## Contribute
Please refer to [the contributing.md file](CONTRIBUTING.md) for information about how to get involved. We welcome issues, questions, and pull requests.
Please refer to the [CONTRIBUTING.md](CONTRIBUTING.md) file for information about how to get involved. We welcome issues, questions, and pull requests.

## License
This project is licensed under the terms of the [Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0.html) open source license.
Expand Down
57 changes: 41 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,62 @@
<name>Elide Spring Boot Example</name>
<description>Elide Spring Boot Example</description>
<groupId>example</groupId>
<version>1.0</version>
<version>1.0.0</version>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.5</version>
<version>3.1.0</version>
</parent>

<properties>
<jar.finalName>elide-spring-boot</jar.finalName>
<java.version>17</java.version>

<elide.version>7.0.0-pr3</elide.version>
<elide.version>7.0.0-pr5</elide.version>

<liquibase.version>4.18.0</liquibase.version>
<artemis.version>2.28.0</artemis.version>
<springdoc.version>2.1.0</springdoc.version>
<logback-access-spring-boot-starter.version>4.0.0</logback-access-spring-boot-starter.version>
<snakeyaml.version>2.0</snakeyaml.version>

<rest-assured.version>5.3.0</rest-assured.version>
<!-- Jetty 11 uses servlet-api 5 and not 6 -->
<jakarta.servlet-api.version>5.0.0</jakarta.servlet-api.version>

<!-- see https://github.com/graalvm/native-build-tools/issues/358 -->
<maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
</properties>

<dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>${jakarta.servlet-api.version}</version>
</dependency>

<dependency>
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-bom</artifactId>
<version>${elide.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- Runtime -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
Expand All @@ -54,7 +79,6 @@
<dependency>
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-spring-boot-starter</artifactId>
<version>${elide.version}</version>
<!-- Remove Tomcat -->
<exclusions>
<exclusion>
Expand All @@ -73,11 +97,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -116,12 +135,12 @@

<!-- Request/Response logging -->
<dependency>
<groupId>net.rakugakibox.spring.boot</groupId>
<groupId>dev.akkinoc.spring.boot</groupId>
<artifactId>logback-access-spring-boot-starter</artifactId>
<version>2.7.1</version>
<version>${logback-access-spring-boot-starter.version}</version>
</dependency>
<!-- Test -->

<!-- Test -->
<dependency>
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-test-helpers</artifactId>
Expand Down Expand Up @@ -165,6 +184,12 @@
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>

<build>
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/example/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,25 @@
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ImportRuntimeHints;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.security.SecurityScheme;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;

/**
* Example app using elide-spring.
*/
@SpringBootApplication
@EntityScan
@ImportRuntimeHints(AppRuntimeHints.class)
@OpenAPIDefinition(info = @Info(title = "My Title"), security = @SecurityRequirement(name = "bearerAuth"))
@SecurityScheme(
name = "bearerAuth",
type = SecuritySchemeType.HTTP,
bearerFormat = "JWT",
scheme = "bearer"
)
public class App {
public static void main(String[] args) throws Exception {
SpringApplication.run(App.class, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See LICENSE file in project root for terms.
*/

package example;
package example.config;

import ch.qos.logback.access.servlet.TeeFilter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
* See LICENSE file in project root for terms.
*/

package example;
package example.config;

import org.springframework.boot.context.properties.ConfigurationProperties;

import lombok.Data;

@Data
@ConfigurationProperties(prefix = "security")
@ConfigurationProperties(prefix = "app.security")
public class SecurityConfigProperties {
private String origin = "*";
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
* See LICENSE file in project root for terms.
*/

package example;
package example.config;

import static org.springframework.security.config.Customizer.withDefaults;

import java.time.Duration;
import java.util.Arrays;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
Expand All @@ -23,17 +26,15 @@
*/
@Configuration
@EnableWebSecurity
@EnableConfigurationProperties(SecurityConfigProperties.class)
public class SecurityConfiguration {

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.cors()
.and()
.headers().frameOptions().sameOrigin()
.and()
.authorizeHttpRequests().anyRequest().permitAll()
.and()
.csrf().disable();
http.cors(withDefaults())
.headers(headers -> headers.frameOptions(frameOptions -> frameOptions.sameOrigin()))
.authorizeHttpRequests(authorizeHttpRequests -> authorizeHttpRequests.anyRequest().permitAll())
.csrf(csrf -> csrf.disable());
return http.build();
}

Expand Down
40 changes: 40 additions & 0 deletions src/main/java/example/controllers/HelloController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package example.controllers;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.tags.Tags;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Tags(value = { @Tag(name = "hello", description = "Say hello.") })
@RestController
public class HelloController {
@Builder
@AllArgsConstructor
@Schema(title= "Hello", description = "The hello response.")
public static class HelloResource {
@Getter
private String text;
@Getter
private String language;
}

@GetMapping(value = "/hello", produces = MediaType.APPLICATION_JSON_VALUE)
@ApiResponses(
@ApiResponse(
responseCode = "200",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = HelloResource.class))))
public ResponseEntity<HelloResource> hello() {
return ResponseEntity.ok(HelloResource.builder().text("Hello").language("English").build());
}
}
2 changes: 1 addition & 1 deletion src/main/java/example/models/ArtifactGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.ArrayList;
import java.util.List;

@Include(name = "group")
@Include(name = "group", description = "Artifact group.", friendlyName = "Group")
@Table(name = "artifactgroup")
@Entity
@Subscription
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/example/models/ArtifactProduct.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.ArrayList;
import java.util.List;

@Include(rootLevel = false, name = "product")
@Include(rootLevel = false, name = "product", description = "Artifact product.", friendlyName = "Product")
@Table(name = "artifactproduct")
@Entity
public class ArtifactProduct {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/example/models/ArtifactVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import jakarta.persistence.Table;
import java.util.Date;

@Include(rootLevel = false, name = "version")
@Include(rootLevel = false, name = "version", description = "Artifact version.", friendlyName = "Version")
@Table(name = "artifactversion")
@Entity
public class ArtifactVersion {
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/example/models/v1/ArtifactGroupV1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2019, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package example.models.v1;

import com.yahoo.elide.annotation.Include;
import com.yahoo.elide.graphql.subscriptions.annotations.Subscription;
import com.yahoo.elide.graphql.subscriptions.annotations.SubscriptionField;

import lombok.Data;

import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.util.ArrayList;
import java.util.List;

@Include(name = "groupV1", description = "Artifact group.", friendlyName = "GroupV1")
@Table(name = "artifactgroup")
@Entity
@Subscription
@Data
public class ArtifactGroupV1 {
@Id
private String name = "";

@SubscriptionField
private String commonName = "";

@SubscriptionField
private String description = "";

@SubscriptionField
@OneToMany(mappedBy = "group")
private List<ArtifactProductV1> products = new ArrayList<>();
}
34 changes: 34 additions & 0 deletions src/main/java/example/models/v1/ArtifactProductV1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2019, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package example.models.v1;

import com.yahoo.elide.annotation.Include;

import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.util.ArrayList;
import java.util.List;

@Include(rootLevel = false, name = "productV1", description = "Artifact product.", friendlyName = "ProductV1")
@Table(name = "artifactproduct")
@Entity
public class ArtifactProductV1 {
@Id
private String name = "";

private String commonName = "";

private String description = "";

@ManyToOne
private ArtifactGroupV1 group = null;

@OneToMany(mappedBy = "artifact")
private List<ArtifactVersionV1> versions = new ArrayList<>();
}
Loading

0 comments on commit 3d25a4d

Please sign in to comment.