Skip to content

Commit 814fca1

Browse files
author
bllassit
committed
source code for TimeSpan
1 parent bc70f04 commit 814fca1

11 files changed

+51
-1
lines changed

docs/generators/csharp-functions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl
7474
<li>DateTime?</li>
7575
<li>DateTimeOffset</li>
7676
<li>DateTimeOffset?</li>
77+
<li>TimeSpan</li>
78+
<li>TimeSpan?</li>
7779
<li>Decimal</li>
7880
<li>Dictionary</li>
7981
<li>Double</li>

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ public AbstractCSharpCodegen() {
195195
"DateTimeOffset",
196196
"DateOnly?",
197197
"DateOnly",
198+
"TimeSpan?",
199+
"TimeSpan",
198200
"Boolean",
199201
"Double",
200202
"Decimal",
@@ -1427,6 +1429,10 @@ public String toDefaultValue(Schema p) {
14271429
if (p.getDefault() != null) {
14281430
return "\"" + p.getDefault().toString() + "\"";
14291431
}
1432+
} else if (ModelUtils.isDurationSchema(p)) {
1433+
if (p.getDefault() != null) {
1434+
return "\"" + p.getDefault().toString() + "\"";
1435+
}
14301436
} else if (ModelUtils.isNumberSchema(p)) {
14311437
if (p.getDefault() != null) {
14321438
if (ModelUtils.isFloatSchema(p)) { // float
@@ -1986,7 +1992,7 @@ protected Set<String> getNullableTypes() {
19861992
}
19871993

19881994
protected Set<String> getValueTypes() {
1989-
return new HashSet<>(Arrays.asList("decimal", "bool", "int", "uint", "long", "ulong", "float", "double", "DateTime", "DateOnly", "DateTimeOffset", "Guid"));
1995+
return new HashSet<>(Arrays.asList("decimal", "bool", "int", "uint", "long", "ulong", "float", "double", "DateTime", "DateOnly", "DateTimeOffset", "TimeSpan", "Guid"));
19901996
}
19911997

19921998
protected void setTypeMapping() {
@@ -2006,6 +2012,7 @@ protected void setTypeMapping() {
20062012
typeMapping.put("BigDecimal", "decimal");
20072013
typeMapping.put("DateTime", this.useDateTimeOffsetFlag ? "DateTimeOffset" : "DateTime");
20082014
typeMapping.put("date", this.useDateOnly() ? "DateOnly" : "DateTime");
2015+
typeMapping.put("duration", "TimeSpan");
20092016
typeMapping.put("file", "System.IO.Stream");
20102017
typeMapping.put("array", "List");
20112018
typeMapping.put("list", "List");

modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,12 @@ public static boolean isDateTimeSchema(Schema schema) {
692692
&& SchemaTypeUtil.DATE_TIME_FORMAT.equals(schema.getFormat()));
693693
}
694694

695+
public static boolean isDurationSchema(Schema schema) {
696+
// format: duration (todo: swagger parser does not support duration)
697+
return (SchemaTypeUtil.STRING_TYPE.equals(getType(schema))
698+
&& "duration".equals(schema.getFormat()));
699+
}
700+
695701
public static boolean isPasswordSchema(Schema schema) {
696702
return (schema instanceof PasswordSchema) ||
697703
// double

modules/openapi-generator/src/test/resources/3_0/csharp-netcore/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,10 @@ components:
15921592
type: string
15931593
format: date-time
15941594
example: '2007-12-03T10:15:30+01:00'
1595+
duration:
1596+
type: string
1597+
format: duration
1598+
example: '1.03:14:56.1667'
15951599
uuid:
15961600
type: string
15971601
format: uuid

modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature-oneof-primitive-types.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,7 @@ components:
16581658
- number
16591659
- byte
16601660
- date
1661+
- duration
16611662
- password
16621663
properties:
16631664
integer:
@@ -1718,6 +1719,10 @@ components:
17181719
type: string
17191720
format: date-time
17201721
example: '2007-12-03T10:15:30+01:00'
1722+
duration:
1723+
type: string
1724+
format: duration
1725+
example: '1.03:14:56.1667'
17211726
uuid:
17221727
type: string
17231728
format: uuid

modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,6 +1672,7 @@ components:
16721672
- number
16731673
- byte
16741674
- date
1675+
- duration
16751676
- password
16761677
properties:
16771678
integer:
@@ -1750,6 +1751,10 @@ components:
17501751
type: string
17511752
format: date-time
17521753
example: '2007-12-03T10:15:30+01:00'
1754+
duration:
1755+
type: string
1756+
format: duration
1757+
example: '1.03:14:56.1667'
17531758
uuid:
17541759
type: string
17551760
format: uuid

modules/openapi-generator/src/test/resources/3_0/petstore-echo.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,7 @@ components:
15491549
- number
15501550
- byte
15511551
- date
1552+
- duration
15521553
- password
15531554
properties:
15541555
integer:
@@ -1595,6 +1596,9 @@ components:
15951596
dateTime:
15961597
type: string
15971598
format: date-time
1599+
duration:
1600+
type: string
1601+
format: duration
15981602
uuid:
15991603
type: string
16001604
format: uuid

modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,7 @@ components:
15201520
- number
15211521
- byte
15221522
- date
1523+
- duration
15231524
- password
15241525
properties:
15251526
integer:
@@ -1563,6 +1564,9 @@ components:
15631564
dateTime:
15641565
type: string
15651566
format: date-time
1567+
duration:
1568+
type: string
1569+
format: duration
15661570
uuid:
15671571
type: string
15681572
format: uuid

modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,7 @@ components:
15981598
- number
15991599
- byte
16001600
- date
1601+
- duration
16011602
- password
16021603
properties:
16031604
integer:
@@ -1644,6 +1645,9 @@ components:
16441645
dateTime:
16451646
type: string
16461647
format: date-time
1648+
duration:
1649+
type: string
1650+
format: duration
16471651
uuid:
16481652
type: string
16491653
format: uuid

modules/openapi-generator/src/test/resources/3_0/snakecase-discriminator.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,7 @@ components:
15251525
- number
15261526
- byte
15271527
- date
1528+
- duration
15281529
- password
15291530
properties:
15301531
integer:
@@ -1571,6 +1572,9 @@ components:
15711572
dateTime:
15721573
type: string
15731574
format: date-time
1575+
duration:
1576+
type: string
1577+
format: duration
15741578
uuid:
15751579
type: string
15761580
format: uuid

0 commit comments

Comments
 (0)