@typespec/http-server-csharp 0.58.0-alpha.2-dev.1 → 0.58.0-alpha.20-dev.0

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.
Files changed (78) hide show
  1. package/README.md +69 -6
  2. package/cmd/hscs.js +2 -0
  3. package/dist/src/cli/cli.d.ts +2 -0
  4. package/dist/src/cli/cli.d.ts.map +1 -0
  5. package/dist/src/cli/cli.js +173 -0
  6. package/dist/src/cli/cli.js.map +1 -0
  7. package/dist/src/{attributes.d.ts → lib/attributes.d.ts} +1 -1
  8. package/dist/src/lib/attributes.d.ts.map +1 -0
  9. package/dist/src/{attributes.js → lib/attributes.js} +113 -35
  10. package/dist/src/lib/attributes.js.map +1 -0
  11. package/dist/src/lib/boilerplate.d.ts +6 -0
  12. package/dist/src/lib/boilerplate.d.ts.map +1 -0
  13. package/dist/src/{boilerplate.js → lib/boilerplate.js} +253 -66
  14. package/dist/src/lib/boilerplate.js.map +1 -0
  15. package/dist/src/lib/doc.d.ts +5 -0
  16. package/dist/src/lib/doc.d.ts.map +1 -0
  17. package/dist/src/lib/doc.js +237 -0
  18. package/dist/src/lib/doc.js.map +1 -0
  19. package/dist/src/lib/index.d.ts.map +1 -0
  20. package/dist/src/lib/index.js.map +1 -0
  21. package/dist/src/{interfaces.d.ts → lib/interfaces.d.ts} +58 -4
  22. package/dist/src/lib/interfaces.d.ts.map +1 -0
  23. package/dist/src/{interfaces.js → lib/interfaces.js} +100 -27
  24. package/dist/src/lib/interfaces.js.map +1 -0
  25. package/dist/src/{lib.d.ts → lib/lib.d.ts} +54 -1
  26. package/dist/src/lib/lib.d.ts.map +1 -0
  27. package/dist/src/lib/lib.js +146 -0
  28. package/dist/src/lib/lib.js.map +1 -0
  29. package/dist/src/lib/project.d.ts +5 -0
  30. package/dist/src/lib/project.d.ts.map +1 -0
  31. package/dist/src/lib/project.js +101 -0
  32. package/dist/src/lib/project.js.map +1 -0
  33. package/dist/src/lib/scaffolding.d.ts +22 -0
  34. package/dist/src/lib/scaffolding.d.ts.map +1 -0
  35. package/dist/src/lib/scaffolding.js +461 -0
  36. package/dist/src/lib/scaffolding.js.map +1 -0
  37. package/dist/src/lib/service.d.ts.map +1 -0
  38. package/dist/src/lib/service.js +1188 -0
  39. package/dist/src/lib/service.js.map +1 -0
  40. package/dist/src/lib/testing/index.d.ts.map +1 -0
  41. package/dist/src/{testing → lib/testing}/index.js +1 -0
  42. package/dist/src/lib/testing/index.js.map +1 -0
  43. package/dist/src/{type-helpers.d.ts → lib/type-helpers.d.ts} +5 -1
  44. package/dist/src/lib/type-helpers.d.ts.map +1 -0
  45. package/dist/src/{type-helpers.js → lib/type-helpers.js} +31 -0
  46. package/dist/src/lib/type-helpers.js.map +1 -0
  47. package/dist/src/lib/utils.d.ts +114 -0
  48. package/dist/src/lib/utils.d.ts.map +1 -0
  49. package/dist/src/lib/utils.js +1557 -0
  50. package/dist/src/lib/utils.js.map +1 -0
  51. package/package.json +49 -27
  52. package/dist/src/attributes.d.ts.map +0 -1
  53. package/dist/src/attributes.js.map +0 -1
  54. package/dist/src/boilerplate.d.ts +0 -4
  55. package/dist/src/boilerplate.d.ts.map +0 -1
  56. package/dist/src/boilerplate.js.map +0 -1
  57. package/dist/src/index.d.ts.map +0 -1
  58. package/dist/src/index.js.map +0 -1
  59. package/dist/src/interfaces.d.ts.map +0 -1
  60. package/dist/src/interfaces.js.map +0 -1
  61. package/dist/src/lib.d.ts.map +0 -1
  62. package/dist/src/lib.js +0 -60
  63. package/dist/src/lib.js.map +0 -1
  64. package/dist/src/service.d.ts.map +0 -1
  65. package/dist/src/service.js +0 -829
  66. package/dist/src/service.js.map +0 -1
  67. package/dist/src/testing/index.d.ts.map +0 -1
  68. package/dist/src/testing/index.js.map +0 -1
  69. package/dist/src/type-helpers.d.ts.map +0 -1
  70. package/dist/src/type-helpers.js.map +0 -1
  71. package/dist/src/utils.d.ts +0 -48
  72. package/dist/src/utils.d.ts.map +0 -1
  73. package/dist/src/utils.js +0 -628
  74. package/dist/src/utils.js.map +0 -1
  75. /package/dist/src/{index.d.ts → lib/index.d.ts} +0 -0
  76. /package/dist/src/{index.js → lib/index.js} +0 -0
  77. /package/dist/src/{service.d.ts → lib/service.d.ts} +0 -0
  78. /package/dist/src/{testing → lib/testing}/index.d.ts +0 -0
@@ -1,4 +1,9 @@
1
1
  import { LibrarySourceFile } from "./interfaces.js";
2
+ export const GeneratedFileHeader = `// Generated by @typespec/http-server-csharp
3
+ // <auto-generated />`;
4
+ export const GeneratedFileHeaderWithNullable = `// Generated by @typespec/http-server-csharp
5
+ // <auto-generated />
6
+ #nullable enable`;
2
7
  export function getSerializationSourceFiles(emitter) {
3
8
  const sourceFiles = [];
4
9
  sourceFiles.push(new LibrarySourceFile({
@@ -6,9 +11,9 @@ export function getSerializationSourceFiles(emitter) {
6
11
  emitter: emitter,
7
12
  getContents: getTimeSpanDurationConverter,
8
13
  }), new LibrarySourceFile({
9
- filename: "Base64UrlConverter.cs",
14
+ filename: "Base64UrlJsonConverter.cs",
10
15
  emitter: emitter,
11
- getContents: getBase64UrlConverter,
16
+ getContents: getBase64UrlJsonConverter,
12
17
  }), new LibrarySourceFile({
13
18
  filename: "UnixEpochDateTimeConverter.cs",
14
19
  emitter: emitter,
@@ -37,14 +42,23 @@ export function getSerializationSourceFiles(emitter) {
37
42
  filename: "NumericArrayConstraintAttribute.cs",
38
43
  emitter: emitter,
39
44
  getContents: getNumericArrayConstraintConverter,
45
+ }), new LibrarySourceFile({
46
+ filename: "IJsonSerializationProvider.cs",
47
+ emitter: emitter,
48
+ getContents: getJsonProviderInterface,
49
+ }), new LibrarySourceFile({
50
+ filename: "JsonSerializationProvider.cs",
51
+ emitter: emitter,
52
+ getContents: getJsonProvider,
53
+ }), new LibrarySourceFile({
54
+ filename: "HttpServiceException.cs",
55
+ emitter: emitter,
56
+ getContents: getHttpServiceException,
40
57
  }));
41
58
  return sourceFiles;
42
59
  }
43
60
  function getNumericConstraintConverter() {
44
- return `// Copyright (c) Microsoft Corporation. All rights reserved.
45
- // Licensed under the MIT License.
46
- // <auto-generated />
47
- #nullable enable
61
+ return `${GeneratedFileHeaderWithNullable}
48
62
 
49
63
  using System.Numerics;
50
64
  using System.Text.Json;
@@ -144,10 +158,7 @@ function getNumericConstraintConverter() {
144
158
  }`;
145
159
  }
146
160
  function getStringConstraintConverter() {
147
- return `// Copyright (c) Microsoft Corporation. All rights reserved.
148
- // Licensed under the MIT License.
149
- // <auto-generated />
150
- #nullable enable
161
+ return `${GeneratedFileHeaderWithNullable}
151
162
 
152
163
  using System.Text.Json;
153
164
  using System.Text.Json.Serialization;
@@ -268,10 +279,7 @@ function getStringConstraintConverter() {
268
279
  }`;
269
280
  }
270
281
  function getArrayConstraintConverter() {
271
- return `// Copyright (c) Microsoft Corporation. All rights reserved.
272
- // Licensed under the MIT License.
273
- // <auto-generated />
274
- #nullable enable
282
+ return `${GeneratedFileHeaderWithNullable}
275
283
 
276
284
  using System.Text.Json;
277
285
  using System.Text.Json.Serialization;
@@ -301,44 +309,52 @@ function getArrayConstraintConverter() {
301
309
 
302
310
  public override JsonConverter? CreateConverter(Type typeToConvert)
303
311
  {
304
- return new ConstrainedArrayConverter<T>(_minItems, _maxItems);
312
+ if (typeof(ISet<T>).IsAssignableFrom(typeToConvert))
313
+ {
314
+ return new ConstrainedSetConverter<T>(_minItems, _maxItems);
315
+ }
316
+ else if (typeToConvert.IsArray && typeToConvert.GetElementType() == typeof(T))
317
+ {
318
+ return new ConstrainedStandardArrayConverter<T>(_minItems, _maxItems);
319
+ }
320
+ else
321
+ {
322
+ return new ConstrainedEnumerableConverter<T>(_minItems, _maxItems);
323
+ }
305
324
  }
306
-
307
-
308
325
  }
309
326
 
310
- public class ConstrainedArrayConverter<T> : JsonConverter<T[]>
327
+ public abstract class ConstrainedCollectionConverter<T, TCollection> : JsonConverter<TCollection>
311
328
  {
312
- public ConstrainedArrayConverter(int? min, int? max) : base()
329
+ protected ConstrainedCollectionConverter(int? min, int? max)
313
330
  {
314
331
  _minItems = min;
315
332
  _maxItems = max;
316
333
  }
317
334
 
318
- internal int? _minItems, _maxItems;
335
+ protected int? _minItems, _maxItems;
319
336
  public JsonConverter<T>? InnerConverter { get; set; }
320
337
 
321
- public virtual Func<ConstrainedArrayConverter<T>, JsonSerializerOptions, JsonConverter<T>> InnerConverterFactory { get; set; } = ConverterHelpers.GetStandardInnerConverter<T>;
322
-
338
+ public virtual Func<ConstrainedCollectionConverter<T, TCollection>, JsonSerializerOptions, JsonConverter<T>> InnerConverterFactory { get; set; } = ConverterHelpers.GetStandardInnerConverter<T, TCollection>;
323
339
 
324
- internal bool ValidateMin(int count)
340
+ protected bool ValidateMin(int count)
325
341
  {
326
342
  return !_minItems.HasValue || count >= _minItems.Value;
327
343
  }
328
344
 
329
- internal bool ValidateMax(int count)
345
+ protected bool ValidateMax(int count)
330
346
  {
331
347
  return !_maxItems.HasValue || count <= _maxItems.Value;
332
348
  }
333
349
 
334
- internal void ValidateRange(int count)
350
+ protected void ValidateRange(int count)
335
351
  {
336
352
  if (!ValidateMax(count) || !ValidateMin(count))
337
353
  {
338
354
  throw new JsonException($"Number of array elements not in range [{(_minItems.HasValue ? _minItems.Value : 0)}, {(_maxItems.HasValue ? _maxItems.Value : Array.MaxLength)}]");
339
355
  }
340
356
  }
341
- public override T[]? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
357
+ public override TCollection? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
342
358
  {
343
359
  var _innerConverter = InnerConverterFactory(this, options);
344
360
  if (reader.TokenType != JsonTokenType.StartArray) { throw new JsonException("Expected start of array"); }
@@ -353,40 +369,59 @@ function getArrayConstraintConverter() {
353
369
  count++;
354
370
  }
355
371
 
356
- return list.ToArray();
357
-
372
+ return ConvertToCollection(list);
358
373
 
359
374
  }
360
375
 
361
- public override void Write(Utf8JsonWriter writer, T[] value, JsonSerializerOptions options)
376
+ public override void Write(Utf8JsonWriter writer, TCollection value, JsonSerializerOptions options)
362
377
  {
363
378
  var _innerConverter = InnerConverterFactory(this, options);
364
379
  writer.WriteStartArray();
365
- for (int i = 0; i < value.Length; ++i)
366
- _innerConverter.Write(writer, value[i], options);
380
+ foreach (var item in GetEnumerable(value))
381
+ _innerConverter.Write(writer, item, options);
367
382
  writer.WriteEndArray();
368
383
  }
384
+
385
+ protected abstract TCollection ConvertToCollection(List<T> list);
386
+ protected abstract IEnumerable<T> GetEnumerable(TCollection collection);
387
+ }
388
+
389
+ public class ConstrainedEnumerableConverter<T> : ConstrainedCollectionConverter<T, IEnumerable<T>>
390
+ {
391
+ public ConstrainedEnumerableConverter(int? min, int? max) : base(min, max) { }
392
+ protected override IEnumerable<T> ConvertToCollection(List<T> list) => list;
393
+ protected override IEnumerable<T> GetEnumerable(IEnumerable<T> collection) => collection;
394
+ }
395
+
396
+ public class ConstrainedSetConverter<T> : ConstrainedCollectionConverter<T, ISet<T>>
397
+ {
398
+ public ConstrainedSetConverter(int? min, int? max) : base(min, max) { }
399
+ protected override ISet<T> ConvertToCollection(List<T> list) => new HashSet<T>(list);
400
+ protected override IEnumerable<T> GetEnumerable(ISet<T> collection) => collection;
401
+ }
402
+
403
+ public class ConstrainedStandardArrayConverter<T> : ConstrainedCollectionConverter<T, T[]>
404
+ {
405
+ public ConstrainedStandardArrayConverter(int? min, int? max) : base(min, max) { }
406
+ protected override T[] ConvertToCollection(List<T> list) => list.ToArray();
407
+ protected override IEnumerable<T> GetEnumerable(T[] collection) => collection;
369
408
  }
370
409
 
371
410
  internal static class ConverterHelpers
372
411
  {
373
- internal static JsonConverter<T> GetStandardInnerConverter<T>(this ConstrainedArrayConverter<T> converter, JsonSerializerOptions options)
412
+ internal static JsonConverter<T> GetStandardInnerConverter<T, TCollection>(this ConstrainedCollectionConverter<T, TCollection> converter, JsonSerializerOptions options)
374
413
  {
375
414
  if (converter.InnerConverter == null)
376
415
  {
377
416
  converter.InnerConverter = (JsonConverter<T>)options.GetConverter(typeof(T));
378
417
  }
379
-
380
418
  return converter.InnerConverter;
381
419
  }
382
420
  }
383
421
  }`;
384
422
  }
385
423
  function getNumericArrayConstraintConverter() {
386
- return `// Copyright (c) Microsoft Corporation. All rights reserved.
387
- // Licensed under the MIT License.
388
- // <auto-generated />
389
- #nullable enable
424
+ return `${GeneratedFileHeaderWithNullable}
390
425
 
391
426
  using System.Numerics;
392
427
  using System.Text.Json;
@@ -412,18 +447,29 @@ public class NumericArrayConstraintAttribute<T> : ArrayConstraintAttribute<T> wh
412
447
 
413
448
  public override JsonConverter? CreateConverter(Type typeToConvert)
414
449
  {
415
- var result = base.CreateConverter(typeToConvert) as ConstrainedArrayConverter<T>;
416
- if (result != null) result.InnerConverterFactory = (c, o) => new NumericJsonConverter<T>(MinValue, MaxValue, MinValueExclusive, MaxValueExclusive, o);
417
- return result;
450
+ var result = base.CreateConverter(typeToConvert);
451
+ var resultSet = result as ConstrainedSetConverter<T>;
452
+ if (resultSet != null) {
453
+ resultSet.InnerConverterFactory = (c, o) => new NumericJsonConverter<T>(MinValue, MaxValue, MinValueExclusive, MaxValueExclusive, o);
454
+ return resultSet;
455
+ }
456
+ var resultEnumerable = result as ConstrainedEnumerableConverter<T>;
457
+ if (resultEnumerable != null) {
458
+ resultEnumerable.InnerConverterFactory = (c, o) => new NumericJsonConverter<T>(MinValue, MaxValue, MinValueExclusive, MaxValueExclusive, o);
459
+ return resultEnumerable;
460
+ }
461
+ var resultStandardArray = result as ConstrainedStandardArrayConverter<T>;
462
+ if (resultStandardArray != null) {
463
+ resultStandardArray.InnerConverterFactory = (c, o) => new NumericJsonConverter<T>(MinValue, MaxValue, MinValueExclusive, MaxValueExclusive, o);
464
+ return resultStandardArray;
465
+ }
466
+ throw new InvalidOperationException($"Cannot create converter for {typeToConvert} with {this}");
418
467
  }
419
468
  }
420
469
  }`;
421
470
  }
422
471
  function getStringArrayConstraintConverter() {
423
- return `// Copyright (c) Microsoft Corporation. All rights reserved.
424
- // Licensed under the MIT License.
425
- // <auto-generated />
426
- #nullable enable
472
+ return `${GeneratedFileHeaderWithNullable}
427
473
 
428
474
  using System.Text.Json;
429
475
  using System.Text.Json.Serialization;
@@ -444,20 +490,33 @@ public class StringArrayConstraintAttribute : ArrayConstraintAttribute<string>
444
490
  public int MaxItemLength { get { return _maxItemLength.HasValue ? _maxItemLength.Value : 0; } set { _maxItemLength = value; } }
445
491
  public string? Pattern { get; set; }
446
492
 
447
- override public JsonConverter<string[]> CreateConverter(Type typeToConvert)
493
+ override public JsonConverter? CreateConverter(Type typeToConvert)
448
494
  {
449
- var result = base.CreateConverter(typeToConvert) as ConstrainedArrayConverter<string>;
450
- result!.InnerConverterFactory = (c, o) => new StringJsonConverter(MinItemLength, MaxItemLength, Pattern, o);
451
- return result;
495
+ var result = base.CreateConverter(typeToConvert);
496
+ var resultSet = result as ConstrainedSetConverter<string>;
497
+ if (resultSet != null) {
498
+ resultSet.InnerConverterFactory = (c, o) => new StringJsonConverter(MinItemLength, MaxItemLength, Pattern, o);
499
+ return resultSet;
500
+ }
501
+
502
+ var resultEnumerable = result as ConstrainedEnumerableConverter<string>;
503
+ if (resultEnumerable != null) {
504
+ resultEnumerable.InnerConverterFactory = (c, o) => new StringJsonConverter(MinItemLength, MaxItemLength, Pattern, o);
505
+ return resultEnumerable;
506
+ }
507
+
508
+ var resultStandardArray = result as ConstrainedStandardArrayConverter<string>;
509
+ if (resultStandardArray != null) {
510
+ resultStandardArray.InnerConverterFactory = (c, o) => new StringJsonConverter(MinItemLength, MaxItemLength, Pattern, o);
511
+ return resultStandardArray;
512
+ }
513
+ throw new InvalidOperationException($"Cannot create converter for {typeToConvert} with {this}");
452
514
  }
453
515
  }
454
516
  }`;
455
517
  }
456
518
  function getTimeSpanDurationConverter() {
457
- return `// Copyright (c) Microsoft Corporation. All rights reserved.
458
- // Licensed under the MIT License.
459
- // <auto-generated />
460
- #nullable enable
519
+ return `${GeneratedFileHeaderWithNullable}
461
520
 
462
521
  using System.Text.Json;
463
522
  using System.Text.Json.Serialization;
@@ -468,7 +527,7 @@ function getTimeSpanDurationConverter() {
468
527
  /// <summary>
469
528
  /// Converts between Json duration and .Net TimeSpan
470
529
  /// </summary>
471
- public class TimespanDurationConverter : JsonConverter<TimeSpan>
530
+ public class TimeSpanDurationConverter : JsonConverter<TimeSpan>
472
531
  {
473
532
  public override TimeSpan Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
474
533
  {
@@ -488,11 +547,8 @@ function getTimeSpanDurationConverter() {
488
547
  }
489
548
  `;
