@typespec/http-server-csharp 0.58.0-alpha.28 → 0.58.0-alpha.29-dev.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/cli/cli.js +118 -154
- package/dist/src/cli/cli.js.map +1 -1
- package/dist/src/components/controller-action/controller-action.d.ts +16 -0
- package/dist/src/components/controller-action/controller-action.d.ts.map +1 -0
- package/dist/src/components/controller-action/controller-action.js +251 -0
- package/dist/src/components/controller-action/controller-action.js.map +1 -0
- package/dist/src/components/controller-action/controller-action.test.d.ts +2 -0
- package/dist/src/components/controller-action/controller-action.test.d.ts.map +1 -0
- package/dist/src/components/controller-action/controller-action.test.js +106 -0
- package/dist/src/components/controller-action/controller-action.test.js.map +1 -0
- package/dist/src/components/controller-action/parameter-binding.d.ts +17 -0
- package/dist/src/components/controller-action/parameter-binding.d.ts.map +1 -0
- package/dist/src/components/controller-action/parameter-binding.js +77 -0
- package/dist/src/components/controller-action/parameter-binding.js.map +1 -0
- package/dist/src/components/controller-action/response-analysis.d.ts +10 -0
- package/dist/src/components/controller-action/response-analysis.d.ts.map +1 -0
- package/dist/src/components/controller-action/response-analysis.js +61 -0
- package/dist/src/components/controller-action/response-analysis.js.map +1 -0
- package/dist/src/components/controllers/controllers.d.ts +18 -0
- package/dist/src/components/controllers/controllers.d.ts.map +1 -0
- package/dist/src/components/controllers/controllers.js +64 -0
- package/dist/src/components/controllers/controllers.js.map +1 -0
- package/dist/src/components/controllers/controllers.test.d.ts +2 -0
- package/dist/src/components/controllers/controllers.test.d.ts.map +1 -0
- package/dist/src/components/controllers/controllers.test.js +84 -0
- package/dist/src/components/controllers/controllers.test.js.map +1 -0
- package/dist/src/components/csharp-file.d.ts +15 -0
- package/dist/src/components/csharp-file.d.ts.map +1 -0
- package/dist/src/components/csharp-file.js +28 -0
- package/dist/src/components/csharp-file.js.map +1 -0
- package/dist/src/components/enums/enums.d.ts +28 -0
- package/dist/src/components/enums/enums.d.ts.map +1 -0
- package/dist/src/components/enums/enums.js +158 -0
- package/dist/src/components/enums/enums.js.map +1 -0
- package/dist/src/components/enums/enums.test.d.ts +2 -0
- package/dist/src/components/enums/enums.test.d.ts.map +1 -0
- package/dist/src/components/enums/enums.test.js +112 -0
- package/dist/src/components/enums/enums.test.js.map +1 -0
- package/dist/src/components/interfaces/interfaces.d.ts +17 -0
- package/dist/src/components/interfaces/interfaces.d.ts.map +1 -0
- package/dist/src/components/interfaces/interfaces.js +153 -0
- package/dist/src/components/interfaces/interfaces.js.map +1 -0
- package/dist/src/components/interfaces/interfaces.test.d.ts +2 -0
- package/dist/src/components/interfaces/interfaces.test.d.ts.map +1 -0
- package/dist/src/components/interfaces/interfaces.test.js +76 -0
- package/dist/src/components/interfaces/interfaces.test.js.map +1 -0
- package/dist/src/components/models/anonymous-models.d.ts +9 -0
- package/dist/src/components/models/anonymous-models.d.ts.map +1 -0
- package/dist/src/components/models/anonymous-models.js +37 -0
- package/dist/src/components/models/anonymous-models.js.map +1 -0
- package/dist/src/components/models/error-models.d.ts +5 -0
- package/dist/src/components/models/error-models.d.ts.map +1 -0
- package/dist/src/components/models/error-models.js +84 -0
- package/dist/src/components/models/error-models.js.map +1 -0
- package/dist/src/components/models/model-helpers.d.ts +40 -0
- package/dist/src/components/models/model-helpers.d.ts.map +1 -0
- package/dist/src/components/models/model-helpers.js +239 -0
- package/dist/src/components/models/model-helpers.js.map +1 -0
- package/dist/src/components/models/models.d.ts +15 -0
- package/dist/src/components/models/models.d.ts.map +1 -0
- package/dist/src/components/models/models.js +234 -0
- package/dist/src/components/models/models.js.map +1 -0
- package/dist/src/components/models/models.test.d.ts +2 -0
- package/dist/src/components/models/models.test.d.ts.map +1 -0
- package/dist/src/components/models/models.test.js +151 -0
- package/dist/src/components/models/models.test.js.map +1 -0
- package/dist/src/components/project/csproj.d.ts +12 -0
- package/dist/src/components/project/csproj.d.ts.map +1 -0
- package/dist/src/components/project/csproj.js +35 -0
- package/dist/src/components/project/csproj.js.map +1 -0
- package/dist/src/components/project/csproj.test.d.ts +2 -0
- package/dist/src/components/project/csproj.test.d.ts.map +1 -0
- package/dist/src/components/project/csproj.test.js +42 -0
- package/dist/src/components/project/csproj.test.js.map +1 -0
- package/dist/src/components/project/launch-settings.d.ts +16 -0
- package/dist/src/components/project/launch-settings.d.ts.map +1 -0
- package/dist/src/components/project/launch-settings.js +73 -0
- package/dist/src/components/project/launch-settings.js.map +1 -0
- package/dist/src/components/project/launch-settings.test.d.ts +2 -0
- package/dist/src/components/project/launch-settings.test.d.ts.map +1 -0
- package/dist/src/components/project/launch-settings.test.js +48 -0
- package/dist/src/components/project/launch-settings.test.js.map +1 -0
- package/dist/src/components/project/program.d.ts +14 -0
- package/dist/src/components/project/program.d.ts.map +1 -0
- package/dist/src/components/project/program.js +75 -0
- package/dist/src/components/project/program.js.map +1 -0
- package/dist/src/components/project/program.test.d.ts +2 -0
- package/dist/src/components/project/program.test.d.ts.map +1 -0
- package/dist/src/components/project/program.test.js +50 -0
- package/dist/src/components/project/program.test.js.map +1 -0
- package/dist/src/components/render-root.d.ts +14 -0
- package/dist/src/components/render-root.d.ts.map +1 -0
- package/dist/src/components/render-root.js +122 -0
- package/dist/src/components/render-root.js.map +1 -0
- package/dist/src/components/request-models.d.ts +15 -0
- package/dist/src/components/request-models.d.ts.map +1 -0
- package/dist/src/components/request-models.js +97 -0
- package/dist/src/components/request-models.js.map +1 -0
- package/dist/src/components/scaffolding/documentation.d.ts +12 -0
- package/dist/src/components/scaffolding/documentation.d.ts.map +1 -0
- package/dist/src/{lib/doc.js → components/scaffolding/documentation.js} +56 -46
- package/dist/src/components/scaffolding/documentation.js.map +1 -0
- package/dist/src/components/scaffolding/mock-helpers.d.ts +10 -0
- package/dist/src/components/scaffolding/mock-helpers.d.ts.map +1 -0
- package/dist/src/components/scaffolding/mock-helpers.js +268 -0
- package/dist/src/components/scaffolding/mock-helpers.js.map +1 -0
- package/dist/src/components/scaffolding/mock-implementations.d.ts +14 -0
- package/dist/src/components/scaffolding/mock-implementations.d.ts.map +1 -0
- package/dist/src/components/scaffolding/mock-implementations.js +152 -0
- package/dist/src/components/scaffolding/mock-implementations.js.map +1 -0
- package/dist/src/components/scaffolding/mock-return-utils.d.ts +11 -0
- package/dist/src/components/scaffolding/mock-return-utils.d.ts.map +1 -0
- package/dist/src/components/scaffolding/mock-return-utils.js +62 -0
- package/dist/src/components/scaffolding/mock-return-utils.js.map +1 -0
- package/dist/src/components/scaffolding/mock-scaffolding.d.ts +6 -0
- package/dist/src/components/scaffolding/mock-scaffolding.d.ts.map +1 -0
- package/dist/src/components/scaffolding/mock-scaffolding.js +5 -0
- package/dist/src/components/scaffolding/mock-scaffolding.js.map +1 -0
- package/dist/src/components/scaffolding/mock-scaffolding.test.d.ts +2 -0
- package/dist/src/components/scaffolding/mock-scaffolding.test.d.ts.map +1 -0
- package/dist/src/components/scaffolding/mock-scaffolding.test.js +59 -0
- package/dist/src/components/scaffolding/mock-scaffolding.test.js.map +1 -0
- package/dist/src/components/serialization/base64-url-json-converter.d.ts +7 -0
- package/dist/src/components/serialization/base64-url-json-converter.d.ts.map +1 -0
- package/dist/src/components/serialization/base64-url-json-converter.js +58 -0
- package/dist/src/components/serialization/base64-url-json-converter.js.map +1 -0
- package/dist/src/components/serialization/constraint-attributes.d.ts +7 -0
- package/dist/src/components/serialization/constraint-attributes.d.ts.map +1 -0
- package/dist/src/components/serialization/constraint-attributes.js +556 -0
- package/dist/src/components/serialization/constraint-attributes.js.map +1 -0
- package/dist/src/components/serialization/http-service-exception-filter.d.ts +8 -0
- package/dist/src/components/serialization/http-service-exception-filter.d.ts.map +1 -0
- package/dist/src/components/serialization/http-service-exception-filter.js +71 -0
- package/dist/src/components/serialization/http-service-exception-filter.js.map +1 -0
- package/dist/src/components/serialization/json-converters.d.ts +7 -0
- package/dist/src/components/serialization/json-converters.d.ts.map +1 -0
- package/dist/src/components/serialization/json-converters.js +22 -0
- package/dist/src/components/serialization/json-converters.js.map +1 -0
- package/dist/src/components/serialization/json-converters.test.d.ts +2 -0
- package/dist/src/components/serialization/json-converters.test.d.ts.map +1 -0
- package/dist/src/components/serialization/json-converters.test.js +136 -0
- package/dist/src/components/serialization/json-converters.test.js.map +1 -0
- package/dist/src/components/serialization/json-serialization-provider.d.ts +7 -0
- package/dist/src/components/serialization/json-serialization-provider.d.ts.map +1 -0
- package/dist/src/components/serialization/json-serialization-provider.js +90 -0
- package/dist/src/components/serialization/json-serialization-provider.js.map +1 -0
- package/dist/src/components/serialization/time-span-duration-converter.d.ts +7 -0
- package/dist/src/components/serialization/time-span-duration-converter.d.ts.map +1 -0
- package/dist/src/components/serialization/time-span-duration-converter.js +44 -0
- package/dist/src/components/serialization/time-span-duration-converter.js.map +1 -0
- package/dist/src/components/serialization/unix-epoch-date-time-converter.d.ts +7 -0
- package/dist/src/components/serialization/unix-epoch-date-time-converter.d.ts.map +1 -0
- package/dist/src/components/serialization/unix-epoch-date-time-converter.js +71 -0
- package/dist/src/components/serialization/unix-epoch-date-time-converter.js.map +1 -0
- package/dist/src/components/type-expression/type-expression.d.ts +24 -0
- package/dist/src/components/type-expression/type-expression.d.ts.map +1 -0
- package/dist/src/components/type-expression/type-expression.js +223 -0
- package/dist/src/components/type-expression/type-expression.js.map +1 -0
- package/dist/src/components/type-expression/type-expression.test.d.ts +2 -0
- package/dist/src/components/type-expression/type-expression.test.d.ts.map +1 -0
- package/dist/src/components/type-expression/type-expression.test.js +207 -0
- package/dist/src/components/type-expression/type-expression.test.js.map +1 -0
- package/dist/src/context/emitter-options-context.d.ts +13 -0
- package/dist/src/context/emitter-options-context.d.ts.map +1 -0
- package/dist/src/context/emitter-options-context.js +15 -0
- package/dist/src/context/emitter-options-context.js.map +1 -0
- package/dist/src/diagnostics.d.ts +8 -0
- package/dist/src/diagnostics.d.ts.map +1 -0
- package/dist/src/diagnostics.js +164 -0
- package/dist/src/diagnostics.js.map +1 -0
- package/dist/src/emitter.d.ts +8 -0
- package/dist/src/emitter.d.ts.map +1 -0
- package/dist/src/emitter.js +180 -0
- package/dist/src/emitter.js.map +1 -0
- package/dist/src/{lib/index.d.ts → index.d.ts} +1 -1
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/{lib/index.js → index.js} +1 -1
- package/dist/src/index.js.map +1 -0
- package/dist/src/{lib/lib.d.ts → lib.d.ts} +4 -14
- package/dist/src/lib.d.ts.map +1 -0
- package/dist/src/lib.js +133 -0
- package/dist/src/lib.js.map +1 -0
- package/dist/src/output-writer.d.ts +11 -0
- package/dist/src/output-writer.d.ts.map +1 -0
- package/dist/src/output-writer.js +72 -0
- package/dist/src/output-writer.js.map +1 -0
- package/dist/src/service-discovery.d.ts +13 -0
- package/dist/src/service-discovery.d.ts.map +1 -0
- package/dist/src/service-discovery.js +93 -0
- package/dist/src/service-discovery.js.map +1 -0
- package/dist/src/service-resolution.d.ts +34 -0
- package/dist/src/service-resolution.d.ts.map +1 -0
- package/dist/src/service-resolution.js +244 -0
- package/dist/src/service-resolution.js.map +1 -0
- package/dist/src/testing/index.d.ts +2 -0
- package/dist/src/testing/index.d.ts.map +1 -0
- package/dist/src/testing/index.js +2 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/utils/attributes.d.ts +8 -0
- package/dist/src/utils/attributes.d.ts.map +1 -0
- package/dist/src/utils/attributes.js +224 -0
- package/dist/src/utils/attributes.js.map +1 -0
- package/dist/src/utils/csharp-libs.d.ts +87 -0
- package/dist/src/utils/csharp-libs.d.ts.map +1 -0
- package/dist/src/utils/csharp-libs.js +90 -0
- package/dist/src/utils/csharp-libs.js.map +1 -0
- package/dist/src/utils/doc-comments.d.ts +2 -0
- package/dist/src/utils/doc-comments.d.ts.map +1 -0
- package/dist/src/utils/doc-comments.js +4 -0
- package/dist/src/utils/doc-comments.js.map +1 -0
- package/dist/src/utils/http-helpers.d.ts +19 -0
- package/dist/src/utils/http-helpers.d.ts.map +1 -0
- package/dist/src/utils/http-helpers.js +70 -0
- package/dist/src/utils/http-helpers.js.map +1 -0
- package/dist/src/utils/http-helpers.test.d.ts +2 -0
- package/dist/src/utils/http-helpers.test.d.ts.map +1 -0
- package/dist/src/utils/http-helpers.test.js +68 -0
- package/dist/src/utils/http-helpers.test.js.map +1 -0
- package/dist/src/utils/namespace-utils.d.ts +13 -0
- package/dist/src/utils/namespace-utils.d.ts.map +1 -0
- package/dist/src/utils/namespace-utils.js +55 -0
- package/dist/src/utils/namespace-utils.js.map +1 -0
- package/dist/src/utils/naming.d.ts +31 -0
- package/dist/src/utils/naming.d.ts.map +1 -0
- package/dist/src/utils/naming.js +87 -0
- package/dist/src/utils/naming.js.map +1 -0
- package/dist/src/utils/naming.test.d.ts +2 -0
- package/dist/src/utils/naming.test.d.ts.map +1 -0
- package/dist/src/utils/naming.test.js +86 -0
- package/dist/src/utils/naming.test.js.map +1 -0
- package/dist/src/utils/port.d.ts +5 -0
- package/dist/src/utils/port.d.ts.map +1 -0
- package/dist/src/utils/port.js +33 -0
- package/dist/src/utils/port.js.map +1 -0
- package/dist/src/utils/return-type-helpers.d.ts +8 -0
- package/dist/src/utils/return-type-helpers.d.ts.map +1 -0
- package/dist/src/utils/return-type-helpers.js +59 -0
- package/dist/src/utils/return-type-helpers.js.map +1 -0
- package/package.json +36 -28
- package/dist/src/lib/attributes.d.ts +0 -43
- package/dist/src/lib/attributes.d.ts.map +0 -1
- package/dist/src/lib/attributes.js +0 -422
- package/dist/src/lib/attributes.js.map +0 -1
- package/dist/src/lib/boilerplate.d.ts +0 -6
- package/dist/src/lib/boilerplate.d.ts.map +0 -1
- package/dist/src/lib/boilerplate.js +0 -792
- package/dist/src/lib/boilerplate.js.map +0 -1
- package/dist/src/lib/doc.d.ts +0 -5
- package/dist/src/lib/doc.d.ts.map +0 -1
- package/dist/src/lib/doc.js.map +0 -1
- package/dist/src/lib/index.d.ts.map +0 -1
- package/dist/src/lib/index.js.map +0 -1
- package/dist/src/lib/interfaces.d.ts +0 -183
- package/dist/src/lib/interfaces.d.ts.map +0 -1
- package/dist/src/lib/interfaces.js +0 -287
- package/dist/src/lib/interfaces.js.map +0 -1
- package/dist/src/lib/lib.d.ts.map +0 -1
- package/dist/src/lib/lib.js +0 -146
- package/dist/src/lib/lib.js.map +0 -1
- package/dist/src/lib/project.d.ts +0 -5
- package/dist/src/lib/project.d.ts.map +0 -1
- package/dist/src/lib/project.js +0 -101
- package/dist/src/lib/project.js.map +0 -1
- package/dist/src/lib/scaffolding.d.ts +0 -22
- package/dist/src/lib/scaffolding.d.ts.map +0 -1
- package/dist/src/lib/scaffolding.js +0 -461
- package/dist/src/lib/scaffolding.js.map +0 -1
- package/dist/src/lib/service.d.ts +0 -4
- package/dist/src/lib/service.d.ts.map +0 -1
- package/dist/src/lib/service.js +0 -1208
- package/dist/src/lib/service.js.map +0 -1
- package/dist/src/lib/type-helpers.d.ts +0 -44
- package/dist/src/lib/type-helpers.d.ts.map +0 -1
- package/dist/src/lib/type-helpers.js +0 -106
- package/dist/src/lib/type-helpers.js.map +0 -1
- package/dist/src/lib/utils.d.ts +0 -120
- package/dist/src/lib/utils.d.ts.map +0 -1
- package/dist/src/lib/utils.js +0 -1580
- package/dist/src/lib/utils.js.map +0 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { code } from "@alloy-js/core";
|
|
3
|
+
import { Namespace } from "@alloy-js/csharp";
|
|
4
|
+
import { CSharpFile } from "../csharp-file.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Renders the Base64UrlJsonConverter.
|
|
8
|
+
* Converts between base64url-encoded strings and byte arrays.
|
|
9
|
+
*/
|
|
10
|
+
export function Base64UrlJsonConverter() {
|
|
11
|
+
return _$createComponent(CSharpFile, {
|
|
12
|
+
path: "Base64UrlJsonConverter.cs",
|
|
13
|
+
using: ["System.Text.Json", "System.Text.Json.Serialization"],
|
|
14
|
+
get children() {
|
|
15
|
+
return _$createComponent(Namespace, {
|
|
16
|
+
name: "TypeSpec.Helpers.JsonConverters",
|
|
17
|
+
children: code`
|
|
18
|
+
/// <summary>
|
|
19
|
+
/// System.Text.Json converter for the properties using Base64Url encoding
|
|
20
|
+
/// </summary>
|
|
21
|
+
public class Base64UrlJsonConverter : JsonConverter<byte[]>
|
|
22
|
+
{
|
|
23
|
+
/// <summary>
|
|
24
|
+
/// Adds padding to the input
|
|
25
|
+
/// </summary>
|
|
26
|
+
/// <param name="input"> the input string </param>
|
|
27
|
+
/// <returns> the padded string </returns>
|
|
28
|
+
private static string Pad(string input)
|
|
29
|
+
{
|
|
30
|
+
var count = 3 - ((input.Length + 3) % 4);
|
|
31
|
+
if (count == 0)
|
|
32
|
+
{
|
|
33
|
+
return input;
|
|
34
|
+
}
|
|
35
|
+
return $"{input}{new string('=', count)}";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public override byte[]? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
39
|
+
{
|
|
40
|
+
if (typeToConvert != typeof(byte[]))
|
|
41
|
+
throw new ArgumentException($"Cannot apply converter {this.GetType().FullName} to type {typeToConvert.FullName}");
|
|
42
|
+
var value = reader.GetString();
|
|
43
|
+
if (string.IsNullOrWhiteSpace(value))
|
|
44
|
+
return null;
|
|
45
|
+
return Convert.FromBase64String(Pad(value.Replace('-', '+').Replace('_', '/')));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public override void Write(Utf8JsonWriter writer, byte[] value, JsonSerializerOptions options)
|
|
49
|
+
{
|
|
50
|
+
writer.WriteStringValue(Convert.ToBase64String(value).TrimEnd('=').Replace('+', '-').Replace('/', '_'));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
`
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=base64-url-json-converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["code","Namespace","CSharpFile","Base64UrlJsonConverter","_$createComponent","path","using","children","name"],"sources":["../../../../src/components/serialization/base64-url-json-converter.tsx"],"sourcesContent":[null],"mappings":";AAAA,SAASA,IAAI,QAAuB,gBAAgB;AACpD,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,UAAU;;AAEnB;AACA;AACA;AACA;AACA,OAAO,SAASC,sBAAsBA,CAAA,EAAa;EACjD,OAAAC,iBAAA,CACGF,UAAU;IACTG,IAAI;IACJC,KAAK,EAAE,CAAC,kBAAkB,EAAE,gCAAgC,CAAC;IAAA,IAAAC,SAAA;MAAA,OAAAH,iBAAA,CAE5DH,SAAS;QAACO,IAAI;QAAAD,QAAA,EACZP,IAAI;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MAAS;IAAA;EAAA;AAIT","ignoreList":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Children } from "@alloy-js/core";
|
|
2
|
+
/**
|
|
3
|
+
* Renders all constraint attribute helper files.
|
|
4
|
+
* These provide validation at serialization time for numeric, string, and array constraints.
|
|
5
|
+
*/
|
|
6
|
+
export declare function ConstraintAttributes(): Children;
|
|
7
|
+
//# sourceMappingURL=constraint-attributes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constraint-attributes.d.ts","sourceRoot":"","sources":["../../../../src/components/serialization/constraint-attributes.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAIrD;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,QAAQ,CAU/C"}
|
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { code } from "@alloy-js/core";
|
|
3
|
+
import { Namespace } from "@alloy-js/csharp";
|
|
4
|
+
import { CSharpFile } from "../csharp-file.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Renders all constraint attribute helper files.
|
|
8
|
+
* These provide validation at serialization time for numeric, string, and array constraints.
|
|
9
|
+
*/
|
|
10
|
+
export function ConstraintAttributes() {
|
|
11
|
+
return [_$createComponent(NumericConstraintAttribute, {}), _$createComponent(StringConstraintAttribute, {}), _$createComponent(ArrayConstraintAttribute, {}), _$createComponent(StringArrayConstraintAttribute, {}), _$createComponent(NumericArrayConstraintAttribute, {})];
|
|
12
|
+
}
|
|
13
|
+
function NumericConstraintAttribute() {
|
|
14
|
+
return _$createComponent(CSharpFile, {
|
|
15
|
+
path: "NumericConstraintAttribute.cs",
|
|
16
|
+
using: ["System.Numerics", "System.Text.Json", "System.Text.Json.Serialization"],
|
|
17
|
+
get children() {
|
|
18
|
+
return _$createComponent(Namespace, {
|
|
19
|
+
name: "TypeSpec.Helpers.JsonConverters",
|
|
20
|
+
children: code`
|
|
21
|
+
/// <summary>
|
|
22
|
+
/// Provides numeric constraint validation at serialization time
|
|
23
|
+
/// </summary>
|
|
24
|
+
/// <typeparam name="T"></typeparam>
|
|
25
|
+
public class NumericConstraintAttribute<T> : JsonConverterAttribute where T: struct, INumber<T>
|
|
26
|
+
{
|
|
27
|
+
T? _minValue = null, _maxValue = null;
|
|
28
|
+
|
|
29
|
+
public NumericConstraintAttribute() { }
|
|
30
|
+
|
|
31
|
+
/// <summary>
|
|
32
|
+
/// Provides the minimum value
|
|
33
|
+
/// </summary>
|
|
34
|
+
public T MinValue
|
|
35
|
+
{
|
|
36
|
+
get { return _minValue.HasValue ? _minValue.Value : default(T); }
|
|
37
|
+
set { _minValue = value; }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/// <summary>
|
|
41
|
+
/// Provides the maximum allowed value
|
|
42
|
+
/// </summary>
|
|
43
|
+
public T MaxValue
|
|
44
|
+
{
|
|
45
|
+
get { return _maxValue.HasValue ? _maxValue.Value : default(T); }
|
|
46
|
+
set { _maxValue = value; }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/// <summary>
|
|
50
|
+
/// If true, then values greater than but not equal to the minimum value are allowed
|
|
51
|
+
/// </summary>
|
|
52
|
+
public bool MinValueExclusive { get; set; }
|
|
53
|
+
|
|
54
|
+
/// <summary>
|
|
55
|
+
/// If true, values less than, but not equal to the provided maximum are allowed
|
|
56
|
+
/// </summary>
|
|
57
|
+
public bool MaxValueExclusive { get; set; }
|
|
58
|
+
|
|
59
|
+
public override JsonConverter? CreateConverter(Type typeToConvert)
|
|
60
|
+
{
|
|
61
|
+
return new NumericJsonConverter<T>(_minValue, _maxValue, MinValueExclusive, MaxValueExclusive);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public class NumericJsonConverter<T> : JsonConverter<T> where T : struct, INumber<T>
|
|
66
|
+
{
|
|
67
|
+
string _rangeString;
|
|
68
|
+
|
|
69
|
+
public NumericJsonConverter(T? minValue = null, T? maxValue = null, bool? minValueExclusive = false, bool? maxValueExclusive = false, JsonSerializerOptions? options = null)
|
|
70
|
+
{
|
|
71
|
+
MinValue = minValue;
|
|
72
|
+
MaxValue = maxValue;
|
|
73
|
+
MinValueExclusive = minValueExclusive.HasValue ? minValueExclusive.Value : false;
|
|
74
|
+
MaxValueExclusive = maxValueExclusive.HasValue ? maxValueExclusive.Value : false;
|
|
75
|
+
_rangeString = $"{(MinValue.HasValue ? (MinValueExclusive ? $"({MinValue}" : $"[{MinValue}") : $"[{typeof(T).Name}.Min")}, {(MaxValue.HasValue ? (MaxValueExclusive ? $"{MaxValue})" : $"{MaxValue}]") : $"{typeof(T).Name}.Max]")}";
|
|
76
|
+
if (options != null)
|
|
77
|
+
{
|
|
78
|
+
InnerConverter = options.GetConverter(typeof(T)) as JsonConverter<T>;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
protected T? MinValue { get; }
|
|
83
|
+
protected bool MinValueExclusive { get; }
|
|
84
|
+
protected T? MaxValue { get; }
|
|
85
|
+
|
|
86
|
+
protected bool MaxValueExclusive { get; }
|
|
87
|
+
|
|
88
|
+
private JsonConverter<T>? InnerConverter { get; set; }
|
|
89
|
+
|
|
90
|
+
private JsonConverter<T> GetInnerConverter(JsonSerializerOptions options)
|
|
91
|
+
{
|
|
92
|
+
if (InnerConverter == null)
|
|
93
|
+
{
|
|
94
|
+
InnerConverter = (JsonConverter<T>)options.GetConverter(typeof(T));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return InnerConverter;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
101
|
+
{
|
|
102
|
+
var inner = GetInnerConverter(options);
|
|
103
|
+
T candidate = inner.Read(ref reader, typeToConvert, options);
|
|
104
|
+
ValidateRange(candidate);
|
|
105
|
+
return candidate;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
|
|
109
|
+
{
|
|
110
|
+
ValidateRange(value);
|
|
111
|
+
GetInnerConverter(options).Write(writer, value, options);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
protected virtual void ValidateRange(T value)
|
|
115
|
+
{
|
|
116
|
+
if ((MinValue.HasValue && (value < MinValue.Value || (value == MinValue.Value && MinValueExclusive)))
|
|
117
|
+
|| (MaxValue.HasValue && (value > MaxValue.Value || (value == MaxValue.Value && MaxValueExclusive))))
|
|
118
|
+
throw new JsonException($"{value} is outside the allowed range of {_rangeString}");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
`
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function StringConstraintAttribute() {
|
|
127
|
+
return _$createComponent(CSharpFile, {
|
|
128
|
+
path: "StringConstraintAttribute.cs",
|
|
129
|
+
using: ["System.Text.Json", "System.Text.Json.Serialization"],
|
|
130
|
+
get children() {
|
|
131
|
+
return _$createComponent(Namespace, {
|
|
132
|
+
name: "TypeSpec.Helpers.JsonConverters",
|
|
133
|
+
children: code`
|
|
134
|
+
/// <summary>
|
|
135
|
+
/// Provides constraints for a string values property
|
|
136
|
+
/// </summary>
|
|
137
|
+
public class StringConstraint : JsonConverterAttribute
|
|
138
|
+
{
|
|
139
|
+
int? _minLength = null, _maxLength = null;
|
|
140
|
+
|
|
141
|
+
public StringConstraint() { }
|
|
142
|
+
|
|
143
|
+
/// <summary>
|
|
144
|
+
/// The minimum length of the string
|
|
145
|
+
/// </summary>
|
|
146
|
+
public int MinLength
|
|
147
|
+
{
|
|
148
|
+
get { return _minLength.HasValue ? _minLength.Value : 0; }
|
|
149
|
+
set { _minLength = value; }
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/// <summary>
|
|
153
|
+
/// The maximum length of the string
|
|
154
|
+
/// </summary>
|
|
155
|
+
public int MaxLength
|
|
156
|
+
{
|
|
157
|
+
get { return _maxLength.HasValue ? _maxLength.Value : 0; }
|
|
158
|
+
set { _maxLength = value; }
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/// <summary>
|
|
162
|
+
/// The pattern that the string must match
|
|
163
|
+
/// </summary>
|
|
164
|
+
public string? Pattern { get; set; }
|
|
165
|
+
|
|
166
|
+
public override JsonConverter? CreateConverter(Type typeToConvert)
|
|
167
|
+
{
|
|
168
|
+
return new StringJsonConverter(_minLength, _maxLength, Pattern);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
public class StringJsonConverter : JsonConverter<string>
|
|
173
|
+
{
|
|
174
|
+
public StringJsonConverter(int? minLength, int? maxLength, string? pattern, JsonSerializerOptions? options = null)
|
|
175
|
+
{
|
|
176
|
+
MinLength = minLength;
|
|
177
|
+
MaxLength = maxLength;
|
|
178
|
+
Pattern = pattern;
|
|
179
|
+
if (options != null)
|
|
180
|
+
{
|
|
181
|
+
InnerConverter = options.GetConverter(typeof(string)) as JsonConverter<string>;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
protected int? MinLength { get; }
|
|
186
|
+
protected int? MaxLength { get; }
|
|
187
|
+
protected string? Pattern { get; }
|
|
188
|
+
|
|
189
|
+
private JsonConverter<string>? InnerConverter { get; set; }
|
|
190
|
+
|
|
191
|
+
private JsonConverter<string> GetInnerConverter(JsonSerializerOptions options)
|
|
192
|
+
{
|
|
193
|
+
if (InnerConverter == null)
|
|
194
|
+
{
|
|
195
|
+
InnerConverter = (JsonConverter<string>)options.GetConverter(typeof(string));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return InnerConverter;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
public override bool CanConvert(Type typeToConvert)
|
|
202
|
+
{
|
|
203
|
+
return base.CanConvert(typeToConvert);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
public override string? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
207
|
+
{
|
|
208
|
+
var innerConverter = GetInnerConverter(options);
|
|
209
|
+
string? candidate = innerConverter.Read(ref reader, typeToConvert, options);
|
|
210
|
+
if (MinLength.HasValue && (candidate == null || candidate.Length < MinLength.Value))
|
|
211
|
+
{
|
|
212
|
+
throw new JsonException($"String length less than minimum length {MinLength.Value}");
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (candidate != null)
|
|
216
|
+
{
|
|
217
|
+
if (MaxLength.HasValue && candidate.Length > MaxLength.Value)
|
|
218
|
+
{
|
|
219
|
+
throw new JsonException($"String length greater than maximum length {MaxLength.Value}");
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (Pattern != null && !System.Text.RegularExpressions.Regex.IsMatch(candidate, Pattern))
|
|
223
|
+
{
|
|
224
|
+
throw new JsonException($"String does not match pattern {Pattern}");
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return candidate;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
|
|
232
|
+
{
|
|
233
|
+
if (MinLength.HasValue && (value == null || value.Length < MinLength.Value))
|
|
234
|
+
{
|
|
235
|
+
throw new JsonException($"String length less than minimum length {MinLength.Value}");
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (value != null)
|
|
239
|
+
{
|
|
240
|
+
if (MaxLength.HasValue && value.Length > MaxLength.Value)
|
|
241
|
+
{
|
|
242
|
+
throw new JsonException($"String length greater than maximum length {MaxLength.Value}");
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (Pattern != null && !System.Text.RegularExpressions.Regex.IsMatch(value, Pattern))
|
|
246
|
+
{
|
|
247
|
+
throw new JsonException($"String does not match pattern {Pattern}");
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
GetInnerConverter(options).Write(writer, value, options);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
`
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
function ArrayConstraintAttribute() {
|
|
260
|
+
return _$createComponent(CSharpFile, {
|
|
261
|
+
path: "ArrayConstraintAttribute.cs",
|
|
262
|
+
using: ["System.Text.Json", "System.Text.Json.Serialization"],
|
|
263
|
+
get children() {
|
|
264
|
+
return _$createComponent(Namespace, {
|
|
265
|
+
name: "TypeSpec.Helpers.JsonConverters",
|
|
266
|
+
children: code`
|
|
267
|
+
/// <summary>
|
|
268
|
+
/// Constrains the number of elements in an array
|
|
269
|
+
/// </summary>
|
|
270
|
+
/// <typeparam name="T">The element type of the array</typeparam>
|
|
271
|
+
public class ArrayConstraintAttribute<T> : JsonConverterAttribute
|
|
272
|
+
{
|
|
273
|
+
int? _minItems = null, _maxItems = null;
|
|
274
|
+
|
|
275
|
+
/// <summary>
|
|
276
|
+
/// The smallest number of allowed items
|
|
277
|
+
/// </summary>
|
|
278
|
+
public int MinItems
|
|
279
|
+
{
|
|
280
|
+
get { return _minItems.HasValue ? _minItems.Value : 0; }
|
|
281
|
+
set { _minItems = value; }
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/// <summary>
|
|
285
|
+
/// The largest number of allowed items
|
|
286
|
+
/// </summary>
|
|
287
|
+
public int MaxItems
|
|
288
|
+
{
|
|
289
|
+
get { return _maxItems.HasValue ? _maxItems.Value : 0; }
|
|
290
|
+
set { _maxItems = value; }
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
public ArrayConstraintAttribute() { }
|
|
294
|
+
|
|
295
|
+
public override JsonConverter? CreateConverter(Type typeToConvert)
|
|
296
|
+
{
|
|
297
|
+
if (typeof(ISet<T>).IsAssignableFrom(typeToConvert))
|
|
298
|
+
{
|
|
299
|
+
return new ConstrainedSetConverter<T>(_minItems, _maxItems);
|
|
300
|
+
}
|
|
301
|
+
else if (typeToConvert.IsArray && typeToConvert.GetElementType() == typeof(T))
|
|
302
|
+
{
|
|
303
|
+
return new ConstrainedStandardArrayConverter<T>(_minItems, _maxItems);
|
|
304
|
+
}
|
|
305
|
+
else
|
|
306
|
+
{
|
|
307
|
+
return new ConstrainedEnumerableConverter<T>(_minItems, _maxItems);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
public abstract class ConstrainedCollectionConverter<T, TCollection> : JsonConverter<TCollection>
|
|
313
|
+
{
|
|
314
|
+
protected ConstrainedCollectionConverter(int? min, int? max)
|
|
315
|
+
{
|
|
316
|
+
_minItems = min;
|
|
317
|
+
_maxItems = max;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
protected int? _minItems, _maxItems;
|
|
321
|
+
public JsonConverter<T>? InnerConverter { get; set; }
|
|
322
|
+
|
|
323
|
+
public virtual Func<ConstrainedCollectionConverter<T, TCollection>, JsonSerializerOptions, JsonConverter<T>> InnerConverterFactory { get; set; } =
|
|
324
|
+
ConverterHelpers.GetStandardInnerConverter<T, TCollection>;
|
|
325
|
+
|
|
326
|
+
protected bool ValidateMin(int count)
|
|
327
|
+
{
|
|
328
|
+
return !_minItems.HasValue || count >= _minItems.Value;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
protected bool ValidateMax(int count)
|
|
332
|
+
{
|
|
333
|
+
return !_maxItems.HasValue || count <= _maxItems.Value;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
protected void ValidateRange(int count)
|
|
337
|
+
{
|
|
338
|
+
if (!ValidateMax(count) || !ValidateMin(count))
|
|
339
|
+
{
|
|
340
|
+
throw new JsonException($"Number of array elements not in range [{(_minItems.HasValue ? _minItems.Value : 0)}, {(_maxItems.HasValue ? _maxItems.Value : Array.MaxLength)}]");
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
public override TCollection? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
345
|
+
{
|
|
346
|
+
var _innerConverter = InnerConverterFactory(this, options);
|
|
347
|
+
if (reader.TokenType != JsonTokenType.StartArray)
|
|
348
|
+
{
|
|
349
|
+
throw new JsonException("Expected start of array");
|
|
350
|
+
}
|
|
351
|
+
var list = new List<T>();
|
|
352
|
+
int count = 0;
|
|
353
|
+
while (reader.Read())
|
|
354
|
+
{
|
|
355
|
+
if (reader.TokenType == JsonTokenType.EndArray)
|
|
356
|
+
{
|
|
357
|
+
ValidateRange(count);
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
if (!ValidateMax(count))
|
|
361
|
+
{
|
|
362
|
+
ValidateRange(count);
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
T value = _innerConverter.Read(ref reader, typeof(T), options)!;
|
|
366
|
+
list.Add(value);
|
|
367
|
+
count++;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
return ConvertToCollection(list);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
public override void Write(Utf8JsonWriter writer, TCollection value, JsonSerializerOptions options)
|
|
374
|
+
{
|
|
375
|
+
var _innerConverter = InnerConverterFactory(this, options);
|
|
376
|
+
writer.WriteStartArray();
|
|
377
|
+
foreach (var item in GetEnumerable(value))
|
|
378
|
+
_innerConverter.Write(writer, item, options);
|
|
379
|
+
writer.WriteEndArray();
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
protected abstract TCollection ConvertToCollection(List<T> list);
|
|
383
|
+
protected abstract IEnumerable<T> GetEnumerable(TCollection collection);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
public class ConstrainedEnumerableConverter<T> : ConstrainedCollectionConverter<T, IEnumerable<T>>
|
|
387
|
+
{
|
|
388
|
+
public ConstrainedEnumerableConverter(int? min, int? max) : base(min, max) { }
|
|
389
|
+
|
|
390
|
+
protected override IEnumerable<T> ConvertToCollection(List<T> list) => list;
|
|
391
|
+
|
|
392
|
+
protected override IEnumerable<T> GetEnumerable(IEnumerable<T> collection) => collection;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
public class ConstrainedSetConverter<T> : ConstrainedCollectionConverter<T, ISet<T>>
|
|
396
|
+
{
|
|
397
|
+
public ConstrainedSetConverter(int? min, int? max) : base(min, max) { }
|
|
398
|
+
|
|
399
|
+
protected override ISet<T> ConvertToCollection(List<T> list) => new HashSet<T>(list);
|
|
400
|
+
|
|
401
|
+
protected override IEnumerable<T> GetEnumerable(ISet<T> collection) => collection;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
public class ConstrainedStandardArrayConverter<T> : ConstrainedCollectionConverter<T, T[]>
|
|
405
|
+
{
|
|
406
|
+
public ConstrainedStandardArrayConverter(int? min, int? max) : base(min, max) { }
|
|
407
|
+
|
|
408
|
+
protected override T[] ConvertToCollection(List<T> list) => list.ToArray();
|
|
409
|
+
|
|
410
|
+
protected override IEnumerable<T> GetEnumerable(T[] collection) => collection;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
internal static class ConverterHelpers
|
|
414
|
+
{
|
|
415
|
+
internal static JsonConverter<T> GetStandardInnerConverter<T, TCollection>(this ConstrainedCollectionConverter<T, TCollection> converter, JsonSerializerOptions options)
|
|
416
|
+
{
|
|
417
|
+
if (converter.InnerConverter == null)
|
|
418
|
+
{
|
|
419
|
+
converter.InnerConverter = (JsonConverter<T>)options.GetConverter(typeof(T));
|
|
420
|
+
}
|
|
421
|
+
return converter.InnerConverter;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
`
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
function StringArrayConstraintAttribute() {
|
|
430
|
+
return _$createComponent(CSharpFile, {
|
|
431
|
+
path: "StringArrayConstraintAttribute.cs",
|
|
432
|
+
using: ["System.Text.Json", "System.Text.Json.Serialization"],
|
|
433
|
+
get children() {
|
|
434
|
+
return _$createComponent(Namespace, {
|
|
435
|
+
name: "TypeSpec.Helpers.JsonConverters",
|
|
436
|
+
children: code`
|
|
437
|
+
/// <summary>
|
|
438
|
+
/// Constrains an array of strings
|
|
439
|
+
/// </summary>
|
|
440
|
+
public class StringArrayConstraintAttribute : ArrayConstraintAttribute<string>
|
|
441
|
+
{
|
|
442
|
+
int? _minItemLength = null, _maxItemLength = null;
|
|
443
|
+
|
|
444
|
+
public StringArrayConstraintAttribute() : base() { }
|
|
445
|
+
|
|
446
|
+
public int MinItemLength
|
|
447
|
+
{
|
|
448
|
+
get { return _minItemLength.HasValue ? _minItemLength.Value : 0; }
|
|
449
|
+
set { _minItemLength = value; }
|
|
450
|
+
}
|
|
451
|
+
public int MaxItemLength
|
|
452
|
+
{
|
|
453
|
+
get { return _maxItemLength.HasValue ? _maxItemLength.Value : 0; }
|
|
454
|
+
set { _maxItemLength = value; }
|
|
455
|
+
}
|
|
456
|
+
public string? Pattern { get; set; }
|
|
457
|
+
|
|
458
|
+
public override JsonConverter? CreateConverter(Type typeToConvert)
|
|
459
|
+
{
|
|
460
|
+
var result = base.CreateConverter(typeToConvert);
|
|
461
|
+
var resultSet = result as ConstrainedSetConverter<string>;
|
|
462
|
+
if (resultSet != null)
|
|
463
|
+
{
|
|
464
|
+
resultSet.InnerConverterFactory = (c, o) =>
|
|
465
|
+
new StringJsonConverter(MinItemLength, MaxItemLength, Pattern, o);
|
|
466
|
+
return resultSet;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
var resultEnumerable = result as ConstrainedEnumerableConverter<string>;
|
|
470
|
+
if (resultEnumerable != null)
|
|
471
|
+
{
|
|
472
|
+
resultEnumerable.InnerConverterFactory = (c, o) =>
|
|
473
|
+
new StringJsonConverter(MinItemLength, MaxItemLength, Pattern, o);
|
|
474
|
+
return resultEnumerable;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
var resultStandardArray = result as ConstrainedStandardArrayConverter<string>;
|
|
478
|
+
if (resultStandardArray != null)
|
|
479
|
+
{
|
|
480
|
+
resultStandardArray.InnerConverterFactory = (c, o) =>
|
|
481
|
+
new StringJsonConverter(MinItemLength, MaxItemLength, Pattern, o);
|
|
482
|
+
return resultStandardArray;
|
|
483
|
+
}
|
|
484
|
+
throw new InvalidOperationException($"Cannot create converter for {typeToConvert} with {this}");
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
`
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
function NumericArrayConstraintAttribute() {
|
|
493
|
+
return _$createComponent(CSharpFile, {
|
|
494
|
+
path: "NumericArrayConstraintAttribute.cs",
|
|
495
|
+
using: ["System.Numerics", "System.Text.Json", "System.Text.Json.Serialization"],
|
|
496
|
+
get children() {
|
|
497
|
+
return _$createComponent(Namespace, {
|
|
498
|
+
name: "TypeSpec.Helpers.JsonConverters",
|
|
499
|
+
children: code`
|
|
500
|
+
/// <summary>
|
|
501
|
+
/// Constrains an array and the item types within it
|
|
502
|
+
/// </summary>
|
|
503
|
+
/// <typeparam name="T">The item type</typeparam>
|
|
504
|
+
public class NumericArrayConstraintAttribute<T> : ArrayConstraintAttribute<T>
|
|
505
|
+
where T : struct, INumber<T>
|
|
506
|
+
{
|
|
507
|
+
T? _minValue = null, _maxValue = null;
|
|
508
|
+
|
|
509
|
+
public NumericArrayConstraintAttribute() : base() { }
|
|
510
|
+
|
|
511
|
+
public T MinValue
|
|
512
|
+
{
|
|
513
|
+
get { return _minValue.HasValue ? _minValue.Value : default(T); }
|
|
514
|
+
set { _minValue = value; }
|
|
515
|
+
}
|
|
516
|
+
public T MaxValue
|
|
517
|
+
{
|
|
518
|
+
get { return _maxValue.HasValue ? _maxValue.Value : default(T); }
|
|
519
|
+
set { _maxValue = value; }
|
|
520
|
+
}
|
|
521
|
+
bool MinValueExclusive { get; set; }
|
|
522
|
+
bool MaxValueExclusive { get; set; }
|
|
523
|
+
|
|
524
|
+
public override JsonConverter? CreateConverter(Type typeToConvert)
|
|
525
|
+
{
|
|
526
|
+
var result = base.CreateConverter(typeToConvert);
|
|
527
|
+
var resultSet = result as ConstrainedSetConverter<T>;
|
|
528
|
+
if (resultSet != null)
|
|
529
|
+
{
|
|
530
|
+
resultSet.InnerConverterFactory = (c, o) =>
|
|
531
|
+
new NumericJsonConverter<T>(MinValue, MaxValue, MinValueExclusive, MaxValueExclusive, o);
|
|
532
|
+
return resultSet;
|
|
533
|
+
}
|
|
534
|
+
var resultEnumerable = result as ConstrainedEnumerableConverter<T>;
|
|
535
|
+
if (resultEnumerable != null)
|
|
536
|
+
{
|
|
537
|
+
resultEnumerable.InnerConverterFactory = (c, o) =>
|
|
538
|
+
new NumericJsonConverter<T>(MinValue, MaxValue, MinValueExclusive, MaxValueExclusive, o);
|
|
539
|
+
return resultEnumerable;
|
|
540
|
+
}
|
|
541
|
+
var resultStandardArray = result as ConstrainedStandardArrayConverter<T>;
|
|
542
|
+
if (resultStandardArray != null)
|
|
543
|
+
{
|
|
544
|
+
resultStandardArray.InnerConverterFactory = (c, o) =>
|
|
545
|
+
new NumericJsonConverter<T>(MinValue, MaxValue, MinValueExclusive, MaxValueExclusive, o);
|
|
546
|
+
return resultStandardArray;
|
|
547
|
+
}
|
|
548
|
+
throw new InvalidOperationException($"Cannot create converter for {typeToConvert} with {this}");
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
`
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
//# sourceMappingURL=constraint-attributes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["code","Namespace","CSharpFile","ConstraintAttributes","_$createComponent","NumericConstraintAttribute","StringConstraintAttribute","ArrayConstraintAttribute","StringArrayConstraintAttribute","NumericArrayConstraintAttribute","path","using","children","name"],"sources":["../../../../src/components/serialization/constraint-attributes.tsx"],"sourcesContent":[null],"mappings":";AAAA,SAASA,IAAI,QAAuB,gBAAgB;AACpD,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,UAAU;;AAEnB;AACA;AACA;AACA;AACA,OAAO,SAASC,oBAAoBA,CAAA,EAAa;EAC/C,QAAAC,iBAAA,CAEKC,0BAA0B,OAAAD,iBAAA,CAC1BE,yBAAyB,OAAAF,iBAAA,CACzBG,wBAAwB,OAAAH,iBAAA,CACxBI,8BAA8B,OAAAJ,iBAAA,CAC9BK,+BAA+B;AAGtC;AAEA,SAASJ,0BAA0BA,CAAA,EAAa;EAC9C,OAAAD,iBAAA,CACGF,UAAU;IACTQ,IAAI;IACJC,KAAK,EAAE,CAAC,iBAAiB,EAAE,kBAAkB,EAAE,gCAAgC,CAAC;IAAA,IAAAC,SAAA;MAAA,OAAAR,iBAAA,CAE/EH,SAAS;QAACY,IAAI;QAAAD,QAAA,EACZZ,IAAI;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MAAS;IAAA;EAAA;AAIT;AAEA,SAASM,yBAAyBA,CAAA,EAAa;EAC7C,OAAAF,iBAAA,CACGF,UAAU;IACTQ,IAAI;IACJC,KAAK,EAAE,CAAC,kBAAkB,EAAE,gCAAgC,CAAC;IAAA,IAAAC,SAAA;MAAA,OAAAR,iBAAA,CAE5DH,SAAS;QAACY,IAAI;QAAAD,QAAA,EACZZ,IAAI;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MAAS;IAAA;EAAA;AAIT;AAEA,SAASO,wBAAwBA,CAAA,EAAa;EAC5C,OAAAH,iBAAA,CACGF,UAAU;IACTQ,IAAI;IACJC,KAAK,EAAE,CAAC,kBAAkB,EAAE,gCAAgC,CAAC;IAAA,IAAAC,SAAA;MAAA,OAAAR,iBAAA,CAE5DH,SAAS;QAACY,IAAI;QAAAD,QAAA,EACZZ,IAAI;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MAAS;IAAA;EAAA;AAIT;AAEA,SAASQ,8BAA8BA,CAAA,EAAa;EAClD,OAAAJ,iBAAA,CACGF,UAAU;IACTQ,IAAI;IACJC,KAAK,EAAE,CAAC,kBAAkB,EAAE,gCAAgC,CAAC;IAAA,IAAAC,SAAA;MAAA,OAAAR,iBAAA,CAE5DH,SAAS;QAACY,IAAI;QAAAD,QAAA,EACZZ,IAAI;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MAAS;IAAA;EAAA;AAIT;AAEA,SAASS,+BAA+BA,CAAA,EAAa;EACnD,OAAAL,iBAAA,CACGF,UAAU;IACTQ,IAAI;IACJC,KAAK,EAAE,CAAC,iBAAiB,EAAE,kBAAkB,EAAE,gCAAgC,CAAC;IAAA,IAAAC,SAAA;MAAA,OAAAR,iBAAA,CAE/EH,SAAS;QAACY,IAAI;QAAAD,QAAA,EACZZ,IAAI;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MAAS;IAAA;EAAA;AAIT","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Children } from "@alloy-js/core";
|
|
2
|
+
/**
|
|
3
|
+
* Renders the HttpServiceException class and HttpServiceExceptionFilter.
|
|
4
|
+
* The exception class represents HTTP response exceptions with status codes.
|
|
5
|
+
* The filter converts these exceptions to proper HTTP responses.
|
|
6
|
+
*/
|
|
7
|
+
export declare function HttpServiceExceptionFilter(): Children;
|
|
8
|
+
//# sourceMappingURL=http-service-exception-filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-service-exception-filter.d.ts","sourceRoot":"","sources":["../../../../src/components/serialization/http-service-exception-filter.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAIrD;;;;GAIG;AACH,wBAAgB,0BAA0B,IAAI,QAAQ,CA2DrD"}
|