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

server codegen documentation #6265

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

server codegen documentation #6265

wants to merge 1 commit into from

Conversation

mario-guerra
Copy link
Member

Putting this up for review only, do not commit. This is a draft and it still needs work.

@mario-guerra
Copy link
Member Author

hi @josefree, I need your help with this codegen documentation, can you provide screenshots for the VS Code portions in the doc?

@mario-guerra mario-guerra requested a review from josefree March 4, 2025 22:02
@azure-sdk
Copy link
Collaborator

No changes needing a change description found.

@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@allenjzhang
Copy link
Member

There will be changes around how server scaffolding gets streamlined. @markcowl

Let's keep this one open and see if Mark had any of his doc and then reconcile them.


## Prerequisites

Before you begin, make sure you have the following installed:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the introduction of the standalone cli feel like it might be better of to redirect the initial setup to the install doc

Before you begin, make sure you have the following installed:

* **Node.js:** (version 20.x or later). Download from [https://nodejs.org/](https://nodejs.org/)
* **npm:** (version 6.x or later). Typically included with Node.js.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we say 7+ in the install docs


* **Node.js:** (version 20.x or later). Download from [https://nodejs.org/](https://nodejs.org/)
* **npm:** (version 6.x or later). Typically included with Node.js.
* **TypeSpec compiler:** Install the latest `@next` version globally using:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why next?


4. **Project structure:** After compiling, you will typically see the following structure:

```text
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See startlight filetree component to have a better presentation here https://starlight.astro.build/components/file-tree/, we use it in a few other places in the codebase too

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for all the other dir examples

@@ -0,0 +1,375 @@
# Generating server stubs with TypeSpec: a user guide
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be reformulated as api first as this also mention clients

┃ ┃ ┃ ┣ ... (other operation interface files)
```

* **`Controllers`**: These folders contain *base classes* for your API controllers (e.g., `CommentOpsOperationsControllerBase.cs`, `TodoItemsOperationsControllerBase.cs`). These base classes define the API endpoints and handle basic request processing. **You will need to create concrete controller classes that inherit from these base classes and implement your business logic.**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is out of date - there are no more base controllers


* **`Controllers`**: These folders contain *base classes* for your API controllers (e.g., `CommentOpsOperationsControllerBase.cs`, `TodoItemsOperationsControllerBase.cs`). These base classes define the API endpoints and handle basic request processing. **You will need to create concrete controller classes that inherit from these base classes and implement your business logic.**

* **`lib`**: This directory contains utility classes such as custom attributes used for server side validation to ensure input data adhere to the spec.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* **`lib`**: This directory contains utility classes such as custom attributes used for server side validation to ensure input data adhere to the spec.
* **`lib`**: This directory contains helper classes used in generated code, such as custom attributes used for server-side validation to ensure input data adhere to the spec.


* **`Models`**: These files define the data models (also known as Data Transfer Objects or DTOs) used in your API (e.g., `TodoItem.cs`, `Project.cs`). These classes represent the structure of the data being exchanged between the client and the server.

* **`Operations`**: These files defines the service interface used for API operations.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* **`Operations`**: These files defines the service interface used for API operations.
* **`Operations`**: These files defines the service interface used for API operations. You will implement these interfaces to execute the business logic for each operation.


## Cli: running the project and adding necessary code:

Now that you have the base controller, models and service interface generated, the next step is to implement the code with a service scaffolding and business logic for a runnable server. Please follow the instruction below:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has changed quite a bit

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markcowl where/how can I get the latest info on how it works?

* `[Placeholder: Screenshot showing "Create TypeSpec Project" in the VSCode Explorer sidebar]`
* Select a project root folder.
* Provide the required inputs via Quick Picks, similar to using `tsp init` on the command line.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May use this gif - vscode_project_scaffolding.gif

* Provide the required inputs via Quick Picks, similar to using `tsp init` on the command line.

3. **Define your api:** Write your API specification in a `.tsp` file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May mention “code faster with IntelliSense and Auto-completion support”. vscode.gif

3. **Define your api:** Write your API specification in a `.tsp` file.

4. **Generate the server stub:**
* Right-click on a `.tsp` file to open the context menu.
Copy link
Member

@josefree josefree Mar 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to introduce TypeSpec command here. Launch TypeSpec command with ">TypeSpec: Emit from TypeSpec" from Command Palette.

#6342 the gif is here. when it is merged. it can be used with ![vscode.gif] (https://raw.githubusercontent.com/microsoft/typespec/main/website/src/content/docs/docs/images/vscode_tsp_to_server_stubs_generation.gif)"

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

Successfully merging this pull request may close these issues.

7 participants