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 @@ -308,8 +308,13 @@ public String getHelp() {

@Override
public String toApiName(String name) {
if (name == null || name.length() == 0) {
return "DefaultController";
if (name == null || name.length() == 0 || "default".equalsIgnoreCase(name)) {
// Operations without a tag are grouped under the "default" tag. Honor the
// configurable defaultController module name for them (issue #1891); this
// drives both the generated controller file name and connexion's
// x-openapi-router-controller routing, keeping the two consistent.
String controller = defaultController != null ? defaultController : "default_controller";
return camelize(controller);
}
return camelize(name) + "Controller";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,25 @@ public void testRequestBody() throws IOException {
assertFileContains(p4, "def with_path_param_required(param1, body):");
assertFileContains(p4, "test_request = body");
}

@Test(description = "the defaultController option controls the module name for untagged operations (issue #1891)")
public void testDefaultController() throws IOException {
final PythonFlaskConnexionServerCodegen codegen = new PythonFlaskConnexionServerCodegen();
codegen.additionalProperties().put("defaultController", "my_default_controller");
final String outputPath = generateFiles(codegen, "src/test/resources/bugs/issue_1891.yaml");

// The untagged operation should land in the configured controller module...
final Path expected = Paths.get(outputPath + "openapi_server/controllers/my_default_controller.py");
assertFileExists(expected);
assertFileContains(expected, "def ping():");

// ...and connexion's routing must point at the same module, not the hardcoded default.
final Path openapiYaml = Paths.get(outputPath + "openapi_server/openapi/openapi.yaml");
assertFileContains(openapiYaml, "x-openapi-router-controller: openapi_server.controllers.my_default_controller");

// The hardcoded default_controller.py must no longer be emitted.
final Path old = Paths.get(outputPath + "openapi_server/controllers/default_controller.py");
Assert.assertFalse(Files.exists(old),
"Untagged operations should honor defaultController, not fall back to default_controller.py");
}
}
11 changes: 11 additions & 0 deletions modules/openapi-generator/src/test/resources/bugs/issue_1891.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
openapi: 3.0.0
info:
title: Issue 1891 - defaultController
version: 1.0.0
paths:
/ping:
get:
operationId: ping
responses:
'200':
description: ok
Loading