Skip to content

Commit b54947d

Browse files
committed
Merge pull request #2112 from hideya/fix/swift-sanitize
[Swift] Fix #2095, missing sanitization for operationId
2 parents 6dfc86f + aa09678 commit b54947d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SwiftCodegen.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,21 @@ public String toApiName(String name) {
293293
return initialCaps(name) + "API";
294294
}
295295

296+
@Override
297+
public String toOperationId(String operationId) {
298+
// throw exception if method name is empty
299+
if (StringUtils.isEmpty(operationId)) {
300+
throw new RuntimeException("Empty method name (operationId) not allowed");
301+
}
302+
303+
// method name cannot use reserved keyword, e.g. return
304+
if (reservedWords.contains(operationId)) {
305+
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
306+
}
307+
308+
return camelize(sanitizeName(operationId), true);
309+
}
310+
296311
@Override
297312
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions, Swagger swagger) {
298313
path = normalizePath(path); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.

0 commit comments

Comments
 (0)