Skip to content

Commit 623463a

Browse files
wing328jarryDk
andauthored
[Java] Fix content for enum in MultiPart (#21428)
* [Java] Fix content for enum in addPartToMultiPartBuilder ([#19973](#19973)) * [Java] Fix content for enum with restclient (#19973) * [Java] Fix content for enum with restclient (#19973) * [Java] Fix content for enum with restclient (#19973) * update samples --------- Co-authored-by: Michael Bornholdt Nielsen <michaelbornholdtnielsen@gmail.com> Co-authored-by: Michael Bornholdt Nielsen <jarryDk@users.noreply.github.com>
1 parent 43e878b commit 623463a

File tree

55 files changed

+3544
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3544
-0
lines changed

.github/workflows/samples-java-client-jdk17.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ on:
77
- samples/client/petstore/java/webclient-jakarta/**
88
- samples/client/petstore/java/restclient-*/**
99
- samples/client/petstore/java/webclient-useSingleRequestParameter/**
10+
- samples/client/others/java/restclient-enum-in-multipart/**
1011
pull_request:
1112
paths:
1213
- samples/client/petstore/java/resttemplate-jakarta/**
1314
- samples/client/petstore/java/webclient-jakarta/**
1415
- samples/client/petstore/java/restclient-*/**
1516
- samples/client/petstore/java/webclient-useSingleRequestParameter/**
17+
- samples/client/others/java/restclient-enum-in-multipart/**
1618
jobs:
1719
build:
1820
name: Build Java Client JDK17
@@ -30,6 +32,7 @@ jobs:
3032
- samples/client/petstore/java/restclient-useSingleRequestParameter
3133
- samples/client/petstore/java/restclient-useSingleRequestParameter-static
3234
- samples/client/petstore/java/webclient-useSingleRequestParameter
35+
- samples/client/others/java/restclient-enum-in-multipart
3336
steps:
3437
- uses: actions/checkout@v4
3538
- uses: actions/setup-java@v4
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
generatorName: java
2+
outputDir: samples/client/others/java/restclient-enum-in-multipart
3+
library: restclient
4+
inputSpec: modules/openapi-generator/src/test/resources/3_1/enum-in-multipart.yaml
5+
templateDir: modules/openapi-generator/src/main/resources/Java
6+
additionalProperties:
7+
hideGenerationTimestamp: "true"

modules/openapi-generator/src/main/resources/Java/libraries/restclient/ApiClient.mustache

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,18 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
685685
addCookiesToRequest(cookieParams, requestBuilder);
686686
addCookiesToRequest(defaultCookies, requestBuilder);
687687
688+
if (MediaType.MULTIPART_FORM_DATA.isCompatibleWith(contentType)) {
689+
formParams.forEach(
690+
(k, v) -> {
691+
if (v instanceof java.util.ArrayList) {
692+
Object o = v.get(0);
693+
if (o != null && o.getClass().getEnumConstants() != null) {
694+
v.set(0, o.toString());
695+
}
696+
}
697+
});
698+
}
699+
688700
var selectedBody = selectBody(body, formParams, contentType);
689701
if (selectedBody != null) {
690702
requestBuilder.body(selectedBody);
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
openapi: 3.1.0
2+
info:
3+
description: API
4+
title: API
5+
version: 1.0.0
6+
servers:
7+
- description: "Localhost, used when testing"
8+
url: http://localhost:8080
9+
security:
10+
- basicAuth: []
11+
paths:
12+
/messages:
13+
post:
14+
description: Creates a new message
15+
x-content-type: multipart/form-data
16+
x-accepts:
17+
- application/json
18+
operationId: CreateMessage
19+
requestBody:
20+
$ref: "#/components/requestBodies/CreateMessageBody"
21+
responses:
22+
"201":
23+
$ref: "#/components/responses/MessageCreatedResponse"
24+
summary: Creates a new message
25+
tags:
26+
- BAS
27+
components:
28+
parameters:
29+
messageId:
30+
description: The identifier the message
31+
explode: false
32+
in: path
33+
name: messageId
34+
required: true
35+
schema:
36+
format: uuid
37+
type: string
38+
style: simple
39+
requestBodies:
40+
CreateMessageBody:
41+
content:
42+
multipart/form-data:
43+
schema:
44+
$ref: "#/components/schemas/CreateMessage_request"
45+
required: true
46+
responses:
47+
MessageCreatedResponse:
48+
content:
49+
application/json:
50+
schema:
51+
$ref: "#/components/schemas/inline_object"
52+
description: The message was created.
53+
schemas:
54+
DataDirection:
55+
description: The direction a message travels
56+
enum:
57+
- INGOING
58+
- OUTGOING
59+
type: string
60+
DataChannel:
61+
description: The transport-channel
62+
enum:
63+
- BIKE
64+
- CAR
65+
- BUS
66+
- PLANE
67+
type: string
68+
messageId:
69+
description: The messageID
70+
format: uuid
71+
type: string
72+
CreateMessage_request:
73+
properties:
74+
fileContent:
75+
description: The message payload
76+
format: binary
77+
type: string
78+
idempotencyKey:
79+
type: string
80+
dataDirection:
81+
$ref: "#/components/schemas/DataDirection"
82+
dataChannel:
83+
$ref: "#/components/schemas/DataChannel"
84+
required:
85+
- dataChannel
86+
- dataDirection
87+
- fileContent
88+
- fileType
89+
- idempotencyKey
90+
type: object
91+
inline_object:
92+
example:
93+
messageId: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
94+
properties:
95+
messageId:
96+
description: The messageID
97+
format: uuid
98+
type: string
99+
required:
100+
- messageId
101+
securitySchemes:
102+
basicAuth:
103+
scheme: basic
104+
type: http
105+

samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,18 @@ protected RestClient.RequestBodySpec prepareRequest(String path, HttpMethod meth
639639
addCookiesToRequest(cookieParams, requestBuilder);
640640
addCookiesToRequest(defaultCookies, requestBuilder);
641641

642+
if (MediaType.MULTIPART_FORM_DATA.isCompatibleWith(contentType)) {
643+
formParams.forEach(
644+
(k, v) -> {
645+
if (v instanceof java.util.ArrayList) {
646+
Object o = v.get(0);
647+
if (o != null && o.getClass().getEnumConstants() != null) {
648+
v.set(0, o.toString());
649+
}
650+
}
651+
});
652+
}
653+
642654
var selectedBody = selectBody(body, formParams, contentType);
643655
if (selectedBody != null) {
644656
requestBuilder.body(selectedBody);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3+
#
4+
# This file is auto-generated by OpenAPI Generator (https://openapi-generator.tech)
5+
6+
name: Java CI with Maven
7+
8+
on:
9+
push:
10+
branches: [ main, master ]
11+
pull_request:
12+
branches: [ main, master ]
13+
14+
jobs:
15+
build:
16+
name: Build API
17+
runs-on: ubuntu-latest
18+
strategy:
19+
matrix:
20+
java: [ 17, 21 ]
21+
steps:
22+
- uses: actions/checkout@v4
23+
- name: Set up JDK
24+
uses: actions/setup-java@v4
25+
with:
26+
java-version: ${{ matrix.java }}
27+
distribution: 'temurin'
28+
cache: maven
29+
- name: Build with Maven
30+
run: mvn -B package --no-transfer-progress --file pom.xml
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
*.class
2+
3+
# Mobile Tools for Java (J2ME)
4+
.mtj.tmp/
5+
6+
# Package Files #
7+
*.jar
8+
*.war
9+
*.ear
10+
11+
# exclude jar for gradle wrapper
12+
!gradle/wrapper/*.jar
13+
14+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
15+
hs_err_pid*
16+
17+
# build files
18+
**/target
19+
target
20+
.gradle
21+
build
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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.github/workflows/maven.yml
2+
.gitignore
3+
.travis.yml
4+
README.md
5+
api/openapi.yaml
6+
build.gradle
7+
build.sbt
8+
docs/BasApi.md
9+
docs/DataChannel.md
10+
docs/DataDirection.md
11+
docs/InlineObject.md
12+
git_push.sh
13+
gradle.properties
14+
gradle/wrapper/gradle-wrapper.jar
15+
gradle/wrapper/gradle-wrapper.properties
16+
gradlew
17+
gradlew.bat
18+
pom.xml
19+
settings.gradle
20+
src/main/AndroidManifest.xml
21+
src/main/java/org/openapitools/client/ApiClient.java
22+
src/main/java/org/openapitools/client/JavaTimeFormatter.java
23+
src/main/java/org/openapitools/client/RFC3339DateFormat.java
24+
src/main/java/org/openapitools/client/RFC3339InstantDeserializer.java
25+
src/main/java/org/openapitools/client/RFC3339JavaTimeModule.java
26+
src/main/java/org/openapitools/client/ServerConfiguration.java
27+
src/main/java/org/openapitools/client/ServerVariable.java
28+
src/main/java/org/openapitools/client/StringUtil.java
29+
src/main/java/org/openapitools/client/api/BasApi.java
30+
src/main/java/org/openapitools/client/auth/ApiKeyAuth.java
31+
src/main/java/org/openapitools/client/auth/Authentication.java
32+
src/main/java/org/openapitools/client/auth/HttpBasicAuth.java
33+
src/main/java/org/openapitools/client/auth/HttpBearerAuth.java
34+
src/main/java/org/openapitools/client/model/DataChannel.java
35+
src/main/java/org/openapitools/client/model/DataDirection.java
36+
src/main/java/org/openapitools/client/model/InlineObject.java
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.14.0-SNAPSHOT
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Generated by OpenAPI Generator: https://openapi-generator.tech
3+
#
4+
# Ref: https://docs.travis-ci.com/user/languages/java/
5+
#
6+
language: java
7+
jdk:
8+
- openjdk12
9+
- openjdk11
10+
- openjdk10
11+
- openjdk9
12+
- openjdk8
13+
before_install:
14+
# ensure gradlew has proper permission
15+
- chmod a+x ./gradlew
16+
script:
17+
# test using maven
18+
#- mvn test
19+
# test using gradle
20+
- gradle test
21+
# test using sbt
22+
# - sbt test

0 commit comments

Comments
 (0)