Skip to content
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

adding support for @ResponseStatus annotation into spring-http-interface java spring generator #20071

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 6 additions & 2 deletions .github/workflows/samples-jdk17.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:
- samples/client/petstore/java-helidon-client/v3/se/**
- samples/client/petstore/spring-http-interface-reactive/**
- samples/client/petstore/spring-http-interface/**
- samples/client/petstore/spring-http-interface-reactive-noResponseEntity/**
- samples/client/petstore/spring-http-interface-noResponseEntity/**
- samples/client/petstore/java/webclient-jakarta/**
- samples/client/petstore/java/microprofile-rest-client-outer-enum/**
# servers
Expand All @@ -23,6 +25,8 @@ on:
- samples/client/petstore/java-helidon-client/v3/se/**
- samples/client/petstore/spring-http-interface-reactive/**
- samples/client/petstore/spring-http-interface/**
- samples/client/petstore/spring-http-interface-reactive-noResponseEntity/**
- samples/client/petstore/spring-http-interface-noResponseEntity/**
- samples/client/petstore/java/webclient-jakarta/**
- samples/client/petstore/java/microprofile-rest-client-outer-enum/**
# servers
Expand All @@ -44,15 +48,15 @@ jobs:
- samples/client/petstore/java-helidon-client/v3/se
- samples/client/petstore/spring-http-interface-reactive
- samples/client/petstore/spring-http-interface
- samples/client/petstore/spring-http-interface-reactive-noResponseEntity
- samples/client/petstore/spring-http-interface-noResponseEntity
- samples/client/petstore/java/webclient-jakarta
- samples/client/petstore/java/microprofile-rest-client-outer-enum
# servers
- samples/openapi3/server/petstore/springboot-3
- samples/server/petstore/java-camel/
- samples/server/petstore/java-helidon-server/v3/mp/
- samples/server/petstore/java-helidon-server/v3/se
- samples/client/petstore/spring-http-interface-reactive
- samples/client/petstore/spring-http-interface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason to remove these tests?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are duplicated. Same paths are already present in the #clients section. Probably copy/paste issue.

steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
Expand Down
19 changes: 19 additions & 0 deletions bin/configs/spring-http-interface-noResponseEntity.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
generatorName: spring
library: spring-http-interface
outputDir: samples/client/petstore/spring-http-interface-noResponseEntity
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-noResponseEntity
snapshotVersion: "true"
hideGenerationTimestamp: "true"
modelNameSuffix: 'Dto'
generatedConstructorWithRequiredArgs: "false"
# documentation provider should be ignored
documentationProvider: "springdoc"
# annotation provider should be ignored
annotationLibrary: "swagger2"
# validation should be ignored
useBeanValidation: "true"
performBeanValidation: "true"
useResponseEntity: "false"
19 changes: 19 additions & 0 deletions bin/configs/spring-http-interface-reactive-noResponseEntity.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
generatorName: spring
library: spring-http-interface
outputDir: samples/client/petstore/spring-http-interface-reactive-noResponseEntity
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-reactive-noResponseEntity
snapshotVersion: "true"
hideGenerationTimestamp: "true"
reactive: "true"
# documentation provider should be ignored
documentationProvider: "springfox"
# annotation provider should be ignored
annotationLibrary: "swagger1"
# validation should be ignored
useBeanValidation: "true"
performBeanValidation: "true"
useResponseEntity: "false"

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ package {{package}};

{{#imports}}import {{import}};
{{/imports}}
{{^useResponseEntity}}
import org.springframework.http.HttpStatus;
{{/useResponseEntity}}
{{#useResponseEntity}}
import org.springframework.http.ResponseEntity;
{{/useResponseEntity}}
import org.springframework.web.bind.annotation.*;
import org.springframework.web.service.annotation.*;
import org.springframework.web.multipart.MultipartFile;
Expand Down Expand Up @@ -51,6 +56,9 @@ public interface {{classname}} {
{{#isDeprecated}}
@Deprecated
{{/isDeprecated}}
{{^useResponseEntity}}
@ResponseStatus({{#springHttpStatus}}{{#responses.0}}{{{code}}}{{/responses.0}}{{/springHttpStatus}})
{{/useResponseEntity}}
@HttpExchange(
method = "{{{httpMethod}}}",
value = "{{{path}}}",
Expand Down
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/AdditionalPropertiesAnyTypeDto.java
src/main/java/org/openapitools/model/AdditionalPropertiesArrayDto.java
src/main/java/org/openapitools/model/AdditionalPropertiesBooleanDto.java
src/main/java/org/openapitools/model/AdditionalPropertiesClassDto.java
src/main/java/org/openapitools/model/AdditionalPropertiesIntegerDto.java
src/main/java/org/openapitools/model/AdditionalPropertiesNumberDto.java
src/main/java/org/openapitools/model/AdditionalPropertiesObjectDto.java
src/main/java/org/openapitools/model/AdditionalPropertiesStringDto.java
src/main/java/org/openapitools/model/AnimalDto.java
src/main/java/org/openapitools/model/ApiResponseDto.java
src/main/java/org/openapitools/model/ArrayOfArrayOfNumberOnlyDto.java
src/main/java/org/openapitools/model/ArrayOfNumberOnlyDto.java
src/main/java/org/openapitools/model/ArrayTestDto.java
src/main/java/org/openapitools/model/BigCatDto.java
src/main/java/org/openapitools/model/CapitalizationDto.java
src/main/java/org/openapitools/model/CatDto.java
src/main/java/org/openapitools/model/CategoryDto.java
src/main/java/org/openapitools/model/ChildWithNullableDto.java
src/main/java/org/openapitools/model/ClassModelDto.java
src/main/java/org/openapitools/model/ClientDto.java
src/main/java/org/openapitools/model/ContainerDefaultValueDto.java
src/main/java/org/openapitools/model/DogDto.java
src/main/java/org/openapitools/model/EnumArraysDto.java
src/main/java/org/openapitools/model/EnumClassDto.java
src/main/java/org/openapitools/model/EnumTestDto.java
src/main/java/org/openapitools/model/FileDto.java
src/main/java/org/openapitools/model/FileSchemaTestClassDto.java
src/main/java/org/openapitools/model/FormatTestDto.java
src/main/java/org/openapitools/model/HasOnlyReadOnlyDto.java
src/main/java/org/openapitools/model/ListDto.java
src/main/java/org/openapitools/model/MapTestDto.java
src/main/java/org/openapitools/model/MixedPropertiesAndAdditionalPropertiesClassDto.java
src/main/java/org/openapitools/model/Model200ResponseDto.java
src/main/java/org/openapitools/model/NameDto.java
src/main/java/org/openapitools/model/NullableMapPropertyDto.java
src/main/java/org/openapitools/model/NumberOnlyDto.java
src/main/java/org/openapitools/model/OrderDto.java
src/main/java/org/openapitools/model/OuterCompositeDto.java
src/main/java/org/openapitools/model/OuterEnumDto.java
src/main/java/org/openapitools/model/ParentWithNullableDto.java
src/main/java/org/openapitools/model/PetDto.java
src/main/java/org/openapitools/model/ReadOnlyFirstDto.java
src/main/java/org/openapitools/model/ResponseObjectWithDifferentFieldNamesDto.java
src/main/java/org/openapitools/model/ReturnDto.java
src/main/java/org/openapitools/model/SpecialModelNameDto.java
src/main/java/org/openapitools/model/TagDto.java
src/main/java/org/openapitools/model/TypeHolderDefaultDto.java
src/main/java/org/openapitools/model/TypeHolderExampleDto.java
src/main/java/org/openapitools/model/UserDto.java
src/main/java/org/openapitools/model/XmlItemDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.10.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 `WebClient` instance via constructor
```java
@Configuration
public class MyConfiguration extends org.openapitools.configuration.HttpInterfacesAbstractConfigurator {

public MyConfiguration(WebClient myWebClient) { // separately created WebClient instance
super(myWebClient);
}
}
```
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-noResponseEntity</artifactId>
<packaging>jar</packaging>
<name>spring-http-interface-noResponseEntity</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,41 @@
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.10.0-SNAPSHOT).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.api;

import org.openapitools.model.ClientDto;
import org.springframework.http.HttpStatus;
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.10.0-SNAPSHOT")
public interface AnotherFakeApi {

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

}
Loading