Repository navigation
Description
Minimal reproduction
With SwaggerProvider 4.0.0 or 4.1.0 and .NET SDK 10.0.301:
open SwaggerProvider
type ReproApi =
OpenApiClientProvider<"repro.json", SsrfProtection=false>
let client = ReproApi.Client(){
"openapi": "3.0.0",
"info": { "title": "Named object alias reproduction", "version": "1.0.0" },
"paths": {
"/parent": {
"get": {
"operationId": "getParent",
"responses": {
"200": {
"description": "Parent response",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/Parent" }
}
}
}
}
}
}
},
"components": {
"schemas": {
"Parent": {
"oneOf": [
{ "$ref": "#/components/schemas/Parent_Child" }
]
},
"Parent_Child": {
"type": "object",
"required": ["childValue"],
"properties": {
"childValue": { "type": "string" }
}
}
}
}
}The equivalent single-reference anyOf and allOf component aliases fail in the same way.
Version matrix
| SwaggerProvider | Result |
|---|---|
| 4.0.0 | Reproduced |
| 4.1.0 | Reproduced |
Actual behavior
dotnet build fails while emitting the provided assembly:
FS3033: The type provider 'SwaggerProvider.OpenApiClientTypeProvider' reported an error: duplicate entry 'Parent_Child' in type index table
Expected behavior
Parentresolves to the generatedParent_Childobject type.- The
Parentcomponent path is cached as an alias to that type. Parent_Childis added to the generated namespace exactly once.- An operation returning
Parentexposes the properties generated forParent_Child.
Root-cause analysis
DefinitionCompiler.compileSingleRefOrNewObject recognizes that Parent is a single-reference alias, releases the Parent name reservation, and resolves Parent_Child.
At the end of compileBySchema, the unconditional registerNew(tyName, tyType) call for fromByPathCompiler both caches the component path and registers the returned type in the namespace. The returned ProvidedTypeDefinition is the already-generated Parent_Child, so it is registered under both component entries. NamespaceAbstraction.GetProvidedTypes() consequently returns the same provided type more than once, and assembly emission fails with the duplicate type-index entry.
The fix should separate component-path caching from namespace registration for aliases, rather than suppressing, renaming, dropping, or weakening the generated type.
PR #375 did not cover this case. Its regression tests place a single-reference wrapper on an object property that points to a primitive alias. They do not compile a named top-level component that aliases another named object component, so no duplicate ProvidedTypeDefinition is emitted.
Activity
fix: prevent duplicate ProvidedTypeDefinition for named component ali…
github-actions commentedon Jul 28, 2026
🤖 This is an automated response from Repo Assist.
Your root-cause analysis is spot-on. The fix is now in a draft PR — see the PR for details.
Root cause (confirmed):
registerInNsAndInDefwas callingns.RegisterTypeunconditionally, which re-added theParent_ChildProvidedTypeDefinitionto the namespace under the alias name"Parent". SinceReleaseNameReservationhad removed"Parent"fromprovidedTys, the registration hit thefalse, _(no existing slot) branch inRegisterType, inserting the PTD a second time.GetProvidedTypes()then returned the same PTD twice →duplicate entry 'Parent_Child' in type index table.Fix applied: before calling
ns.RegisterType, check via reference equality whether the PTD is already inpathToType.Values. If it is (i.e., this is an alias path), skip namespace registration — only thepathToTypecache entry is added.The same latent issue affected
allOf/anyOfsingle-ref wrappers and the pre-existingPetRef/DogRef/CatReftests (they passed because duplicate PTDs in the list happen to have the same.Name, and the tests only check for presence, not assembly-emit integrity). The fix covers all three variants; 4 new regression tests added.Add this agentic workflows to your repo
To install this agentic workflow, run
lukaszkrzywizna commentedon Jul 28, 2026
[AGENT] This comment was written and published by an AI coding agent on behalf of the contributor.
I opened #479 as an alternative implementation to the automatically generated #478.
Both changes address the duplicate
ProvidedTypeDefinition, but #479 separates the two responsibilities that caused the bug instead of detecting aliases by scanningpathToType.Valueswith reference equality:compileByPathcaches every resolved component path, including alias paths;ProvidedTypeDefinitionto the namespace a second time;#479 also exercises the complete emitted-provider path requested by this issue. Operations return the aliased components, and the tests assert the response CLR type and access the target object's property. Coverage includes
oneOf,anyOf,allOf, equal leaf names in separate generated namespaces, two aliases sharing one object, and an alias chain.Validation completed locally with .NET SDK 10.0.301:
CheckFormat: succeeded;SwaggerProvider.Tests: 552 total, 0 failed/errors, 1 skipped;SwaggerProvider.ProviderTests: 133 total, 0 failed/errors;RunTests:Status: Okin 53.6228 seconds;Stampli.VistaSync.IntegrationTestsproject built against the local provider with 0 errors.PR: #479
[repo-assist] fix: prevent duplicate ProvidedTypeDefinition for named…