-
Notifications
You must be signed in to change notification settings - Fork 314
Open
Labels
Milestone
Description
Describe the bug
This problem seems to be happened when model T(in this case Product) consists only of enum and built-in types.
I'm not sure this happens in other cases.
versions
@typespec/compiler version 1.3.0
@typespec/http version 1.3.0
@typespec/http-server-csharp version 0.58.0-alpha.19
main.tsp
import "@typespec/http";
using Http;
@service(#{ title: "Product Service" })
namespace DemoService;
model Product {
id: uint32;
name: string;
category: ProductCategory;
}
enum ProductCategory {
Electronics,
Books,
Clothing,
Home
}
@route("/products")
@tag("Products")
interface Products {
/** List products */
@get list(): Product[];
/** Read products */
@get read(@path id: string): Product;
/** Create a product */
@post create(@body body: Product): Product;
/** Update a product */
@patch update(@path id: string, @body body: MergePatchUpdate<Product>): Product;
/** Delete a product */
@delete delete(@path id: string): void;
}
generated ProductMergePatchUpdate.cs
// Generated by @typespec/http-server-csharp
// <auto-generated />
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using TypeSpec.Helpers.JsonConverters;
using TypeSpec.Helpers;
namespace TypeSpec.Http
{
public partial class ProductMergePatchUpdate
{
public UInt32? Id { get; set; }
public string Name { get; set; }
[JsonConverter(typeof(JsonStringEnumConverter))]
public ProductCategory? Category { get; set; } // ProductCategory NOT BE RESOLVED WITHOUT A NAMESPACE IMPORT (using DemoService;)
}
}
ProductMergePatchUpdate.cs should be like this.
// Generated by @typespec/http-server-csharp
// <auto-generated />
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using TypeSpec.Helpers.JsonConverters;
using TypeSpec.Helpers;
using DemoService; // THIS SHOULD BE HERE AND THIS CODE WILL BE COMPILED SUCCESSFULY
namespace TypeSpec.Http
{
public partial class ProductMergePatchUpdate
{
public UInt32? Id { get; set; }
public string Name { get; set; }
[JsonConverter(typeof(JsonStringEnumConverter))]
public ProductCategory? Category { get; set; }
}
}
Reproduction
main.tsp
import "@typespec/http";
using Http;
@service(#{ title: "Product Service" })
namespace DemoService;
model Product {
id: uint32;
name: string;
category: ProductCategory;
}
enum ProductCategory {
Electronics,
Books,
Clothing,
Home
}
@route("/products")
@tag("Products")
interface Products {
/** List products */
@get list(): Product[];
/** Read products */
@get read(@path id: string): Product;
/** Create a product */
@post create(@body body: Product): Product;
/** Update a product */
@patch update(@path id: string, @body body: MergePatchUpdate<Product>): Product;
/** Delete a product */
@delete delete(@path id: string): void;
}
generated ProductMergePatchUpdate.cs
// Generated by @typespec/http-server-csharp
// <auto-generated />
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using TypeSpec.Helpers.JsonConverters;
using TypeSpec.Helpers;
namespace TypeSpec.Http
{
public partial class ProductMergePatchUpdate
{
public UInt32? Id { get; set; }
public string Name { get; set; }
[JsonConverter(typeof(JsonStringEnumConverter))]
public ProductCategory? Category { get; set; }
}
}
Checklist
- Follow our Code of Conduct
- Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion.
- The provided reproduction is a minimal reproducible example of the bug.