Skip to content

Commit 701b035

Browse files
committed
add java samples
1 parent 618d868 commit 701b035

15 files changed

Lines changed: 991 additions & 37 deletions

File tree

bin/configs/spring-boot-sort-validation.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ additionalProperties:
1010
serviceImplementation: "false"
1111
serializableModel: "true"
1212
useBeanValidation: "true"
13-
interfaceOnly: "true"
13+
interfaceOnly: "false"
1414
skipDefaultInterface: "true"
1515
useSpringBoot3: "true"
1616
generateSortValidation: "true"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
README.md
22
pom.xml
3+
src/main/java/org/openapitools/OpenApiGeneratorApplication.java
4+
src/main/java/org/openapitools/RFC3339DateFormat.java
35
src/main/java/org/openapitools/api/ApiUtil.java
46
src/main/java/org/openapitools/api/PetApi.java
7+
src/main/java/org/openapitools/api/PetApiController.java
58
src/main/java/org/openapitools/configuration/EnumConverterConfiguration.java
9+
src/main/java/org/openapitools/configuration/HomeController.java
610
src/main/java/org/openapitools/configuration/ValidPageable.java
711
src/main/java/org/openapitools/configuration/ValidSort.java
812
src/main/java/org/openapitools/model/Pet.java
913
src/main/java/org/openapitools/model/PetSort.java
1014
src/main/java/org/openapitools/model/PetSortEnum.java
15+
src/main/resources/application.properties
16+
src/main/resources/openapi.yaml
17+
src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java
Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
1+
# OpenAPI generated server
12

2-
# OpenAPI generated API stub
3-
4-
Spring Framework stub
5-
3+
Spring Boot Server
64

