Skip to content

Commit a8094c9

Browse files
committed
fix sample
1 parent b8a511f commit a8094c9

17 files changed

Lines changed: 1046 additions & 1 deletion

File tree

bin/configs/spring-boot-paged-model.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ additionalProperties:
99
useSwaggerUI: "false"
1010
serializableModel: "true"
1111
useBeanValidation: "true"
12-
interfaceOnly: "false"
12+
interfaceOnly: "true"
1313
skipDefaultInterface: "true"
1414
useSpringBoot3: "true"
1515
hideGenerationTimestamp: "true"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.openapi-generator-ignore
2+
README.md
3+
pom.xml
4+
src/main/java/org/openapitools/api/ApiUtil.java
5+
src/main/java/org/openapitools/api/OrderApi.java
6+
src/main/java/org/openapitools/api/PetApi.java
7+
src/main/java/org/openapitools/api/UserApi.java
8+
src/main/java/org/openapitools/configuration/EnumConverterConfiguration.java
9+
src/main/java/org/openapitools/model/Order.java
10+
src/main/java/org/openapitools/model/Pet.java
11+
src/main/java/org/openapitools/model/PetSort.java
12+
src/main/java/org/openapitools/model/SearchResult.java
13+
src/main/java/org/openapitools/model/User.java
14+
src/main/java/org/openapitools/model/UserList.java
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.22.0-SNAPSHOT
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
# OpenAPI generated API stub
3+
4+
Spring Framework stub
5+
6+
7+
## 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+
```
20+
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 {
25+
26+
}
27+
```
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>org.openapitools</groupId>
4+
<artifactId>openapi-spring</artifactId>
5+
<packaging>jar</packaging>
6+
<name>openapi-spring</name>
7+
<version>1.0.0</version>
8+
<properties>
9+
<java.version>17</java.version>
10+
<maven.compiler.release>${java.version}</maven.compiler.release>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
</properties>
13+
<parent>
14+
<groupId>org.springframework.boot</groupId>
15+
<artifactId>spring-boot-starter-parent</artifactId>
16+
<version>3.3.13</version>
17+
<relativePath/> <!-- lookup parent from repository -->
18+
</parent>
19+
20+
<build>
21+
<sourceDirectory>src/main/java</sourceDirectory>
22+
<plugins>
23+
<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>
34+
</plugin>
35+
</plugins>
36+
</build>
37+
<dependencies>
38+
<dependency>
39+
<groupId>org.springframework.boot</groupId>
40+
<artifactId>spring-boot-starter-web</artifactId>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.springframework.data</groupId>
44+
<artifactId>spring-data-commons</artifactId>
45+
</dependency>
46+
<!-- @Nullable annotation -->
47+
<dependency>
48+
<groupId>com.google.code.findbugs</groupId>
49+
<artifactId>jsr305</artifactId>
50+
<version>3.0.2</version>
51+
</dependency>
52+
<dependency>
53+
<groupId>com.fasterxml.jackson.datatype</groupId>
54+
<artifactId>jackson-datatype-jsr310</artifactId>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.openapitools</groupId>
58+
<artifactId>jackson-databind-nullable</artifactId>
59+
<version>0.2.10</version>
60+
</dependency>
61+
<!-- Bean Validation API support -->
62+
<dependency>
63+
<groupId>org.springframework.boot</groupId>
64+
<artifactId>spring-boot-starter-validation</artifactId>
65+
</dependency>
66+
<dependency>
67+
<groupId>com.fasterxml.jackson.core</groupId>
68+
<artifactId>jackson-databind</artifactId>
69+
</dependency>
70+
<dependency>
71+
<groupId>org.springframework.boot</groupId>
72+
<artifactId>spring-boot-starter-test</artifactId>
73+
<scope>test</scope>
74+
</dependency>
75+
</dependencies>
76+
</project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.openapitools.api;
2+
3+
import org.springframework.web.context.request.NativeWebRequest;
4+
5+
import jakarta.servlet.http.HttpServletResponse;
6+
import java.io.IOException;
7+
8+
public class ApiUtil {
9+
public static void setExampleResponse(NativeWebRequest req, String contentType, String example) {
10+
try {
11+
HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class);
12+
if (res != null) {
13+
res.setCharacterEncoding("UTF-8");
14+
res.addHeader("Content-Type", contentType);
15+
res.getWriter().print(example);
16+
}
17+
} catch (IOException e) {
18+
throw new RuntimeException(e);
19+
}
20+
}
21+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.22.0-SNAPSHOT).
3+
* https://openapi-generator.tech
4+
* Do not edit the class manually.
5+
*/
6+
package org.openapitools.api;
7+
8+
import org.springframework.lang.Nullable;
9+
import org.openapitools.model.Order;
10+
import org.springframework.data.web.PagedModel;
11+
import org.springframework.http.ResponseEntity;
12+
import org.springframework.validation.annotation.Validated;
13+
import org.springframework.web.bind.annotation.*;
14+
import org.springframework.web.multipart.MultipartFile;
15+
16+
import jakarta.validation.Valid;
17+
import jakarta.validation.constraints.*;
18+
import java.util.List;
19+
import java.util.Map;
20+
import java.util.Optional;
21+
import jakarta.annotation.Generated;
22+
23+
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.22.0-SNAPSHOT")
24+
@Validated
25+
@RequestMapping("${openapi.openAPIPetstorePagedModelSubstitutionTest.base-path:/v2}")
26+
public interface OrderApi {
27+
28+
String PATH_LIST_ORDERS = "/orders";
29+
/**
30+
* GET /orders : List orders (returns OrderPage — PageMetadata lives in external file)
31+
*
32+
* @param page (optional, default to 0)
33+
* @param size (optional, default to 20)
34+
* @return Paged list of orders (status code 200)
35+
*/
36+
@RequestMapping(
37+
method = RequestMethod.GET,
38+
value = OrderApi.PATH_LIST_ORDERS,
39+
produces = { "application/json" }
40+
)
41+
ResponseEntity<PagedModel<Order>> listOrders(
42+
@Valid @RequestParam(value = "page", required = false, defaultValue = "0") Integer page,
43+
@Valid @RequestParam(value = "size", required = false, defaultValue = "20") Integer size
44+
);
45+
46+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.22.0-SNAPSHOT).
3+
* https://openapi-generator.tech
4+
* Do not edit the class manually.
5+
*/
6+
package org.openapitools.api;
7+
8+
import org.springframework.lang.Nullable;
9+
import org.springframework.data.web.PagedModel;
10+
import org.openapitools.model.Pet;
11+
import org.openapitools.model.SearchResult;
12+
import org.springframework.http.ResponseEntity;
13+
import org.springframework.validation.annotation.Validated;
14+
import org.springframework.web.bind.annotation.*;
15+
import org.springframework.web.multipart.MultipartFile;
16+
17+
import jakarta.validation.Valid;
18+
import jakarta.validation.constraints.*;
19+
import java.util.List;
20+
import java.util.Map;
21+
import java.util.Optional;
22+
import jakarta.annotation.Generated;
23+
24+
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.22.0-SNAPSHOT")
25+
@Validated
26+
@RequestMapping("${openapi.openAPIPetstorePagedModelSubstitutionTest.base-path:/v2}")
27+
public interface PetApi {
28+
29+
String PATH_FIND_PETS = "/pets";
30+
/**
31+
* GET /pets : Find pets — returns raw array, no PagedModel replacement
32+
*
33+
* @return List of pets (status code 200)
34+
*/
35+
@RequestMapping(
36+
method = RequestMethod.GET,
37+
value = PetApi.PATH_FIND_PETS,
38+
produces = { "application/json" }
39+
)
40+
ResponseEntity<List<Pet>> findPets(
41+
42+
);
43+
44+
45+
String PATH_LIST_PETS_PAGED = "/pets/paged";
46+
/**
47+
* GET /pets/paged : List pets using allOf paged form (returns PetPageAllOf)
48+
*
49+
* @return Paged list of pets (status code 200)
50+
*/
51+
@RequestMapping(
52+
method = RequestMethod.GET,
53+
value = PetApi.PATH_LIST_PETS_PAGED,
54+
produces = { "application/json" }
55+
)
56+
ResponseEntity<PagedModel<Pet>> listPetsPaged(
57+
58+
);
59+
60+
61+
String PATH_SEARCH_PETS = "/pets/search";
62+
/**
63+
* GET /pets/search : Search result with no content array — SearchResult should NOT be suppressed
64+
*
65+
* @param q (optional)
66+
* @return Search result (status code 200)
67+
*/
68+
@RequestMapping(
69+
method = RequestMethod.GET,
70+
value = PetApi.PATH_SEARCH_PETS,
71+
produces = { "application/json" }
72+
)
73+
ResponseEntity<SearchResult> searchPets(
74+
@Valid @RequestParam(value = "q", required = false) @Nullable String q
75+
);
76+
77+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.22.0-SNAPSHOT).
3+
* https://openapi-generator.tech
4+
* Do not edit the class manually.
5+
*/
6+
package org.openapitools.api;
7+
8+
import org.springframework.lang.Nullable;
9+
import org.springframework.data.web.PagedModel;
10+
import org.openapitools.model.User;
11+
import org.openapitools.model.UserList;
12+
import org.springframework.http.ResponseEntity;
13+
import org.springframework.validation.annotation.Validated;
14+
import org.springframework.web.bind.annotation.*;
15+
import org.springframework.web.multipart.MultipartFile;
16+
17+
import jakarta.validation.Valid;
18+
import jakarta.validation.constraints.*;
19+
import java.util.List;
20+
import java.util.Map;
21+
import java.util.Optional;
22+
import jakarta.annotation.Generated;
23+
24+
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.22.0-SNAPSHOT")
25+
@Validated
26+
@RequestMapping("${openapi.openAPIPetstorePagedModelSubstitutionTest.base-path:/v2}")
27+
public interface UserApi {
28+
29+
String PATH_LIST_USERS = "/users";
30+
/**
31+
* GET /users : List users (returns UserPage — should be replaced with PagedModel&lt;User&gt;)
32+
*
33+
* @param page (optional, default to 0)
34+
* @param size (optional, default to 20)
35+
* @return Paged list of users (status code 200)
36+
*/
37+
@RequestMapping(
38+
method = RequestMethod.GET,
39+
value = UserApi.PATH_LIST_USERS,
40+
produces = { "application/json" }
41+
)
42+
ResponseEntity<PagedModel<User>> listUsers(
43+
@Valid @RequestParam(value = "page", required = false, defaultValue = "0") Integer page,
44+
@Valid @RequestParam(value = "size", required = false, defaultValue = "20") Integer size
45+
);
46+
47+
48+
String PATH_LIST_USERS_SIMPLE = "/users/list";
49+
/**
50+
* GET /users/list : Simple list of users — UserList should NOT be suppressed
51+
*
52+
* @return Plain list (status code 200)
53+
*/
54+
@RequestMapping(
55+
method = RequestMethod.GET,
56+
value = UserApi.PATH_LIST_USERS_SIMPLE,
57+
produces = { "application/json" }
58+
)
59+
ResponseEntity<UserList> listUsersSimple(
60+
61+
);
62+
63+
}

0 commit comments

Comments
 (0)