Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,10 @@ public CodegenModel fromModel(String name, Schema model) {
}
else {
// In-placed type (primitive), because there is no mapping or ref for it.
// use camelized `title` if present, otherwise use `type`
String oneOfName = Optional.ofNullable(schema.getTitle()).orElseGet(schema::getType);
// use camelized `title` if present, otherwise use `type`, otherwise the property's base type
String oneOfName = Optional.ofNullable(schema.getTitle())
.or(() -> Optional.ofNullable(ModelUtils.getType(schema)))
.orElse(oneOf.baseType);
oneOf.setName(toModelName(oneOfName));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,20 @@ public void testReqwestTraitUuidParamsUseNamedLifetimes() throws IOException {
"async fn list_widget_items<'id, 'run_id>(&self, id: &'id str, run_id: Option<&'run_id str>)");
TestUtils.assertFileNotContains(outputPath, "Option<&str>");
}

@Test
public void testOneOfMemberWithoutTitleOrType() throws IOException {
Path target = Files.createTempDirectory("test");
target.toFile().deleteOnExit();
final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("rust")
.setInputSpec("src/test/resources/3_0/rust/oneof-member-without-type.yaml")
.setSkipOverwrite(false)
.setOutputDir(target.toAbsolutePath().toString().replace("\\", "/"));
List<File> files = new DefaultGenerator().opts(configurator.toClientOptInput()).generate();
files.forEach(File::deleteOnExit);
Path outputPath = Path.of(target.toString(), "/src/models/conditions.rs");
TestUtils.assertFileExists(outputPath);
TestUtils.assertFileContains(outputPath, "WorkflowPathCondition(Box<models::WorkflowPathCondition>)");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
openapi: 3.0.3
info:
title: oneOf member without a type
version: "1"
paths:
/conditions:
get:
operationId: getConditions
responses:
"200":
description: ok
content:
application/json:
schema:
$ref: "#/components/schemas/Conditions"
components:
schemas:
Conditions:
type: object
oneOf:
- type: object
maxProperties: 0
- allOf:
- $ref: "#/components/schemas/WorkflowPathCondition"
required:
- workflow_path
maxProperties: 1
WorkflowPathCondition:
type: object
properties:
workflow_path:
type: string
Loading