Skip to content

Commit e78800b

Browse files
committed
add sample
1 parent 8685cb9 commit e78800b

30 files changed

Lines changed: 1553 additions & 0 deletions
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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.openapi-generator-ignore
2+
README.md
3+
pom.xml
4+
src/main/java/org/openapitools/OpenApiGeneratorApplication.java
5+
src/main/java/org/openapitools/RFC3339DateFormat.java
6+
src/main/java/org/openapitools/api/ApiUtil.java
7+
src/main/java/org/openapitools/api/BinaryBodyApi.java
8+
src/main/java/org/openapitools/api/BinaryBodyApiController.java
9+
src/main/java/org/openapitools/api/CookieApi.java
10+
src/main/java/org/openapitools/api/CookieApiController.java
11+
src/main/java/org/openapitools/api/FormApi.java
12+
src/main/java/org/openapitools/api/FormApiController.java
13+
src/main/java/org/openapitools/api/HeaderApi.java
14+
src/main/java/org/openapitools/api/HeaderApiController.java
15+
src/main/java/org/openapitools/api/JsonBodyApi.java
16+
src/main/java/org/openapitools/api/JsonBodyApiController.java
17+
src/main/java/org/openapitools/api/MultipartApi.java
18+
src/main/java/org/openapitools/api/MultipartApiController.java
19+
src/main/java/org/openapitools/api/PathApi.java
20+
src/main/java/org/openapitools/api/PathApiController.java
21+
src/main/java/org/openapitools/api/QueryApi.java
22+
src/main/java/org/openapitools/api/QueryApiController.java
23+
src/main/java/org/openapitools/configuration/HomeController.java
24+
src/main/java/org/openapitools/configuration/SpringDocConfiguration.java
25+
src/main/java/org/openapitools/model/FormParamsRequest.java
26+
src/main/resources/application.properties
27+
src/main/resources/openapi.yaml
28+
src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.20.0-SNAPSHOT
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# OpenAPI generated server
2+
3+
Spring Boot Server
4+
5+
## Overview
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.
9+
10+
11+
The underlying library integrating OpenAPI to Spring Boot is [springdoc](https://springdoc.org).
12+
Springdoc will generate an OpenAPI v3 specification based on the generated Controller and Model classes.
13+
The specification is available to download using the following url:
14+
http://localhost:8080/v3/api-docs/
15+
16+
Start your server as a simple java application
17+
18+
You can view the api documentation in swagger-ui by pointing to
19+
http://localhost:8080/swagger-ui.html
20+
21+
Change default port value in application.properties
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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>springboot</artifactId>
5+
<packaging>jar</packaging>
6+
<name>springboot</name>
7+
<version>1.0.0-SNAPSHOT</version>
8+
<properties>
9+
<java.version>1.8</java.version>
10+
<maven.compiler.source>${java.version}</maven.compiler.source>
11+
<maven.compiler.target>${java.version}</maven.compiler.target>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<springdoc.version>1.6.14</springdoc.version>
14+
<swagger-ui.version>5.3.1</swagger-ui.version>
15+
</properties>
16+
<parent>
17+
<groupId>org.springframework.boot</groupId>
18+
<artifactId>spring-boot-starter-parent</artifactId>
19+
<version>2.7.15</version>
20+
<relativePath/> <!-- lookup parent from repository -->
21+
</parent>
22+
<build>
23+
<sourceDirectory>src/main/java</sourceDirectory>
24+
<plugins>
25+
<plugin>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-maven-plugin</artifactId>
28+
<configuration>
29+
</configuration>
30+
</plugin>
31+
</plugins>
32+
</build>
33+
<dependencies>
34+
<dependency>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter-web</artifactId>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.springframework.data</groupId>
40+
<artifactId>spring-data-commons</artifactId>
41+
</dependency>
42+
<!--SpringDoc dependencies -->
43+
<dependency>
44+
<groupId>org.springdoc</groupId>
45+
<artifactId>springdoc-openapi-ui</artifactId>
46+
<version>${springdoc.version}</version>
47+
</dependency>
48+
<!-- @Nullable annotation -->
49+
<dependency>
50+
<groupId>com.google.code.findbugs</groupId>
51+
<artifactId>jsr305</artifactId>
52+
<version>3.0.2</version>
53+
</dependency>
54+
<dependency>
55+
<groupId>com.fasterxml.jackson.dataformat</groupId>
56+
<artifactId>jackson-dataformat-yaml</artifactId>
57+
</dependency>
58+
<dependency>
59+
<groupId>com.fasterxml.jackson.datatype</groupId>
60+
<artifactId>jackson-datatype-jsr310</artifactId>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.openapitools</groupId>
64+
<artifactId>jackson-databind-nullable</artifactId>
65+
<version>0.2.8</version>
66+
</dependency>
67+
<!-- Bean Validation API support -->
68+
<dependency>
69+
<groupId>org.springframework.boot</groupId>
70+
<artifactId>spring-boot-starter-validation</artifactId>
71+
</dependency>
72+
<dependency>
73+
<groupId>com.fasterxml.jackson.core</groupId>
74+
<artifactId>jackson-databind</artifactId>
75+
</dependency>
76+
<dependency>
77+
<groupId>org.springframework.boot</groupId>
78+
<artifactId>spring-boot-starter-test</artifactId>
79+
<scope>test</scope>
80+
</dependency>
81+
</dependencies>
82+
</project>
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+
}
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 javax.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: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.20.0-SNAPSHOT).
3+
* https://openapi-generator.tech
4+
* Do not edit the class manually.
5+
*/
6+
package org.openapitools.api;
7+
8+
import io.swagger.v3.oas.annotations.ExternalDocumentation;
9+
import io.swagger.v3.oas.annotations.Operation;
10+
import io.swagger.v3.oas.annotations.Parameter;
11+
import io.swagger.v3.oas.annotations.Parameters;
12+
import io.swagger.v3.oas.annotations.media.ArraySchema;
13+
import io.swagger.v3.oas.annotations.media.Content;
14+
import io.swagger.v3.oas.annotations.media.Schema;
15+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
16+
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
17+
import io.swagger.v3.oas.annotations.tags.Tag;
18+
import io.swagger.v3.oas.annotations.enums.ParameterIn;
19+
import io.swagger.v3.oas.annotations.media.ExampleObject;
20+
import org.springframework.http.HttpStatus;
21+
import org.springframework.http.MediaType;
22+
import org.springframework.http.ResponseEntity;
23+
import org.springframework.validation.annotation.Validated;
24+
import org.springframework.web.bind.annotation.*;
25+
import org.springframework.web.context.request.NativeWebRequest;
26+
import org.springframework.web.multipart.MultipartFile;
27+
28+
import javax.validation.Valid;
29+
import javax.validation.constraints.*;
30+
import java.util.List;
31+
import java.util.Map;
32+
import java.util.Optional;
33+
import javax.annotation.Generated;
34+
35+
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.20.0-SNAPSHOT")
36+
@Validated
37+
@Tag(name = "binary-body", description = "the binary-body API")
38+
public interface BinaryBodyApi {
39+
40+
default Optional<NativeWebRequest> getRequest() {
41+
return Optional.empty();
42+
}
43+
44+
String PATH_BINARY_BODY = "/binary-body";
45+
/**
46+
* POST /binary-body : Raw binary body
47+
*
48+
* @param body (required)
49+
* @return No content (status code 204)
50+
*/
51+
@Operation(
52+
operationId = "binaryBody",
53+
summary = "Raw binary body",
54+
responses = {
55+
@ApiResponse(responseCode = "204", description = "No content")
56+
}
57+
)
58+
@RequestMapping(
59+
method = RequestMethod.POST,
60+
value = BinaryBodyApi.PATH_BINARY_BODY,
61+
consumes = { "application/octet-stream" }
62+
)
63+
default ResponseEntity<Void> binaryBody(
64+
@Parameter(name = "body", description = "", required = true) @Valid @RequestBody org.springframework.core.io.Resource body
65+
) {
66+
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
67+
68+
}
69+
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.openapitools.api;
2+
3+
4+
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.http.HttpStatus;
7+
import org.springframework.http.MediaType;
8+
import org.springframework.http.ResponseEntity;
9+
import org.springframework.stereotype.Controller;
10+
import org.springframework.web.bind.annotation.PathVariable;
11+
import org.springframework.web.bind.annotation.RequestBody;
12+
import org.springframework.web.bind.annotation.RequestHeader;
13+
import org.springframework.web.bind.annotation.RequestMapping;
14+
import org.springframework.web.bind.annotation.CookieValue;
15+
import org.springframework.web.bind.annotation.RequestParam;
16+
import org.springframework.web.bind.annotation.RequestPart;
17+
import org.springframework.web.multipart.MultipartFile;
18+
import org.springframework.web.context.request.NativeWebRequest;
19+
20+
import javax.validation.constraints.*;
21+
import javax.validation.Valid;
22+
23+
import java.util.List;
24+
import java.util.Map;
25+
import java.util.Optional;
26+
import javax.annotation.Generated;
27+
28+
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.20.0-SNAPSHOT")
29+
@Controller
30+
@RequestMapping("${openapi.byteFormatEdgeCases.base-path:}")
31+
public class BinaryBodyApiController implements BinaryBodyApi {
32+
33+
private final NativeWebRequest request;
34+
35+
@Autowired
36+
public BinaryBodyApiController(NativeWebRequest request) {
37+
this.request = request;
38+
}
39+
40+
@Override
41+
public Optional<NativeWebRequest> getRequest() {
42+
return Optional.ofNullable(request);
43+
}
44+
45+
}

0 commit comments

Comments
 (0)