Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -4888,6 +4888,9 @@ public CodegenOperation fromOperation(String path,
imports.add(r.baseType);
}

addImportMappedType(imports, r.dataType);
addImportMappedType(imports, r.baseType);

if ("set".equals(r.containerType) && typeMapping.containsKey(r.containerType)) {
op.uniqueItems = true;
imports.add(typeMapping.get(r.containerType));
Expand Down Expand Up @@ -5132,6 +5135,18 @@ public CodegenOperation fromOperation(String path,
return op;
}

/**
* Helper method to add an import for a data type if it exists in the importMapping.
*
* @param imports The set of imports to add to.
* @param dataType The data type to check for a mapping.
*/
protected void addImportMappedType(Set<String> imports, String dataType) {
if (imports != null && dataType != null && importMapping.containsKey(dataType)) {
imports.add(dataType);
}
}

public void SortParametersByRequiredFlag(List<CodegenParameter> parameters) {
Collections.sort(parameters, new Comparator<CodegenParameter>() {
@Override
Expand Down Expand Up @@ -5728,6 +5743,8 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
if (codegenProperty.complexType != null) {
imports.add(codegenProperty.complexType);
}
addImportMappedType(imports, codegenParameter.dataType);
addImportMappedType(imports, codegenParameter.baseType);

codegenParameter.pattern = toRegularExpression(parameterSchema.getPattern());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9163,4 +9163,25 @@ public void testReactiveSpringHttpInterfaceSupportListOfStringReturnTypeNoRespon
"Mono<Set<String>> getUserIdSet"
);
}

@Test
public void issue_24232() throws IOException {
Map<String, File> files = generateFromContract(
"src/test/resources/3_0/spring/issue_24232.yaml", SPRING_BOOT,
Map.of(USE_SPRING_BOOT4, true),
codegenConfigurator ->
codegenConfigurator
.addTypeMapping("string+custom", "MyCustomId")
.addSchemaMapping("MyKey", "MyCustomKey")
.addImportMapping("MyCustomId", "org.myorg.MyCustomId")
.addImportMapping("MyCustomKey", "org.myorg.MyCustomKey"));

JavaFileAssert.assertThat(files.get("SomeApi.java"))
.assertMethod("getDummy", "MyCustomId", "MyCustomKey")
.toFileAssert()
.fileContains("import org.myorg.MyCustomId;", "import org.myorg.MyCustomKey;");

JavaFileAssert.assertThat(files.get("Dummy.java"))
.fileContains("import org.myorg.MyCustomId;", "import org.myorg.MyCustomKey;");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
openapi: 3.0.0
info:
version: "1.0.0"
title: mapping
paths:
/some/dummy/endpoint/{id}:
get:
operationId: getDummy
parameters:
- name: id
in: path
required: true
description: My Custom Id
schema:
$ref: '#/components/schemas/MyId'
- name: key
in: query
required: true
description: filter on key
schema:
$ref: '#/components/schemas/MyKey'
responses:
200:
description: Successfully created reverse listings for retail
content:
application/json:
schema:
$ref: '#/components/schemas/Dummy'
components:
schemas:
Dummy:
type: object
properties:
id:
$ref: '#/components/schemas/MyId'
key:
$ref: '#/components/schemas/MyKey'
MyId:
type: string
format: custom
MyKey:
type: string
Loading