Skip to content

Commit 2267cbb

Browse files
committed
Merge branch 'master' into bugfix/pagedModel-use-import-mapping-and-schema-mapping
2 parents 5780ef7 + 9490683 commit 2267cbb

18 files changed

Lines changed: 112 additions & 21 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,6 @@ samples/client/petstore/ocaml-recursion-test/_build/
309309

310310
# jetbrain http client
311311
samples/client/jetbrains/adyen/checkout71/http/client/Apis/http-client.private.env.json
312+
313+
# Generated by the run-in-docker.sh
314+
\?/

docs/customization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ Another useful option is `inlineSchemaOptions`, which allows you to customize ho
530530
- `MAP_ITEM_SUFFIX` set the map item suffix
531531
- `SKIP_SCHEMA_REUSE=true` is a special value to skip reusing inline schemas during refactoring
532532
- `REFACTOR_ALLOF_INLINE_SCHEMAS=true` will restore the 6.x (or below) behaviour to refactor allOf inline schemas into $ref. (v7.0.0 will skip the refactoring of these allOf inline schemas by default)
533-
- `RESOLVE_INLINE_ENUMS=true` will refactor inline enum definitions into $ref. This must be activated to allow the renaming of inline enum definitions using `inlineSchemaMappings`.
533+
- `RESOLVE_INLINE_ENUMS=true` will refactor inline enum definitions into $ref. This must be activated to allow the renaming of inline enum definitions using `inlineSchemaNameMappings`.
534534
535535
## OpenAPI Normalizer
536536

modules/openapi-generator/src/main/java/org/openapitools/codegen/TemplateManager.java

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import org.slf4j.LoggerFactory;
1313

1414
import java.io.*;
15+
import java.net.URL;
16+
import java.net.URLConnection;
1517
import java.nio.charset.StandardCharsets;
1618
import java.nio.file.Files;
1719
import java.nio.file.Path;
@@ -146,22 +148,28 @@ public Reader getTemplateReader(String name) {
146148
try {
147149
InputStream is = getInputStream(name);
148150
return new InputStreamReader(is, StandardCharsets.UTF_8);
149-
} catch (FileNotFoundException e) {
151+
} catch (IOException e) {
150152
LOGGER.error(e.getMessage());
151153
throw new RuntimeException("can't load template " + name);
152154
}
153155
}
154156

