-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Spring] Spring HTTP Interface library (#14485)
- Loading branch information
Showing
130 changed files
with
16,970 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
generatorName: spring | ||
library: spring-http-interface | ||
outputDir: samples/client/petstore/spring-http-interface-reactive | ||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring | ||
additionalProperties: | ||
artifactId: spring-http-interface-reactive | ||
snapshotVersion: "true" | ||
hideGenerationTimestamp: "true" | ||
reactive: "true" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
generatorName: spring | ||
library: spring-http-interface | ||
outputDir: samples/client/petstore/spring-http-interface | ||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring | ||
additionalProperties: | ||
artifactId: spring-http-interface | ||
snapshotVersion: "true" | ||
hideGenerationTimestamp: "true" | ||
modelNameSuffix: 'Dto' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...i-generator/src/main/resources/JavaSpring/libraries/spring-http-interface/README.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# OpenAPI generated API stub | ||
|
||
[Spring Framework 6 HTTP Interface](https://docs.spring.io/spring-framework/docs/6.0.0/reference/html/integration.html#rest-http-interface) | ||
|
||
|
||
## Overview | ||
This code was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. | ||
By using the [OpenAPI-Spec](https://openapis.org), you can easily generate an API stub. | ||
This is an example of building API stub interfaces in Java using the Spring framework. | ||
|
||
The stubs generated can be used in your existing Spring application for HTTP integration with other REST services | ||
To use auto-generated interfaces you have to create your own configuration which extends default abstract configurator & provide `WebClient` instance via constructor | ||
```java | ||
@Configuration | ||
public class MyConfiguration extends {{configPackage}}.HttpInterfacesAbstractConfigurator { | ||
public MyConfiguration(WebClient myWebClient) { // separately created WebClient instance | ||
super(myWebClient); | ||
} | ||
} | ||
``` |
67 changes: 67 additions & 0 deletions
67
...napi-generator/src/main/resources/JavaSpring/libraries/spring-http-interface/api.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) ({{{generatorVersion}}}). | ||
* https://openapi-generator.tech | ||
* Do not edit the class manually. | ||
*/ | ||
package {{package}}; | ||
|
||
{{#imports}}import {{import}}; | ||
{{/imports}} | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.service.annotation.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
{{#reactive}} | ||
|
||
import org.springframework.http.codec.multipart.Part; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
{{/reactive}} | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import {{javaxPackage}}.annotation.Generated; | ||
|
||
|
||
{{>generatedAnnotation}} | ||
{{#operations}} | ||
public interface {{classname}} { | ||
{{#operation}} | ||
|
||
/** | ||
* {{httpMethod}} {{{path}}}{{#summary}} : {{.}}{{/summary}} | ||
{{#notes}} | ||
* {{.}} | ||
{{/notes}} | ||
* | ||
{{#allParams}} | ||
* @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}} | ||
{{/allParams}} | ||
* @return {{#responses}}{{message}} (status code {{code}}){{^-last}} | ||
* or {{/-last}}{{/responses}} | ||
{{#isDeprecated}} | ||
* @deprecated | ||
{{/isDeprecated}} | ||
{{#externalDocs}} | ||
* {{description}} | ||
* @see <a href="{{url}}">{{summary}} Documentation</a> | ||
{{/externalDocs}} | ||
*/ | ||
{{#isDeprecated}} | ||
@Deprecated | ||
{{/isDeprecated}} | ||
@HttpExchange( | ||
method = "{{{httpMethod}}}", | ||
value = "{{{path}}}"{{#vendorExtensions.x-accepts}}, | ||
accept = "{{{vendorExtensions.x-accepts}}}"{{/vendorExtensions.x-accepts}}{{#vendorExtensions.x-content-type}}, | ||
contentType = "{{{vendorExtensions.x-content-type}}}"{{/vendorExtensions.x-content-type}} | ||
) | ||
{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}( | ||
{{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{>cookieParams}}{{^-last}}, | ||
{{/-last}}{{/allParams}} | ||
){{#unhandledException}} throws Exception{{/unhandledException}}; | ||
|
||
{{/operation}} | ||
} | ||
{{/operations}} |
38 changes: 38 additions & 0 deletions
38
...resources/JavaSpring/libraries/spring-http-interface/httpInterfacesConfiguration.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) ({{{generatorVersion}}}). | ||
* https://openapi-generator.tech | ||
* Do not edit the class manually. | ||
*/ | ||
package {{configPackage}}; | ||
|
||
{{#apiInfo}} | ||
{{#apis}} | ||
import {{apiPackage}}.{{classname}}; | ||
{{/apis}} | ||
{{/apiInfo}} | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import org.springframework.web.reactive.function.client.support.WebClientAdapter; | ||
import org.springframework.web.service.invoker.HttpServiceProxyFactory; | ||
|
||
public abstract class HttpInterfacesAbstractConfigurator { | ||
private final WebClient webClient; | ||
public HttpInterfacesAbstractConfigurator(final WebClient webClient) { | ||
this.webClient = webClient; | ||
} | ||
|
||
{{#apiInfo}} | ||
{{#apis}} | ||
@Bean(name = "{{configPackage}}.HttpInterfacesAbstractConfigurator.{{classVarName}}") | ||
{{classname}} {{classVarName}}HttpProxy() { | ||
HttpServiceProxyFactory factory = HttpServiceProxyFactory.builder(WebClientAdapter.forClient(webClient)).build(); | ||
return factory.createClient({{classname}}.class); | ||
} | ||
|
||
{{/apis}} | ||
{{/apiInfo}} | ||
|
||
} |
98 changes: 98 additions & 0 deletions
98
...napi-generator/src/main/resources/JavaSpring/libraries/spring-http-interface/pom.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>{{groupId}}</groupId> | ||
<artifactId>{{artifactId}}</artifactId> | ||
<packaging>jar</packaging> | ||
<name>{{artifactId}}</name> | ||
<version>{{artifactVersion}}</version> | ||
<properties> | ||
<java.version>17</java.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
{{#parentOverridden}} | ||
<parent> | ||
<groupId>{{{parentGroupId}}}</groupId> | ||
<artifactId>{{{parentArtifactId}}}</artifactId> | ||
<version>{{{parentVersion}}}</version> | ||
</parent> | ||
{{/parentOverridden}} | ||
{{^parentOverridden}} | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>3.0.1</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
{{/parentOverridden}} | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
<configuration> | ||
<source>${java.version}</source> | ||
<target>${java.version}</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<version>3.2.1</version> | ||
<executions> | ||
<execution> | ||
<id>attach-sources</id> | ||
<goals> | ||
<goal>jar-no-fork</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-webflux</artifactId> | ||
</dependency> | ||
<!-- @Nullable annotation --> | ||
<dependency> | ||
<groupId>com.google.code.findbugs</groupId> | ||
<artifactId>jsr305</artifactId> | ||
<version>3.0.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>jakarta.validation</groupId> | ||
<artifactId>jakarta.validation-api</artifactId> | ||
</dependency> | ||
{{#withXml}} | ||
<!-- XML processing: Jackson --> | ||
<dependency> | ||
<groupId>jakarta.xml.bind</groupId> | ||
<artifactId>jakarta.xml.bind-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.dataformat</groupId> | ||
<artifactId>jackson-dataformat-xml</artifactId> | ||
</dependency> | ||
{{/withXml}} | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.datatype</groupId> | ||
<artifactId>jackson-datatype-jsr310</artifactId> | ||
</dependency> | ||
{{#openApiNullable}} | ||
<dependency> | ||
<groupId>org.openapitools</groupId> | ||
<artifactId>jackson-databind-nullable</artifactId> | ||
<version>0.2.2</version> | ||
</dependency> | ||
{{/openApiNullable}} | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
Oops, something went wrong.