-
-
Notifications
You must be signed in to change notification settings - Fork 7k
spring-http-interface: introduce springHttpClientAdapter
, fix paramDoc.mustache
#19710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 17 commits
814ee9b
f1bbe1b
4e03298
0f9bfb1
33649f3
c85e8cd
4c3bdae
277c928
6addc9a
21e024a
1ab55cd
0cd4f75
6a55e5d
d84e5f3
02bb3c7
c79efb9
79fbb71
176322a
71e28b3
3de14ae
6408374
ba281f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
generatorName: spring | ||
library: spring-http-interface | ||
outputDir: samples/client/petstore/spring-http-interface-useHttpServiceProxyFactoryInterfacesConfigurator | ||
inputSpec: modules/openapi-generator/src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring | ||
additionalProperties: | ||
artifactId: spring-http-interface-useHttpServiceProxyFactoryInterfacesConfigurator | ||
snapshotVersion: "true" | ||
hideGenerationTimestamp: "true" | ||
# documentation provider should be ignored | ||
documentationProvider: "springdoc" | ||
# annotation provider should be ignored | ||
annotationLibrary: "swagger2" | ||
# validation should be ignored | ||
useBeanValidation: "true" | ||
performBeanValidation: "true" | ||
useHttpServiceProxyFactoryInterfacesConfigurator: "true" | ||
# needed until updating the default parentVersion (3.1.3) to 3.2+ | ||
parentGroupId: "org.springframework.boot" | ||
parentArtifactId: "spring-boot-starter-parent" | ||
parentVersion: "3.2.0" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,8 @@ public class SpringCodegen extends AbstractJavaCodegen | |
public static final String SPRING_BOOT = "spring-boot"; | ||
public static final String SPRING_CLOUD_LIBRARY = "spring-cloud"; | ||
public static final String SPRING_HTTP_INTERFACE = "spring-http-interface"; | ||
public static final String USE_HTTP_SERVICE_PROXY_FACTORY_INTERFACES_CONFIGURATOR = "useHttpServiceProxyFactoryInterfacesConfigurator"; | ||
public static final String HTTP_INTERFACES_CONFIGURATOR_DEPENDENCY = "httpInterfacesConfiguratorDependency"; | ||
public static final String API_FIRST = "apiFirst"; | ||
public static final String SPRING_CONTROLLER = "useSpringController"; | ||
public static final String HATEOAS = "hateoas"; | ||
|
@@ -165,6 +167,7 @@ public class SpringCodegen extends AbstractJavaCodegen | |
protected boolean generatedConstructorWithRequiredArgs = true; | ||
@Getter @Setter | ||
protected RequestMappingMode requestMappingMode = RequestMappingMode.controller; | ||
@Setter boolean useHttpServiceProxyFactoryInterfacesConfigurator = false; | ||
|
||
public SpringCodegen() { | ||
super(); | ||
|
@@ -268,6 +271,10 @@ public SpringCodegen() { | |
generatedConstructorWithRequiredArgs)); | ||
cliOptions.add(new CliOption(RESOURCE_FOLDER, RESOURCE_FOLDER_DESC).defaultValue(this.getResourceFolder())); | ||
|
||
cliOptions.add(CliOption.newString(USE_HTTP_SERVICE_PROXY_FACTORY_INTERFACES_CONFIGURATOR, | ||
"Generate HttpInterfacesAbstractConfigurator based on an HttpServiceProxyFactory instance (as opposed to a WebClient instance, when disabled) for generating Spring HTTP interfaces. Requires spring-web 6.1+.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is this still true after removing the two imports mentioned in my other comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The mention of spring-web 6.1+ is still there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My bad, I missed that commit, pushed it now. |
||
.defaultValue("false") | ||
); | ||
supportedLibraries.put(SPRING_BOOT, "Spring-boot Server application."); | ||
supportedLibraries.put(SPRING_CLOUD_LIBRARY, | ||
"Spring-Cloud-Feign client with Spring-Boot auto-configured settings."); | ||
|
@@ -443,7 +450,9 @@ public void processOpts() { | |
useJakartaEe=true; | ||
applyJakartaPackage(); | ||
} | ||
|
||
convertPropertyToStringAndWriteBack(RESOURCE_FOLDER, this::setResourceFolder); | ||
convertPropertyToBooleanAndWriteBack(USE_HTTP_SERVICE_PROXY_FACTORY_INTERFACES_CONFIGURATOR, this::setUseHttpServiceProxyFactoryInterfacesConfigurator); | ||
|
||
typeMapping.put("file", "org.springframework.core.io.Resource"); | ||
importMapping.put("org.springframework.core.io.Resource", "org.springframework.core.io.Resource"); | ||
|
@@ -528,9 +537,20 @@ public void processOpts() { | |
} | ||
} | ||
} else if (SPRING_HTTP_INTERFACE.equals(library)) { | ||
supportingFiles.add(new SupportingFile("httpInterfacesConfiguration.mustache", | ||
String httpInterfacesAbstractConfiguratorFile = useHttpServiceProxyFactoryInterfacesConfigurator ? | ||
"httpServiceProxyFactoryInterfacesConfigurator.mustache" : | ||
"httpInterfacesConfiguration.mustache"; | ||
|
||
supportingFiles.add(new SupportingFile(httpInterfacesAbstractConfiguratorFile, | ||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "HttpInterfacesAbstractConfigurator.java")); | ||
|
||
writePropertyBack(USE_BEANVALIDATION, false); | ||
|
||
writePropertyBack(HTTP_INTERFACES_CONFIGURATOR_DEPENDENCY, | ||
useHttpServiceProxyFactoryInterfacesConfigurator ? | ||
"HttpServiceProxyFactory" : | ||
"WebClient" | ||
); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* 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.client.RestClient; | ||
import org.springframework.web.client.support.RestClientAdapter; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The imports for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed! |
||
import org.springframework.web.service.invoker.HttpServiceProxyFactory; | ||
|
||
public abstract class HttpInterfacesAbstractConfigurator { | ||
|
||
private final HttpServiceProxyFactory factory; | ||
|
||
public HttpInterfacesAbstractConfigurator(final HttpServiceProxyFactory factory) { | ||
this.factory = factory; | ||
} | ||
|
||
{{#apiInfo}} | ||
{{#apis}} | ||
@Bean(name = "{{configPackage}}.HttpInterfacesAbstractConfigurator.{{classVarName}}") | ||
{{classname}} {{classVarName}}HttpProxy() { | ||
return factory.createClient({{classname}}.class); | ||
} | ||
|
||
{{/apis}} | ||
{{/apiInfo}} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# OpenAPI Generator Ignore | ||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator | ||
|
||
# Use this file to prevent files from being overwritten by the generator. | ||
# The patterns follow closely to .gitignore or .dockerignore. | ||
|
||
# As an example, the C# client generator defines ApiClient.cs. | ||
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: | ||
#ApiClient.cs | ||
|
||
# You can match any string of characters against a directory, file or extension with a single asterisk (*): | ||
#foo/*/qux | ||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux | ||
|
||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**): | ||
#foo/**/qux | ||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux | ||
|
||
# You can also negate patterns with an exclamation (!). | ||
# For example, you can ignore all files in a docs folder with the file extension .md: | ||
#docs/*.md | ||
# Then explicitly reverse the ignore rule for a single file: | ||
#!docs/README.md |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
README.md | ||
pom.xml | ||
src/main/java/org/openapitools/api/AnotherFakeApi.java | ||
src/main/java/org/openapitools/api/FakeApi.java | ||
src/main/java/org/openapitools/api/FakeClassnameTags123Api.java | ||
src/main/java/org/openapitools/api/PetApi.java | ||
src/main/java/org/openapitools/api/StoreApi.java | ||
src/main/java/org/openapitools/api/UserApi.java | ||
src/main/java/org/openapitools/configuration/HttpInterfacesAbstractConfigurator.java | ||
src/main/java/org/openapitools/model/AdditionalPropertiesAnyType.java | ||
src/main/java/org/openapitools/model/AdditionalPropertiesArray.java | ||
src/main/java/org/openapitools/model/AdditionalPropertiesBoolean.java | ||
src/main/java/org/openapitools/model/AdditionalPropertiesClass.java | ||
src/main/java/org/openapitools/model/AdditionalPropertiesInteger.java | ||
src/main/java/org/openapitools/model/AdditionalPropertiesNumber.java | ||
src/main/java/org/openapitools/model/AdditionalPropertiesObject.java | ||
src/main/java/org/openapitools/model/AdditionalPropertiesString.java | ||
src/main/java/org/openapitools/model/Animal.java | ||
src/main/java/org/openapitools/model/ArrayOfArrayOfNumberOnly.java | ||
src/main/java/org/openapitools/model/ArrayOfNumberOnly.java | ||
src/main/java/org/openapitools/model/ArrayTest.java | ||
src/main/java/org/openapitools/model/BigCat.java | ||
src/main/java/org/openapitools/model/Capitalization.java | ||
src/main/java/org/openapitools/model/Cat.java | ||
src/main/java/org/openapitools/model/Category.java | ||
src/main/java/org/openapitools/model/ChildWithNullable.java | ||
src/main/java/org/openapitools/model/ClassModel.java | ||
src/main/java/org/openapitools/model/Client.java | ||
src/main/java/org/openapitools/model/ContainerDefaultValue.java | ||
src/main/java/org/openapitools/model/Dog.java | ||
src/main/java/org/openapitools/model/EnumArrays.java | ||
src/main/java/org/openapitools/model/EnumClass.java | ||
src/main/java/org/openapitools/model/EnumTest.java | ||
src/main/java/org/openapitools/model/File.java | ||
src/main/java/org/openapitools/model/FileSchemaTestClass.java | ||
src/main/java/org/openapitools/model/FormatTest.java | ||
src/main/java/org/openapitools/model/HasOnlyReadOnly.java | ||
src/main/java/org/openapitools/model/MapTest.java | ||
src/main/java/org/openapitools/model/MixedPropertiesAndAdditionalPropertiesClass.java | ||
src/main/java/org/openapitools/model/Model200Response.java | ||
src/main/java/org/openapitools/model/ModelApiResponse.java | ||
src/main/java/org/openapitools/model/ModelList.java | ||
src/main/java/org/openapitools/model/ModelReturn.java | ||
src/main/java/org/openapitools/model/Name.java | ||
src/main/java/org/openapitools/model/NullableMapProperty.java | ||
src/main/java/org/openapitools/model/NumberOnly.java | ||
src/main/java/org/openapitools/model/Order.java | ||
src/main/java/org/openapitools/model/OuterComposite.java | ||
src/main/java/org/openapitools/model/OuterEnum.java | ||
src/main/java/org/openapitools/model/ParentWithNullable.java | ||
src/main/java/org/openapitools/model/Pet.java | ||
src/main/java/org/openapitools/model/ReadOnlyFirst.java | ||
src/main/java/org/openapitools/model/ResponseObjectWithDifferentFieldNames.java | ||
src/main/java/org/openapitools/model/SpecialModelName.java | ||
src/main/java/org/openapitools/model/Tag.java | ||
src/main/java/org/openapitools/model/TypeHolderDefault.java | ||
src/main/java/org/openapitools/model/TypeHolderExample.java | ||
src/main/java/org/openapitools/model/User.java | ||
src/main/java/org/openapitools/model/XmlItem.java |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7.11.0-SNAPSHOT |
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 `HttpServiceProxyFactory` instance via constructor | ||
```java | ||
@Configuration | ||
public class MyConfiguration extends org.openapitools.configuration.HttpInterfacesAbstractConfigurator { | ||
|
||
public MyConfiguration(HttpServiceProxyFactory myHttpServiceProxyFactory) { // separately created HttpServiceProxyFactory instance | ||
super(myHttpServiceProxyFactory); | ||
} | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<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>org.openapitools</groupId> | ||
<artifactId>spring-http-interface-useHttpServiceProxyFactoryInterfacesConfigurator</artifactId> | ||
<packaging>jar</packaging> | ||
<name>spring-http-interface-useHttpServiceProxyFactoryInterfacesConfigurator</name> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<properties> | ||
<java.version>17</java.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>3.2.0</version> | ||
</parent> | ||
|
||
<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> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.datatype</groupId> | ||
<artifactId>jackson-datatype-jsr310</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openapitools</groupId> | ||
<artifactId>jackson-databind-nullable</artifactId> | ||
<version>0.2.6</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still true after removing the two imports mentioned in my other comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, removed the parent overrides!