microsoft / microsoft/typespec
[Bug]: http-server-csharp: Generated model file is empty and produces a warning: Inline models use generated names in emitted code. Consider defining each model with an explicit name.
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 394
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 104
Description
### Describe the bug
All warnings:
```
typespec/node_modules/@azure-tools/typespec-azure-core/lib/traits.tsp:147:20 - warning @typespec/http-server-csharp/anonymous-model: Inline models use generated names in emitted code. Consider defining each model with an explicit name. This model will be named 'Model0' in emitted code
> 147 | clientRequestId: {};
| ^^
typespec/node_modules/@azure-tools/typespec-azure-core/lib/traits.tsp:177:24 - warning @typespec/http-server-csharp/anonymous-model: Inline models use generated names in emitted code. Consider defining each model with an explicit name. This model will be named 'Model1' in emitted code
> 177 | conditionalRequests: {};
| ^^
typespec/node_modules/@azure-tools/typespec-azure-core/lib/traits.tsp:206:23 - warning @typespec/http-server-csharp/anonymous-model: Inline models use generated names in emitted code. Consider defining each model with an explicit name. This model will be named 'Model2' in emitted code
> 206 | repeatableRequests: {};
| ^^
```
Resulting C# class:
```csharp
// Generated by @typespec/http-server-csharp
//
#nullable enable
using System;
using System.Collections.Generic;
using System.Text.Json;
using TypeSpec.Helpers;
using TypeSpec.Helpers.JsonConverters;
namespace Microsoft.MyRpNamespace;
public partial class Model0 {}
```
### Reproduction
1. Use an ARM RP typespec
2. Add the following to tspconfig.yaml
```yml
emit:
- "@typespec/http-server-csharp"
options:
"@typespec/http-server-csharp":
emitter-output-dir: "{project-root}/generated/{emitter-name}"
output-type: all
emit-mocks: none
overwrite: true
```
### Checklist
- [x] Follow our [Code of Conduct](https://github.com/microsoft/typespec/blob/main/CODE_OF_CONDUCT.md)
- [x] Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- [x] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/Microsoft/typespec/discussions).
- [x] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.
Contributor guide
Research direction
Reproduce the issue with an ARM RP TypeSpec project and the emitter settings in tspconfig.yaml. Start by inspecting the @typespec/http-server-csharp emitter output and the warnings from traits.tsp at lines 147, 177, and 206; done means the generated model is no longer empty and the reported anonymous-model warning behavior is addressed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend-api-design, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100