Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Express resource hierarchy #4955

Open
Tracked by #4947
pshao25 opened this issue Apr 22, 2024 · 0 comments
Open
Tracked by #4947

Express resource hierarchy #4955

pshao25 opened this issue Apr 22, 2024 · 0 comments

Comments

@pshao25
Copy link
Member

pshao25 commented Apr 22, 2024

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.

@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.

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant