- Using NodaTime for date types
This commit is contained in:
Jakub Malek
2016-05-24 14:08:09 +02:00
committed by Jakub Malek
parent d0e3b5cc71
commit cef6c9d8ba
3 changed files with 22 additions and 0 deletions

View File

@@ -1,13 +1,17 @@
package io.swagger.codegen.languages;
import com.google.common.collect.ImmutableMap;
import io.swagger.codegen.CodegenOperation;
import io.swagger.codegen.CodegenProperty;
import io.swagger.codegen.CodegenType;
import io.swagger.codegen.SupportingFile;
import io.swagger.models.properties.Property;
import io.swagger.models.properties.StringProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.Map;
import static io.swagger.codegen.CodegenConstants.*;
import static io.swagger.codegen.CodegenType.SERVER;
@@ -42,6 +46,7 @@ public class NancyFXServerCodegen extends AbstractCSharpCodegen {
addSwitch(USE_DATETIME_OFFSET, USE_DATETIME_OFFSET_DESC, useDateTimeOffsetFlag);
addSwitch(USE_COLLECTION, USE_COLLECTION_DESC, useCollection);
addSwitch(RETURN_ICOLLECTION, RETURN_ICOLLECTION_DESC, returnICollection);
typeMapping.putAll(nodaTimeTypesMappings());
}
@Override
@@ -138,4 +143,19 @@ public class NancyFXServerCodegen extends AbstractCSharpCodegen {
public String toEnumName(CodegenProperty property) {
return sanitizeName(camelize(property.name)) ;
}
@Override
public String getSwaggerType(Property property) {
if (property instanceof StringProperty && "time".equalsIgnoreCase(property.getFormat())) {
return "time";
}
return super.getSwaggerType(property);
}
private static Map<String, String> nodaTimeTypesMappings() {
return ImmutableMap.of(
"time", "LocalTime?",
"date", "ZonedDateTime?",
"datetime", "ZonedDateTime?");
}
}