Description
In our generator, we have a post processor to trim unused models. When it does this, it will also remove the corresponding entry in the model factory.
For instance, if we have a model:
namespace Something;
public partial class Foo {}
it will have an entry in model factory:
using Something;
public static partial class ModelFactory
{
public static Foo Foo() {}
}
When the processor removes the entry, it does not clean up its using statements. If the removed model is the only model in that namespace, we get a compilation error about - the namespace does not exist.
using Something; // this will have compilation errors because the only model exists in this namespace has been deleted therefore in the assembly we do not really have this namespace.
public static partial class ModelFactory
{
// entries for other existing models
}
This issue actually exists before we have the "namespace is namespace" feature, but since everyone is in the same namespace, when we remove one model, that namespace still exists. When we have the "namespace is namespace" feature, we have more possibilities when "this namespace only has one model". Especially for those cases that the namespace comes from a template defined in a place like "Typespec.Http`