Open pshao25 opened 2 months ago
See this swagger as an example, currently the generated TypeSpec will throw error when compile:
Path contains parameter projectName but wasn't found in given parameters
Solution 1: we could see from it that Project might be the parent resource of ProjectDeployment.
Project
ProjectDeployment
@resource("projects") model Project { @key("projectName") name: string; } @resource("deployments") @parentResource(Project) model ProjectDeployment { @key deploymentName: string; } @route("authoring/analyze-text/") interface Test { listDeployments is Azure.Core.ResourceList< ProjectDeployment, Traits >; }
Solution 2: but we actually don't know the parent information from swagger. So we add the projectName directly to Traits.
projectName
@trait model Traits { @traitContext(TraitContext.List) queryParams: { @traitLocation(TraitLocation.Parameters) parameters: { @path projectName: string; }; } };
Both of these two solutions have a problem: it needs to promote the url prefix to interface. If the swagger contains more than one prefixes, we have to generate multiple interfaces, which leads to multiple clients in the end.
See this swagger as an example, currently the generated TypeSpec will throw error when compile:
Solution 1: we could see from it that
Project
might be the parent resource ofProjectDeployment
.Solution 2: but we actually don't know the parent information from swagger. So we add the
projectName
directly to Traits.Both of these two solutions have a problem: it needs to promote the url prefix to interface. If the swagger contains more than one prefixes, we have to generate multiple interfaces, which leads to multiple clients in the end.