155-
private InputStream getInputStream(String name) throws FileNotFoundException {
156-
InputStream is;
157-
is = this.getClass().getClassLoader().getResourceAsStream(getCPResourcePath(name));
158-
if (is == null) {
159-
if (name == null || name.contains("..")) {
160-
throw new IllegalArgumentException("Template location must be constrained to template directory.");
161-
}
162-
is = new FileInputStream(name); // May throw but never return a null value
157+
private InputStream getInputStream(String name) throws IOException {
158+
if (name == null || name.contains("..")) {
159+
throw new IllegalArgumentException("Template location must be constrained to template directory.");
160+
}
161+
String cpResourcePath = getCPResourcePath(name);
162+
URL resource = this.getClass().getClassLoader().getResource(cpResourcePath);
163+
if (resource != null) {
164+
// Open a fresh, non-cached connection each time.
165+
// setUseCaches(false) prevents sharing the underlying JarFile across classloaders,
166+
// which avoids "Stream closed" errors when concurrent Gradle workers use isolated
167+
// classloaders that happen to point to the same JAR URL.
168+
URLConnection conn = resource.openConnection();
169+
conn.setUseCaches(false);
170+
return conn.getInputStream();
163171
}
164-
return is;
172+
return new FileInputStream(name); // May throw but never return a null value
165173
}
166174

167175
/**
@@ -180,15 +188,22 @@ public File write(Map<String, Object> data, String template, File target) throws
180188
return writeToFile(target.getPath(), templateContent);
181189
} else {
182190
// Do a straight copy of the file if not listed as supported by the template engine.
183-
InputStream is;
191+
String fullTemplatePath = null;
184192
try {
185193
// look up the file using the same template resolution logic the adapters would use.
186-
String fullTemplatePath = getFullTemplateFile(template);
187-
is = getInputStream(fullTemplatePath);
194+
fullTemplatePath = getFullTemplateFile(template);
188195
} catch (TemplateNotFoundException ex) {
189-
is = new FileInputStream(Paths.get(template).toFile());
196+
// not found on classpath; fall through to direct file read below
197+
}
198+
if (fullTemplatePath != null) {
199+
try (InputStream is = getInputStream(fullTemplatePath)) {
200+
return writeToFile(target.getAbsolutePath(), IOUtils.toByteArray(is));
201+
}
202+
} else {
203+
try (InputStream is = new FileInputStream(Paths.get(template).toFile())) {
204+
return writeToFile(target.getAbsolutePath(), IOUtils.toByteArray(is));
205+
}
190206
}
191-
return writeToFile(target.getAbsolutePath(), IOUtils.toByteArray(is));
192207
}
193208
}
194209

modules/openapi-generator/src/main/resources/JavaSpring/apiController.mustache

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,10 @@ public class {{classname}}Controller implements {{classname}} {
8181
{{^isDelegate}}
8282
{{^reactive}}
8383

84-
@Nullable
8584
private final NativeWebRequest request;
8685

8786
@Autowired
88-
public {{classname}}Controller(@Nullable NativeWebRequest request) {
87+
public {{classname}}Controller(NativeWebRequest request) {
8988
this.request = request;
9089
}
9190

modules/openapi-generator/src/main/resources/python-pydantic-v1/asyncio/rest.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ class RESTClientObject:
128128
if re.search('json', headers['Content-Type'], re.IGNORECASE):
129129
if body is not None:
130130
body = json.dumps(body)
131+
if body is None and post_params:
132+
body = json.dumps(dict(post_params))
131133
args["data"] = body
132134
elif headers['Content-Type'] == 'application/x-www-form-urlencoded': # noqa: E501
133135
args["data"] = aiohttp.FormData(post_params)

modules/openapi-generator/src/main/resources/python-pydantic-v1/rest.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ class RESTClientObject:
172172
request_body = None
173173
if body is not None:
174174
request_body = json.dumps(body)
175+
if body is None and post_params:
176+
request_body = json.dumps(dict(post_params))
175177
r = self.pool_manager.request(
176178
method, url,
177179
body=request_body,

modules/openapi-generator/src/main/resources/python-pydantic-v1/tornado/rest.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ class RESTClientObject:
112112
if re.search('json', headers['Content-Type'], re.IGNORECASE):
113113
if body:
114114
body = json.dumps(body)
115+
if body is None and post_params:
116+
body = json.dumps(dict(post_params))
115117
request.body = body
116118
elif headers['Content-Type'] == 'application/x-www-form-urlencoded': # noqa: E501
117119
request.body = urlencode(post_params)

modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ class RESTClientObject:
156156
if re.search('json', headers['Content-Type'], re.IGNORECASE):
157157
if body is not None:
158158
body = json.dumps(body)
159+
if body is None and post_params:
160+
body = json.dumps(dict(post_params))
159161
args["data"] = body
160162
elif headers['Content-Type'] == 'application/x-www-form-urlencoded':
161163
args["data"] = aiohttp.FormData(post_params)

modules/openapi-generator/src/main/resources/python/httpx/rest.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ class RESTClientObject:
128128
if re.search('json', headers['Content-Type'], re.IGNORECASE):
129129
if body is not None:
130130
args["json"] = body
131+
if body is None and post_params:
132+
args["json"] = dict(post_params)
131133
elif headers['Content-Type'] == 'application/x-www-form-urlencoded': # noqa: E501
132134
args["data"] = dict(post_params)
133135
elif headers['Content-Type'] == 'multipart/form-data':

modules/openapi-generator/src/main/resources/python/tornado/rest.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ class RESTClientObject:
122122
if re.search('json', headers['Content-Type'], re.IGNORECASE):
123123
if body:
124124
body = json.dumps(body)
125+
if body is None and post_params:
126+
body = json.dumps(dict(post_params))
125127
request.body = body
126128
elif headers['Content-Type'] == 'application/x-www-form-urlencoded':
127129
request.body = urlencode(post_params)

0 commit comments

Comments
 (0)