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

[WIP] Merge JavaScript Server Generator to Main #3231

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

witemple-msft
Copy link
Member

This work-in-progress PR tracks merging the JavaScript server code generator to the TypeSpec repository.

The JavaScript server code generator creates HTTP bindings for TypeSpec HTTP services and exposes them for binding either to the Node.js http server directly, or to an Express.js app as middleware.

This is a large PR with some issues to be worked out before it can be merged:

  • Confirm naming. I've named this according to the specification http-server-javascript, but this emitter is just capable of emitting an HTTP server. It can also emit TypeScript models alone, and HTTP is enabled as an optional feature of the emitter.
  • This emitter has many cases of broken functionality and TODO comments that should be either fixed or made issues before merging, and we should document the instability of this experimental emitter until it's ready.
  • There are currently no tests, so I'll need to set up a testing harness.
  • There are a few utilities that are useful enough to consider moving into the core library, such as the ReCase system for changing strings between naming cases, the HTTP route tree, and maybe the OutputDecisionTree if it were more full-featured.

Closes #3215

@witemple-msft witemple-msft added this to the [2024] May milestone Apr 24, 2024
@witemple-msft witemple-msft self-assigned this Apr 24, 2024
@azure-sdk
Copy link
Collaborator

azure-sdk commented Apr 24, 2024

❌ There is undocummented changes. Run chronus add to add a changeset or click here.

The following packages have changes but are not documented.

  • @typespec/http-server-javascript
Show changes

@azure-sdk
Copy link
Collaborator

You can try these changes at https://cadlplayground.z22.web.core.windows.net/prs/3231/

Check the website changes at https://tspwebsitepr.z22.web.core.windows.net/prs/3231/

Copy link
Member

Choose a reason for hiding this comment

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

make sure to update the tsconfig.ws.json so pnpm watch build this too

const argumentType = type.indexer.value;

if (requiresJsonSerialization(ctx, argumentType)) {
return `${expr}.map((item) => ${transposeExpressionToJson(ctx, argumentType, "item", module)})`;

Check warning

Code scanning / CodeQL

Improper code sanitization Medium

Code construction depends on an
improperly sanitized value
.
Code construction depends on an
improperly sanitized value
.
Comment on lines +160 to +165
return `Object.fromEntries(Object.entries(${expr}).map(([key, value]) => [String(key), ${transposeExpressionToJson(
ctx,
argumentType,
"value",
module
)}]))`;

Check warning

Code scanning / CodeQL

Improper code sanitization Medium

Code construction depends on an
improperly sanitized value
.
Code construction depends on an
improperly sanitized value
.
const argumentType = type.indexer.value;

if (requiresJsonSerialization(ctx, argumentType)) {
return `${expr}.map((item) => ${transposeExpressionFromJson(ctx, argumentType, "item", module)})`;

Check warning

Code scanning / CodeQL

Improper code sanitization Medium

Code construction depends on an
improperly sanitized value
.
Code construction depends on an
improperly sanitized value
.
Comment on lines +290 to +295
return `Object.fromEntries(Object.entries(${expr}).map(([key, value]) => [key, ${transposeExpressionFromJson(
ctx,
argumentType,
"value",
module
)}]))`;

Check warning

Code scanning / CodeQL

Improper code sanitization Medium

Code construction depends on an
improperly sanitized value
.
Code construction depends on an
improperly sanitized value
.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[codegen] Merge JavaScript HTTP server code generator to main
6 participants