Skip to content

Commit 5222df2

Browse files
committed
Merge branch 'bugfix/pagedModel-use-import-mapping-and-schema-mapping' into bugfix/pagedModel-for-declarative-http-interface
2 parents 2764446 + c837967 commit 5222df2

23 files changed

Lines changed: 119 additions & 28 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

docs/generators/java-camel.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
104104
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
105105
|sourceFolder|source folder for generated code| |src/main/java|
106106
|springApiVersion|Value for 'version' attribute in @RequestMapping (for Spring 7 and above).| |null|
107-
|substituteGenericPagedModel|Detect schemas that represent paginated responses (an object with a 'content' array property and a pagination-metadata property) and replace their generated references with org.springframework.data.web.PagedModel<T>. The detected page schemas and the pagination metadata schema are suppressed from code generation. Only applies when library=spring-boot.| |false|
107+
|substituteGenericPagedModel|Detect schemas that represent paginated responses (an object with a 'content' array property and a 'page' pagination-metadata property) and replace their generated references with PagedModel<T> generated into config package (default 'org.openapitools.configuration'). The detected page schemas and the pagination metadata schema are suppressed from code generation. Only applies when library=spring-boot.| |false|
108108
|testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi|
109109
|title|server title name or client service name| |OpenAPI Spring|
110110
|unhandledException|Declare operation methods to throw a generic exception and allow unhandled exceptions (useful for Spring `@ControllerAdvice` directives).| |false|

docs/generators/kotlin-spring.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
5858
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |null|
5959
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |null|
6060
|sourceFolder|source folder for generated code| |src/main/kotlin|
61-
|substituteGenericPagedModel|Detect schemas that represent paginated responses (an object with a 'content' array property and a pagination-metadata property) and replace their generated references with org.springframework.data.web.PagedModel<T>. The detected page schemas and the pagination metadata schema are suppressed from code generation. Only applies when library=spring-boot.| |false|
61+
|substituteGenericPagedModel|Detect schemas that represent paginated responses (an object with a 'content' array property and a 'page' pagination-metadata property) and replace their generated references with PagedModel<T> generated into config package (default 'org.openapitools.configuration'). The detected page schemas and the pagination metadata schema are suppressed from code generation. Only applies when library=spring-boot.| |false|
6262
|title|server title name or client service name| |OpenAPI Kotlin Spring|
6363
|useBeanValidation|Use BeanValidation API annotations to validate data types| |true|
6464
|useFeignClientUrl|Whether to generate Feign client with url parameter.| |true|

docs/generators/spring.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
9797
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
9898
|sourceFolder|source folder for generated code| |src/main/java|
9999
|springApiVersion|Value for 'version' attribute in @RequestMapping (for Spring 7 and above).| |null|
100-
|substituteGenericPagedModel|Detect schemas that represent paginated responses (an object with a 'content' array property and a pagination-metadata property) and replace their generated references with org.springframework.data.web.PagedModel<T>. The detected page schemas and the pagination metadata schema are suppressed from code generation. Only applies when library=spring-boot.| |false|
100+
|substituteGenericPagedModel|Detect schemas that represent paginated responses (an object with a 'content' array property and a 'page' pagination-metadata property) and replace their generated references with PagedModel<T> generated into config package (default 'org.openapitools.configuration'). The detected page schemas and the pagination metadata schema are suppressed from code generation. Only applies when library=spring-boot.| |false|
101101
|testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi|
102102
|title|server title name or client service name| |OpenAPI Spring|
103103
|unhandledException|Declare operation methods to throw a generic exception and allow unhandled exceptions (useful for Spring `@ControllerAdvice` directives).| |false|

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/java/org/openapitools/codegen/languages/KotlinSpringServerCodegen.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,9 @@ public KotlinSpringServerCodegen() {
298298
addSwitch(GENERATE_SORT_VALIDATION, "Generate a @ValidSort annotation and SortValidator class, and apply @ValidSort to the injected Pageable parameter of operations whose 'sort' parameter has enum values. The annotation validates that sort values in the Pageable object match the allowed enum values from the spec. Requires useBeanValidation=true and library=spring-boot.", generateSortValidation);
299299
addSwitch(GENERATE_PAGEABLE_CONSTRAINT_VALIDATION, "Generate a @ValidPageable annotation and PageableConstraintValidator class, and apply @ValidPageable to the injected Pageable parameter of operations whose 'page' or 'size' parameter specifies a maximum constraint. The annotation enforces those constraints on the Pageable object that replaces the individual page/size query parameters. Requires useBeanValidation=true and library=spring-boot.", generatePageableConstraintValidation);
300300
addSwitch(SUBSTITUTE_GENERIC_PAGED_MODEL,
301-
"Detect schemas that represent paginated responses (an object with a 'content' array property and a "
301+
"Detect schemas that represent paginated responses (an object with a 'content' array property and a 'page' "
302302
+ "pagination-metadata property) and replace their generated references with "
303-
+ "org.springframework.data.web.PagedModel<T>. The detected page schemas and the pagination metadata "
303+
+ "PagedModel<T> generated into config package (default 'org.openapitools.configuration'). The detected page schemas and the pagination metadata "
304304
+ "schema are suppressed from code generation. Only applies when library=spring-boot.",
305305
substituteGenericPagedModel);
306306
addSwitch(COMPANION_OBJECT, "Whether to generate companion objects in data classes, enabling companion extensions.", companionObject);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,9 @@ public SpringCodegen() {
376376
+ "Requires useBeanValidation=true and library=spring-boot.",
377377
generatePageableConstraintValidation));
378378
cliOptions.add(CliOption.newBoolean(SUBSTITUTE_GENERIC_PAGED_MODEL,
379-
"Detect schemas that represent paginated responses (an object with a 'content' array property and a "
379+
"Detect schemas that represent paginated responses (an object with a 'content' array property and a 'page' "
380380
+ "pagination-metadata property) and replace their generated references with "
381-
+ "org.springframework.data.web.PagedModel<T>. The detected page schemas and the pagination metadata "
381+
+ "PagedModel<T> generated into config package (default 'org.openapitools.configuration'). The detected page schemas and the pagination metadata "
382382
+ "schema are suppressed from code generation. Only applies when library=spring-boot.",
383383
substituteGenericPagedModel));
384384

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)

0 commit comments

Comments
 (0)