Skip to content

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

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
814ee9b
spring-http-interface: introduce `springHttpClientAdapter`, fix `para…
ibaranga Sep 29, 2024
f1bbe1b
fix imports
ibaranga Sep 29, 2024
4e03298
Update SpringCodegen.java
ibaranga Sep 29, 2024
0f9bfb1
fix docs and default value
ibaranga Oct 1, 2024
33649f3
Merge remote-tracking branch 'origin/master'
ibaranga Oct 1, 2024
c85e8cd
Merge remote-tracking branch 'myfork/master'
ibaranga Oct 1, 2024
4c3bdae
fix docs and default value
ibaranga Oct 1, 2024
277c928
Merge remote-tracking branch 'origin/master'
ibaranga Oct 9, 2024
6addc9a
revert to HttpServiceProxyFactory.builder for backward compatibility
ibaranga Oct 16, 2024
21e024a
Merge remote-tracking branch 'origin/master'
ibaranga Oct 16, 2024
1ab55cd
Merge remote-tracking branch 'origin/master'
ibaranga Oct 17, 2024
0cd4f75
Merge remote-tracking branch 'origin/master'
ibaranga Nov 30, 2024
6a55e5d
spring-http-interface: introduce `useHttpServiceProxyFactoryInterface…
ibaranga Nov 30, 2024
d84e5f3
Merge remote-tracking branch 'origin/master'
ibaranga Nov 30, 2024
02bb3c7
spring-http-interface: introduce `useHttpServiceProxyFactoryInterface…
ibaranga Nov 30, 2024
c79efb9
spring-http-interface: introduce `useHttpServiceProxyFactoryInterface…
ibaranga Nov 30, 2024
79fbb71
spring-http-interface: fix generated files
ibaranga Nov 30, 2024
176322a
Merge remote-tracking branch 'origin/master'
ibaranga Mar 4, 2025
71e28b3
remove unnecessary imports from httpServiceProxyFactoryInterfacesConf…
ibaranga Mar 4, 2025
3de14ae
Merge branch 'OpenAPITools:master' into master
ibaranga Mar 4, 2025
6408374
remove unnecessary paramDoc.mustache, update `useHttpServiceProxyFact…
ibaranga Mar 6, 2025
ba281f4
Merge remote-tracking branch 'origin/master'
ibaranga Mar 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/samples-jdk17.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- samples/client/petstore/spring-http-interface/**
- samples/client/petstore/spring-http-interface-reactive-noResponseEntity/**
- samples/client/petstore/spring-http-interface-noResponseEntity/**
- samples/client/petstore/spring-http-interface-useHttpServiceProxyFactoryInterfacesConfigurator/**
- samples/client/petstore/java/webclient-jakarta/**
- samples/client/petstore/java/microprofile-rest-client-outer-enum/**
# servers
Expand All @@ -27,6 +28,7 @@ on:
- samples/client/petstore/spring-http-interface/**
- samples/client/petstore/spring-http-interface-reactive-noResponseEntity/**
- samples/client/petstore/spring-http-interface-noResponseEntity/**
- samples/client/petstore/spring-http-interface-useHttpServiceProxyFactoryInterfacesConfigurator/**
- samples/client/petstore/java/webclient-jakarta/**
- samples/client/petstore/java/microprofile-rest-client-outer-enum/**
# servers
Expand All @@ -50,6 +52,7 @@ jobs:
- samples/client/petstore/spring-http-interface
- samples/client/petstore/spring-http-interface-reactive-noResponseEntity
- samples/client/petstore/spring-http-interface-noResponseEntity
- samples/client/petstore/spring-http-interface-useHttpServiceProxyFactoryInterfacesConfigurator
- samples/client/petstore/java/webclient-jakarta
- samples/client/petstore/java/microprofile-rest-client-outer-enum
# servers
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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"
1 change: 1 addition & 0 deletions docs/generators/java-camel.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|useBeanValidation|Use BeanValidation API annotations| |true|
|useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false|
|useFeignClientUrl|Whether to generate Feign client with url parameter.| |true|
|useHttpServiceProxyFactoryInterfacesConfigurator|Generate HttpInterfacesAbstractConfigurator based on an HttpServiceProxyFactory instance (as opposed to a WebClient instance, when disabled) for generating Spring HTTP interfaces.| |false|
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
|useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false|
|useOptional|Use Optional container for optional parameters| |false|
Expand Down
1 change: 1 addition & 0 deletions docs/generators/spring.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|useBeanValidation|Use BeanValidation API annotations| |true|
|useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false|
|useFeignClientUrl|Whether to generate Feign client with url parameter.| |true|
|useHttpServiceProxyFactoryInterfacesConfigurator|Generate HttpInterfacesAbstractConfigurator based on an HttpServiceProxyFactory instance (as opposed to a WebClient instance, when disabled) for generating Spring HTTP interfaces.| |false|
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
|useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false|
|useOptional|Use Optional container for optional parameters| |false|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,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";
Expand Down Expand Up @@ -152,6 +154,7 @@ public enum RequestMappingMode {
protected RequestMappingMode requestMappingMode = RequestMappingMode.controller;
@Getter @Setter
protected boolean optionalAcceptNullable = true;
@Setter boolean useHttpServiceProxyFactoryInterfacesConfigurator = false;

public SpringCodegen() {
super();
Expand Down Expand Up @@ -260,6 +263,10 @@ public SpringCodegen() {
"Use `ofNullable` instead of just `of` to accept null values when using Optional.",
optionalAcceptNullable));

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.")
.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.");
Expand Down Expand Up @@ -438,7 +445,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("Nullable", "org.springframework.lang.Nullable");
Expand Down Expand Up @@ -524,9 +533,19 @@ 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"
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ By using the [OpenAPI-Spec](https://openapis.org), you can easily generate an AP
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
To use auto-generated interfaces you have to create your own configuration which extends default abstract configurator & provide `{{httpInterfacesConfiguratorDependency}}` instance via constructor
```java
@Configuration
public class MyConfiguration extends {{configPackage}}.HttpInterfacesAbstractConfigurator {

public MyConfiguration(WebClient myWebClient) { // separately created WebClient instance
super(myWebClient);
public MyConfiguration({{httpInterfacesConfiguratorDependency}} my{{httpInterfacesConfiguratorDependency}}) { // separately created {{httpInterfacesConfiguratorDependency}} instance
super(my{{httpInterfacesConfiguratorDependency}});
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* 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.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.13.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,76 @@
<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.1.3</version>
<relativePath/> <!-- lookup parent from repository -->
</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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.13.0-SNAPSHOT).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.api;

import org.openapitools.model.Client;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.service.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import jakarta.annotation.Generated;


@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.13.0-SNAPSHOT")
public interface AnotherFakeApi {

/**
* PATCH /another-fake/dummy : To test special tags
* To test special tags and operation ID starting with number
*
* @param client client model (required)
* @return successful operation (status code 200)
*/
@HttpExchange(
method = "PATCH",
value = "/another-fake/dummy",
accept = { "application/json" },
contentType = "application/json"
)
ResponseEntity<Client> call123testSpecialTags(
@RequestBody Client client
);

}
Loading