Skip to content

Commit

Permalink
Merge pull request #44 from ejball/datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
ejball committed Aug 11, 2023
2 parents cb61c26 + 841691d commit d2e441f
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup>
<VersionPrefix>2.10.1</VersionPrefix>
<VersionPrefix>2.11.0</VersionPrefix>
<LangVersion>11.0</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
4 changes: 4 additions & 0 deletions ReleaseNotes.md
@@ -1,5 +1,9 @@
# Release Notes

## 2.11.0

* Add support for `datetime`.

## 2.10.1

* Add a package README.
Expand Down
3 changes: 3 additions & 0 deletions example/ExampleApi.fsd
Expand Up @@ -285,6 +285,9 @@ service ExampleApi

/// The price of the widget.
price: decimal;

/// When the widget was created.
created: datetime;
}

/// A widget job.
Expand Down
3 changes: 3 additions & 0 deletions example/ExampleApi.fsd.md
Expand Up @@ -328,6 +328,9 @@ data Widget
/// The price of the widget.
price: decimal;
/// When the widget was created.
created: datetime;
}
```

Expand Down
3 changes: 3 additions & 0 deletions example/output/ExampleApi.fsd
Expand Up @@ -287,6 +287,9 @@ service ExampleApi

/// The price of the widget.
price: decimal;

/// When the widget was created.
created: datetime;
}

/// A widget job.
Expand Down
2 changes: 1 addition & 1 deletion src/Facility.Definition/Http/HttpMethodInfo.cs
Expand Up @@ -251,7 +251,7 @@ private static bool IsValidSimpleField(ServiceFieldInfo fieldInfo, ServiceInfo s
if (fieldTypeKind == ServiceTypeKind.Array)
fieldTypeKind = fieldType!.ValueType!.Kind;

return fieldTypeKind is ServiceTypeKind.String or ServiceTypeKind.Boolean or ServiceTypeKind.Double or ServiceTypeKind.Int32 or ServiceTypeKind.Int64 or ServiceTypeKind.Decimal or ServiceTypeKind.Enum or ServiceTypeKind.ExternalEnum;
return fieldTypeKind is ServiceTypeKind.String or ServiceTypeKind.Boolean or ServiceTypeKind.Double or ServiceTypeKind.Int32 or ServiceTypeKind.Int64 or ServiceTypeKind.Decimal or ServiceTypeKind.Enum or ServiceTypeKind.ExternalEnum or ServiceTypeKind.DateTime;
}

private static bool IsValidRequestBodyField(ServiceFieldInfo fieldInfo, ServiceInfo serviceInfo)
Expand Down
1 change: 1 addition & 0 deletions src/Facility.Definition/ServiceTypeInfo.cs
Expand Up @@ -187,5 +187,6 @@ private ServiceTypeInfo(ServiceTypeKind kind, ServiceDtoInfo? dto = null, Servic
(ServiceTypeKind.Bytes, "bytes"),
(ServiceTypeKind.Object, "object"),
(ServiceTypeKind.Error, "error"),
(ServiceTypeKind.DateTime, "datetime"),
};
}
5 changes: 5 additions & 0 deletions src/Facility.Definition/ServiceTypeKind.cs
Expand Up @@ -89,4 +89,9 @@ public enum ServiceTypeKind
/// An external enumerated type.
/// </summary>
ExternalEnum,

/// <summary>
/// A date and time.
/// </summary>
DateTime,
}
5 changes: 5 additions & 0 deletions tests/Facility.Definition.UnitTests/FieldTests.cs
Expand Up @@ -20,6 +20,7 @@ public void InvalidName()
[TestCase("bytes", ServiceTypeKind.Bytes)]
[TestCase("object", ServiceTypeKind.Object)]
[TestCase("error", ServiceTypeKind.Error)]
[TestCase("datetime", ServiceTypeKind.DateTime)]
public void PrimitiveFields(string name, ServiceTypeKind kind)
{
var service = TestUtility.ParseTestApi("service TestApi { data One { x: xyzzy; } }".Replace("xyzzy", name));
Expand Down Expand Up @@ -191,6 +192,7 @@ public void ResultOfDto()
[TestCase("bytes", ServiceTypeKind.Bytes)]
[TestCase("object", ServiceTypeKind.Object)]
[TestCase("error", ServiceTypeKind.Error)]
[TestCase("datetime", ServiceTypeKind.DateTime)]
[TestCase("Dto", ServiceTypeKind.Dto)]
[TestCase("Enum", ServiceTypeKind.Enum)]
[TestCase("result<Dto>", ServiceTypeKind.Result)]
Expand Down Expand Up @@ -220,6 +222,7 @@ public void ArrayOfAnything(string name, ServiceTypeKind kind)
[TestCase("bytes", ServiceTypeKind.Bytes)]
[TestCase("object", ServiceTypeKind.Object)]
[TestCase("error", ServiceTypeKind.Error)]
[TestCase("datetime", ServiceTypeKind.DateTime)]
[TestCase("Dto", ServiceTypeKind.Dto)]
[TestCase("Enum", ServiceTypeKind.Enum)]
[TestCase("result<Dto>", ServiceTypeKind.Result)]
Expand Down Expand Up @@ -249,6 +252,7 @@ public void MapOfAnything(string name, ServiceTypeKind kind)
[TestCase("bytes", ServiceTypeKind.Bytes)]
[TestCase("object", ServiceTypeKind.Object)]
[TestCase("error", ServiceTypeKind.Error)]
[TestCase("datetime", ServiceTypeKind.DateTime)]
[TestCase("Dto", ServiceTypeKind.Dto)]
[TestCase("Enum", ServiceTypeKind.Enum)]
[TestCase("result<Dto>", ServiceTypeKind.Result)]
Expand Down Expand Up @@ -278,6 +282,7 @@ public void ResultOfAnything(string name, ServiceTypeKind kind)
[TestCase("bytes", ServiceTypeKind.Bytes)]
[TestCase("object", ServiceTypeKind.Object)]
[TestCase("error", ServiceTypeKind.Error)]
[TestCase("datetime", ServiceTypeKind.DateTime)]
[TestCase("Dto", ServiceTypeKind.Dto)]
[TestCase("Enum", ServiceTypeKind.Enum)]
[TestCase("result<Dto>", ServiceTypeKind.Result)]
Expand Down
Expand Up @@ -255,6 +255,7 @@ public void BodyRequestField(string type)
[TestCase("int32")]
[TestCase("int64")]
[TestCase("decimal")]
[TestCase("datetime")]
[TestCase("Enum")]
public void BodyRequestFieldInvalidType(string type)
{
Expand Down Expand Up @@ -369,6 +370,7 @@ public void BodyResponseField(string type)
[TestCase("int32")]
[TestCase("int64")]
[TestCase("decimal")]
[TestCase("datetime")]
[TestCase("Enum")]
[TestCase("nullable<string>")]
[TestCase("nullable<Dto>")]
Expand Down Expand Up @@ -592,13 +594,15 @@ public void ResponseFieldInvalidFrom()
[TestCase("int32")]
[TestCase("int64")]
[TestCase("decimal")]
[TestCase("datetime")]
[TestCase("Enum")]
[TestCase("string[]")]
[TestCase("boolean[]")]
[TestCase("double[]")]
[TestCase("int32[]")]
[TestCase("int64[]")]
[TestCase("decimal[]")]
[TestCase("datetime[]")]
[TestCase("Enum[]")]
public void SimpleFieldTypeSupported(string type)
{
Expand Down
Expand Up @@ -14,6 +14,7 @@ public class ServiceTypeInfoTests
[TestCase("bytes", ServiceTypeKind.Bytes)]
[TestCase("object", ServiceTypeKind.Object)]
[TestCase("error", ServiceTypeKind.Error)]
[TestCase("datetime", ServiceTypeKind.DateTime)]
public void PrimitiveTypes(string name, ServiceTypeKind kind)
{
var service = new ServiceInfo(name: "MyApi", members: new[] { new ServiceDtoInfo("MyDto", fields: new[] { new ServiceFieldInfo("myField", name) }) });
Expand Down
10 changes: 5 additions & 5 deletions tools/Build/Build.cs
Expand Up @@ -41,13 +41,13 @@ void CodeGen(bool verify)
var configuration = dotNetBuildSettings.GetConfiguration();
var verifyOption = verify ? "--verify" : null;
RunCodeGen("example/ExampleApi.fsd", "example/output");
RunCodeGen("example/ExampleApi.fsd.md", "example/output");
RunCodeGen("example/ExampleApi.fsd", "example/output", verifyOption);
RunCodeGen("example/ExampleApi.fsd.md", "example/output", "--verify");
RunCodeGen("example/ExampleApi.fsd", "example/output/ExampleApi-nowidgets.fsd", "--excludeTag", "widgets");
RunCodeGen("example/ExampleApi.fsd.md", "example/output/ExampleApi-nowidgets.fsd", "--excludeTag", "widgets");
RunCodeGen("example/ExampleApi.fsd", "example/output/ExampleApi-nowidgets.fsd", "--excludeTag", "widgets", verifyOption);
RunCodeGen("example/ExampleApi.fsd.md", "example/output/ExampleApi-nowidgets.fsd", "--excludeTag", "widgets", "--verify");
void RunCodeGen(params string?[] args) =>
RunDotNet(new[] { "run", "--no-build", "--project", $"src/{codegen}", "-f", "net6.0", "-c", configuration, "--", "--newline", "lf", verifyOption }.Concat(args));
RunDotNet(new[] { "run", "--no-build", "--project", $"src/{codegen}", "-f", "net6.0", "-c", configuration, "--", "--newline", "lf" }.Concat(args));
}
});

0 comments on commit d2e441f

Please sign in to comment.