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

Extension: Generate from TypeSpec does not work with client.tsp as entrypoint file #6062

Open
4 tasks done
swathipil opened this issue Feb 19, 2025 · 5 comments
Open
4 tasks done
Assignees
Labels
bug Something isn't working ide Issues for VS, VSCode, Monaco, etc.

Comments

@swathipil
Copy link
Member

Describe the bug

I've copied over the main.tsp and client.tsp from [this] folder into a test project following these instructions.

I tried to "Generate from TypeSpec" with the client.tsp and Python emitter specified, but it's still using main.tsp as the entrypoint file and the client.tsp changes are not being applied during Python client generation.

tspconfig.yaml:

parameters:
  "service-dir":
    default: "sdk/schemaregistry"
  "dependencies":
    "additionalDirectories": []
    default: ""
emit:
  - "@azure-tools/typespec-autorest"
  - "@typespec/http-client-python"
linter:
  extends:
    - "@azure-tools/typespec-azure-rulesets/data-plane"
options:
  "@azure-tools/typespec-autorest":
    azure-resource-provider-folder: "data-plane"
    emit-lro-options: "none"
    emitter-output-dir: "{project-root}/../"
    output-file: "data-plane/Microsoft.SchemaRegistry/{version-status}/{version}/sc\
      hemaregistry.json"
  "@typespec/http-client-python":
    package-dir: "azure-schemaregistry"
    package-name: "{package-dir}"
    emitter-output-dir: "{project-root}/azure-schemaregistry/_generated/"
    package-version: 1.3.0b4
    generate-packaging-files: false
    flavor: azure
    generate-test: true
    generate-sample: true
  "@azure-tools/typespec-python":
    package-dir: "azure-schemaregistry"
    package-name: "{package-dir}"
    emitter-output-dir: "{project-root}/azure-schemaregistry/_generated/"
    package-version: 1.3.0b4
    generate-packaging-files: false
    flavor: azure
    generate-test: true
    generate-sample: true
  "@azure-tools/typespec-java":
    package-dir: "azure-data-schemaregistry"
    namespace: com.azure.data.schemaregistry
    partial-update: true
    flavor: azure
  "@azure-tools/typespec-ts":
    package-dir: "schema-registry"
    generateMetadata: false
    generateTest: false
    packageDetails:
      name: "@azure/schema-registry"
    flavor: azure
  "@azure-tools/typespec-csharp":
    package-dir: "Azure.Data.SchemaRegistry"
    namespace: "{package-dir}"
    clear-output-folder: true
    model-namespace: true
    flavor: azure

Reproduction

  1. Add the main.tsp, client.tsp, tspconfig.yaml into the project.
  2. Image
  3. Image

I'm not sure if the entrypoint file needs to be set/change elsewhere in the config files. However, I believe it should automatically use the client.tsp file as the entrypoint file/apply those if I'm explicitly right-clicking on that file for generation.

Checklist

@swathipil swathipil added the bug Something isn't working label Feb 19, 2025
@timotheeguerin timotheeguerin added the ide Issues for VS, VSCode, Monaco, etc. label Feb 19, 2025
@RodgeFu
Copy link
Contributor

RodgeFu commented Feb 21, 2025

@timotheeguerin , @allenjzhang , do you have more context about using the client.tsp as entrypoint? I checked our doc but it only mentioned main.tsp as entrypoint.

@timotheeguerin
Copy link
Member

typespec takes whatever input file you give it

tsp compile . // resolve the input file for the current folder which could be main.tsp or what is configured in the package.json if its there


tsp compile client.tsp // compile client.tsp
tsp compile other.tsp // compile other.tsp

if the generation is assumining its always resolving a main.tsp and not building the file that the user asked this is broken then

@chunyu3
Copy link
Contributor

chunyu3 commented Feb 28, 2025

hello @swathipil The default entrypoint file is main.tsp, if the default entrypoint exists in the tsp project folder, Code Generation will generate code from the entrypoint file.

you can set client.tsp as your entrypoine file in package.json

"tspMain": "client.tsp"

@timotheeguerin
Copy link
Member

This is not an good solution. The spec repo has a single package.json that should be touched and hundreds of specs.
Requiring modifying a file as well to do that completely defeats the point of having any IDE experience for his. You would be better of just running the cli.

@chunyu3
Copy link
Contributor

chunyu3 commented Mar 5, 2025

In typespec extension, when customer select a tsp file to generate, there will be two options:

  • Option 1: Generate code from the tsp file selected
  • Option 2: search out the MainEntrypointTspFile( main.tsp by default), and generate code from the mainEntrypointTspFile

Option 1 more convenience, but as for a tsp project, the generated code may not acceptable if the selected file is not mainEntrypointTspFile.

typespec extension choose Option 2, make sure every round of generation generate code for the whole project.

In spec repo, it may not be suitable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ide Issues for VS, VSCode, Monaco, etc.
Projects
None yet
Development

No branches or pull requests

4 participants