490
549
  }
491
- function getBase64UrlConverter() {
492
- return `// Copyright (c) Microsoft Corporation. All rights reserved.
493
- // Licensed under the MIT License.
494
- // <auto-generated />
495
- #nullable enable
550
+ function getBase64UrlJsonConverter() {
551
+ return `${GeneratedFileHeaderWithNullable}
496
552
 
497
553
  using System.Text.Json;
498
554
  using System.Text.Json.Serialization;
@@ -536,10 +592,7 @@ function getBase64UrlConverter() {
536
592
  `;
537
593
  }
538
594
  function getUnixEpochDateTimeConverter() {
539
- return `// Copyright (c) Microsoft Corporation. All rights reserved.
540
- // Licensed under the MIT License.
541
- // <auto-generated />
542
- #nullable enable
595
+ return `${GeneratedFileHeaderWithNullable}
543
596
 
544
597
  using System.Text.Json;
545
598
  using System.Text.Json.Serialization;
@@ -569,10 +622,7 @@ function getUnixEpochDateTimeConverter() {
569
622
  `;
570
623
  }
571
624
  function getUnixEpochDateTimeOffsetConverter() {
572
- return `// Copyright (c) Microsoft Corporation. All rights reserved.
573
- // Licensed under the MIT License.
574
- // <auto-generated />
575
- #nullable enable
625
+ return `${GeneratedFileHeaderWithNullable}
576
626
 
577
627
  using System.Text.Json;
578
628
  using System.Text.Json.Serialization;
@@ -602,4 +652,141 @@ function getUnixEpochDateTimeOffsetConverter() {
602
652
  }
603
653
  `;
604
654
  }
655
+ function getJsonProviderInterface() {
656
+ return `${GeneratedFileHeaderWithNullable}
657
+
658
+ using System.Text.Json;
659
+ using System.Text.Json.Serialization;
660
+
661
+ namespace TypeSpec.Helpers
662
+ {
663
+ /// <summary>
664
+ /// Interface for Json serialization, suitable for providing a service in ASP.Net dependency injection
665
+ /// </summary>
666
+ public interface IJsonSerializationProvider
667
+ {
668
+ /// <summary>
669
+ /// Serialize an object to a JSON string
670
+ /// </summary>
671
+ /// <typeparam name="T">The type of the object</typeparam>
672
+ /// <param name="value">The object to serialize</param>
673
+ /// <returns>A string representing the serialized object</returns>
674
+ string Serialize<T>(T value);
675
+
676
+ /// <summary>
677
+ /// Create an object from a json string
678
+ /// </summary>
679
+ /// <typeparam name="T">The type of the object represented in the string</typeparam>
680
+ /// <param name="value">The strign to deserialize</param>
681
+ /// <returns>The deserialized object, or null</returns>
682
+ T? Deserialize<T>(string value);
683
+ }
684
+ }
685
+ `;
686
+ }
687
+ function getJsonProvider() {
688
+ return `${GeneratedFileHeaderWithNullable}
689
+
690
+ using System.Text.Json;
691
+ using System.Text.Json.Serialization;
692
+
693
+ namespace TypeSpec.Helpers
694
+ {
695
+ /// <summary>
696
+ /// Standard implementation of IJsonSerializationProvider
697
+ /// </summary>
698
+ public class JsonSerializationProvider : IJsonSerializationProvider
699
+ {
700
+ /// <summary>
701
+ /// The options to use for serialization
702
+ /// </summary>
703
+ public virtual JsonSerializerOptions Options { get; } = new JsonSerializerOptions
704
+ {
705
+ PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
706
+ DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
707
+ };
708
+
709
+ /// <summary>
710
+ /// Create an object from a json string
711
+ /// </summary>
712
+ /// <typeparam name="T">The type of the object represented in the string</typeparam>
713
+ /// <param name="value">The strign to deserialize</param>
714
+ /// <returns>The deserialized object, or null</returns>
715
+ public virtual T? Deserialize<T>(string value)
716
+ {
717
+ return JsonSerializer.Deserialize<T>(value, Options);
718
+ }
719
+
720
+ /// <summary>
721
+ /// Serialize an object to a JSON string
722
+ /// </summary>
723
+ /// <typeparam name="T">The type of the object</typeparam>
724
+ /// <param name="value">The object to serialize</param>
725
+ /// <returns>A string representing the serialized object</returns>
726
+ public virtual string Serialize<T>(T value)
727
+ {
728
+ return JsonSerializer.Serialize(value, Options);
729
+ }
730
+ }
731
+ }
732
+ `;
733
+ }
734
+ function getHttpServiceException() {
735
+ return `${GeneratedFileHeaderWithNullable}
736
+
737
+ using Microsoft.AspNetCore.Mvc;
738
+ using Microsoft.AspNetCore.Mvc.Filters;
739
+
740
+ namespace TypeSpec.Helpers
741
+ {
742
+ /// <summary>
743
+ /// Represents an HTTP response exception with a status code and optional value.
744
+ /// </summary>
745
+ public class HttpServiceException : Exception
746
+ {
747
+ /// <summary>
748
+ /// Initializes a new instance of the HttpServiceException class.
749
+ /// </summary>
750
+ /// <param name="statusCode">The HTTP status code.</param>
751
+ /// <param name="value">The optional value to include in the response.</param>
752
+ public HttpServiceException(int statusCode, object? value = null, Dictionary<string, string>? headers = null) =>
753
+ (StatusCode, Value, Headers) = (statusCode, value, headers ?? new Dictionary<string, string>());
754
+
755
+ public int StatusCode { get; }
756
+
757
+ public object? Value { get; }
758
+
759
+ public Dictionary<string, string> Headers { get; }
760
+ }
761
+
762
+ /// <summary>
763
+ /// An action filter that handles HttpServiceException and converts it to an HTTP response.
764
+ /// </summary>
765
+ public class HttpServiceExceptionFilter : IActionFilter, IOrderedFilter
766
+ {
767
+ public int Order => int.MaxValue - 10;
768
+
769
+ public void OnActionExecuting(ActionExecutingContext context) { }
770
+
771
+ public void OnActionExecuted(ActionExecutedContext context)
772
+ {
773
+ if (context.Exception is HttpServiceException httpServiceException)
774
+ {
775
+ foreach (var header in httpServiceException.Headers)
776
+ {
777
+ context.HttpContext.Response.Headers.Append(header.Key, header.Value.ToString());
778
+ }
779
+
780
+ context.Result = new ObjectResult(httpServiceException.Value)
781
+ {
782
+ StatusCode = httpServiceException.StatusCode
783
+ };
784
+
785
+ context.ExceptionHandled = true;
786
+ }
787
+ }
788
+ }
789
+ }
790
+ `;
791
+ }
605
792
  //# sourceMappingURL=boilerplate.js.map
@@ -0,0 +1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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6CzC,CAAC;AACH,CAAC;AAED,SAAS,iCAAiC;IACxC,OAAO,GAAG,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA4CvC,CAAC;AACL,CAAC;AAED,SAAS,4BAA4B;IACnC,OAAO,GAAG,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BxC,CAAC;AACJ,CAAC;AAED,SAAS,yBAAyB;IAChC,OAAO,GAAG,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCxC,CAAC;AACJ,CAAC;AAED,SAAS,6BAA6B;IACpC,OAAO,GAAG,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BxC,CAAC;AACJ,CAAC;AAED,SAAS,mCAAmC;IAC1C,OAAO,GAAG,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BxC,CAAC;AACJ,CAAC;AAED,SAAS,wBAAwB;IAC/B,OAAO,GAAG,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6B1C,CAAC;AACF,CAAC;AAED,SAAS,eAAe;IACtB,OAAO,GAAG,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4C1C,CAAC;AACF,CAAC;AAED,SAAS,uBAAuB;IAC9B,OAAO,GAAG,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuD1C,CAAC;AACF,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { AssetEmitter } from "@typespec/asset-emitter";
2
+ import { LibrarySourceFile } from "./interfaces.js";
3
+ import { BusinessLogicRegistrations } from "./scaffolding.js";
4
+ export declare function getProjectDocs(emitter: AssetEmitter<string, Record<string, never>>, useSwagger: boolean, registrations?: BusinessLogicRegistrations): LibrarySourceFile[];
5
+ //# sourceMappingURL=doc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"doc.d.ts","sourceRoot":"","sources":["../../../src/lib/doc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAA+B,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAE3F,wBAAgB,cAAc,CAC5B,OAAO,EAAE,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,EACpD,UAAU,EAAE,OAAO,EACnB,aAAa,CAAC,EAAE,0BAA0B,GACzC,iBAAiB,EAAE,CA0BrB"}