75
## Overview
8-
This code was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
9-
By using the [OpenAPI-Spec](https://openapis.org), you can easily generate an API stub.
10-
This is an example of building API stub interfaces in Java using the Spring framework.
11-
12-
The stubs generated can be used in your existing Spring-MVC or Spring-Boot application to create controller endpoints
13-
by adding ```@Controller``` classes that implement the interface. Eg:
14-
```java
15-
@Controller
16-
public class PetController implements PetApi {
17-
// implement all PetApi methods
18-
}
19-
```
6+
This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
7+
By using the [OpenAPI-Spec](https://openapis.org), you can easily generate a server stub.
8+
This is an example of building a OpenAPI-enabled server in Java using the SpringBoot framework.
209

21-
You can also use the interface to create [Spring-Cloud Feign clients](http://projects.spring.io/spring-cloud/spring-cloud.html#spring-cloud-feign-inheritance).Eg:
22-
```java
23-
@FeignClient(name="pet", url="http://petstore.swagger.io/v2")
24-
public interface PetClient extends PetApi {
2510

26-
}
27-
```
11+
Start your server as a simple java application
12+
Change default port value in application.properties

samples/server/petstore/springboot-sort-validation/pom.xml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,10 @@
2121
<sourceDirectory>src/main/java</sourceDirectory>
2222
<plugins>
2323
<plugin>
24-
<groupId>org.apache.maven.plugins</groupId>
25-
<artifactId>maven-source-plugin</artifactId>
26-
<executions>
27-
<execution>
28-
<id>attach-sources</id>
29-
<goals>
30-
<goal>jar</goal>
31-
</goals>
32-
</execution>
33-
</executions>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-maven-plugin</artifactId>
26+
<configuration>
27+
</configuration>
3428
</plugin>
3529
</plugins>
3630
</build>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.openapitools;
2+
3+
import com.fasterxml.jackson.databind.Module;
4+
import org.openapitools.jackson.nullable.JsonNullableModule;
5+
import org.springframework.boot.SpringApplication;
6+
import org.springframework.boot.autoconfigure.SpringBootApplication;
7+
import org.springframework.context.annotation.Bean;
8+
import org.springframework.context.annotation.ComponentScan;
9+
import org.springframework.context.annotation.FilterType;
10+
import org.springframework.context.annotation.FullyQualifiedAnnotationBeanNameGenerator;
11+
12+
@SpringBootApplication(
13+
nameGenerator = FullyQualifiedAnnotationBeanNameGenerator.class
14+
)
15+
@ComponentScan(
16+
basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"},
17+
nameGenerator = FullyQualifiedAnnotationBeanNameGenerator.class
18+
)
19+
public class OpenApiGeneratorApplication {
20+
21+
public static void main(String[] args) {
22+
SpringApplication.run(OpenApiGeneratorApplication.class, args);
23+
}
24+
25+
@Bean(name = "org.openapitools.OpenApiGeneratorApplication.jsonNullableModule")
26+
public Module jsonNullableModule() {
27+
return new JsonNullableModule();
28+
}
29+
30+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.openapitools;
2+
3+
import com.fasterxml.jackson.databind.util.StdDateFormat;
4+
5+
import java.text.DateFormat;
6+
import java.text.FieldPosition;
7+
import java.text.ParsePosition;
8+
import java.util.Date;
9+
import java.util.GregorianCalendar;
10+
import java.util.TimeZone;
11+
12+
public class RFC3339DateFormat extends DateFormat {
13+
private static final long serialVersionUID = 1L;
14+
private static final TimeZone TIMEZONE_Z = TimeZone.getTimeZone("UTC");
15+
16+
private final StdDateFormat fmt = new StdDateFormat()
17+
.withTimeZone(TIMEZONE_Z)
18+
.withColonInTimeZone(true);
19+
20+
public RFC3339DateFormat() {
21+
this.calendar = new GregorianCalendar();
22+
}
23+
24+
@Override
25+
public Date parse(String source, ParsePosition pos) {
26+
return fmt.parse(source, pos);
27+
}
28+
29+
@Override
30+
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
31+
return fmt.format(date, toAppendTo, fieldPosition);
32+
}
33+
34+
@Override
35+
public Object clone() {
36+
return this;
37+
}
38+
}

samples/server/petstore/springboot-sort-validation/src/main/java/org/openapitools/api/PetApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import java.util.Optional;
2828
import jakarta.annotation.Generated;
2929

30-
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2026-04-15T16:33:13.225084415Z[UTC]", comments = "Generator version: 7.22.0-SNAPSHOT")
30+
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2026-04-15T20:51:04.118456741Z[UTC]", comments = "Generator version: 7.22.0-SNAPSHOT")
3131
@Validated
3232
@RequestMapping("${openapi.openAPIPetstoreSortValidationTest.base-path:/v2}")
3333
public interface PetApi {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.openapitools.api;
2+
3+
import org.springframework.lang.Nullable;
4+
import org.springframework.data.domain.Pageable;
5+
import org.springframework.data.web.PageableDefault;
6+
import org.openapitools.model.Pet;
7+
import org.openapitools.model.PetSort;
8+
import org.openapitools.model.PetSortEnum;
9+
import org.springframework.data.domain.Sort;
10+
import org.springframework.data.web.SortDefault;
11+
import org.openapitools.configuration.ValidPageable;
12+
import org.openapitools.configuration.ValidSort;
13+
14+
15+
import org.springframework.beans.factory.annotation.Autowired;
16+
import org.springframework.http.HttpStatus;
17+
import org.springframework.http.MediaType;
18+
import org.springframework.http.ResponseEntity;
19+
import org.springframework.stereotype.Controller;
20+
import org.springframework.web.bind.annotation.PathVariable;
21+
import org.springframework.web.bind.annotation.RequestBody;
22+
import org.springframework.web.bind.annotation.RequestHeader;
23+
import org.springframework.web.bind.annotation.RequestMapping;
24+
import org.springframework.web.bind.annotation.CookieValue;
25+
import org.springframework.web.bind.annotation.RequestParam;
26+
import org.springframework.web.bind.annotation.RequestPart;
27+
import org.springframework.web.multipart.MultipartFile;
28+
import org.springframework.web.context.request.NativeWebRequest;
29+
30+
import jakarta.validation.constraints.*;
31+
import jakarta.validation.Valid;
32+
33+
import java.util.List;
34+
import java.util.Map;
35+
import java.util.Optional;
36+
import jakarta.annotation.Generated;
37+
38+
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2026-04-15T20:51:04.118456741Z[UTC]", comments = "Generator version: 7.22.0-SNAPSHOT")
39+
@Controller
40+
public class PetApiController implements PetApi {
41+
42+
@Nullable
43+
private final NativeWebRequest request;
44+
45+
@Autowired
46+
public PetApiController(@Nullable NativeWebRequest request) {
47+
this.request = request;
48+
}
49+
50+
@Override
51+
public Optional<NativeWebRequest> getRequest() {
52+
return Optional.ofNullable(request);
53+
}
54+
55+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.openapitools.configuration;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.stereotype.Controller;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
7+
/**
8+
* Home redirection to OpenAPI api documentation
9+
*/
10+
@Controller
11+
public class HomeController {
12+
13+
}

samples/server/petstore/springboot-sort-validation/src/main/java/org/openapitools/model/Pet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* Pet
2020
*/
2121

22-
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2026-04-15T16:33:13.225084415Z[UTC]", comments = "Generator version: 7.22.0-SNAPSHOT")
22+
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2026-04-15T20:51:04.118456741Z[UTC]", comments = "Generator version: 7.22.0-SNAPSHOT")
2323
public class Pet implements Serializable {
2424

2525
private static final long serialVersionUID = 1L;

0 commit comments

Comments
 (0)