Skip to content

Commit cda2da5

Browse files
committed
[Playground]: revert TypeGen sample to attributes — fluent ITypeGenConfigurator
hits SemanticModel.GetConstantValue ArgumentException in playground's runtime compilation. Attribute-based [GenerateTypes] works correctly. Fluent alternative shown as comment.
1 parent 5f85182 commit cda2da5

1 file changed

Lines changed: 23 additions & 22 deletions

File tree

  • packages/ZibStack.NET.UI/sample/SampleApi/wwwroot

packages/ZibStack.NET.UI/sample/SampleApi/wwwroot/index.html

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -771,30 +771,36 @@ <h1><em>ZibStack.NET</em> Playground</h1>
771771
// [ZMaxLength], [ZRange] constraints automatically.`,
772772

773773
'typegen': `// TypeGen — generate TypeScript, Zod, GraphQL from C# DTOs.
774-
// Two styles: [GenerateTypes] attribute OR fluent ITypeGenConfigurator.
775774
// Open the "TypeGen" tab to see generated output files.
776775
777776
using ZibStack.NET.Dto;
778777
using ZibStack.NET.TypeGen;
779778
780779
namespace Demo;
781780
782-
// MODEL: no [GenerateTypes] attribute needed — fluent config opts it in.
781+
[GenerateTypes(Targets = TypeTarget.TypeScript | TypeTarget.Zod | TypeTarget.GraphQL)]
783782
[CrudApi(Route = "api/products")]
784783
[CreateDto]
785784
[ResponseDto]
786785
public partial class Product
787786
{
788787
[DtoIgnore] public int Id { get; set; }
788+
789+
[TsName("productName")] // override TS field name
789790
public required string Name { get; set; }
791+
790792
public string? Description { get; set; }
791793
public decimal Price { get; set; }
792794
public int Stock { get; set; }
793795
public bool IsActive { get; set; }
794796
public ProductCategory Category { get; set; }
797+
798+
[TsIgnore] // exclude from TypeScript + Zod
799+
[OpenApiIgnore] // exclude from OpenAPI
795800
public string InternalSku { get; set; } = "";
796801
}
797802
803+
[GenerateTypes(Targets = TypeTarget.TypeScript | TypeTarget.Zod | TypeTarget.GraphQL)]
798804
public enum ProductCategory
799805
{
800806
Electronics,
@@ -804,26 +810,21 @@ <h1><em>ZibStack.NET</em> Playground</h1>
804810
Other
805811
}
806812
807-
// FLUENT CONFIG: zero attributes on the model — central file drives output.
808-
internal sealed class TypeGenConfig : ITypeGenConfigurator
809-
{
810-
public void Configure(ITypeGenBuilder b)
811-
{
812-
// Global settings per target
813-
b.TypeScript(ts => ts.OutputDir = "generated/ts");
814-
b.Zod(zod => zod.OutputDir = "generated/zod");
815-
816-
// Opt-in Product for TypeScript + Zod + GraphQL
817-
b.ForType<Product>()
818-
.WithGeneratedTypes(TypeTarget.TypeScript | TypeTarget.Zod | TypeTarget.GraphQL)
819-
.Property(p => p.Name).TsName("productName") // rename in TS
820-
.Property(p => p.InternalSku).TsIgnore(); // exclude from TS
821-
822-
// Opt-in enum too
823-
b.ForType<ProductCategory>()
824-
.WithGeneratedTypes(TypeTarget.TypeScript | TypeTarget.Zod | TypeTarget.GraphQL);
825-
}
826-
}`,
813+
// ──────────────────────────────────────────────────────────
814+
// Alternative: fluent ITypeGenConfigurator (zero attributes
815+
// on the model — central config file drives output).
816+
// Works in real projects, not in the playground.
817+
//
818+
// internal sealed class TypeGenConfig : ITypeGenConfigurator
819+
// {
820+
// public void Configure(ITypeGenBuilder b)
821+
// {
822+
// b.ForType<Product>()
823+
// .WithGeneratedTypes(TypeTarget.TypeScript | TypeTarget.Zod)
824+
// .Property(p => p.Name).TsName("productName")
825+
// .Property(p => p.InternalSku).TsIgnore();
826+
// }
827+
// }`,
827828
};
828829

829830
function loadSample(name) { if(editor && samples[name]) { editor.setValue(samples[name]); } }

0 commit comments

Comments
 (0)