Skip to content

[http-client-js] Improve documentation #6940

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

joheredi
Copy link
Member

Improve code documentation to make it more understandable for AI systems or human developers.

This has been mostly generated by AI and reviewed by me. Appreciate another set of eyes

Copy link
Contributor

github-actions bot commented Apr 10, 2025

All changed packages have been documented.

  • @typespec/http-client-js
Show changes

@typespec/http-client-js - internal ✏️

Add code documentation

@azure-sdk
Copy link
Collaborator

azure-sdk commented Apr 10, 2025

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

return (
<For each={responses.filter((r) => !$.httpResponse.isErrorResponse(r))}>
{({ statusCode, contentType, responseContent, type }) => {
// Extract the body from the response content
Copy link
Member

Choose a reason for hiding this comment

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

Is this also auto generated by AI? how did it know which lines to add and which not?

export function HttpResponses(props: HttpResponsesProps) {
// Handle response by status code and content type
// Obtain and flatten the HTTP responses from the operation, filtering by non-error responses.
Copy link
Member

Choose a reason for hiding this comment

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

Feel like this would be more useful if we could add the typekit description to it?
"Get the responses for the given operation. This function will return an array of responses grouped by status code and content type."

*
* @param type - The type object that must have a `name` property of type `string`.
* @param type - The type object whose name is to be transformed.
Copy link
Member

Choose a reason for hiding this comment

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

is the previous documentation also generated by AI? will it change everytime we use the AI to help us regen the documentation once in a while?
Also, what if the logic has been changed but we forget about improve the documentation?

import { PagingOperation } from "@typespec/compiler";
import { $ } from "@typespec/compiler/experimental/typekit";
import { TypeExpression } from "@typespec/emitter-framework/typescript";

/**
* Extracts and returns the element type of the page items array from a paging operation.
Copy link
Member

Choose a reason for hiding this comment

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

interesting, AI is writing the right stuff here.

@@ -27,9 +55,15 @@ export function PageResponseDeclaration(props: PageResponseProps) {
"firstLink",
"lastLink",
];

// Array to hold validated paging properties extracted from the defined responses.
Copy link
Member

Choose a reason for hiding this comment

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

nit: i may not say validated here, no validation.

Suggested change
// Array to hold validated paging properties extracted from the defined responses.
// Array to hold paging properties extracted from the defined responses.

@@ -1,38 +1,82 @@
/**
* This file defines helper functions and a component to generate TypeScript interface declarations
* for page settings used in HTTP operations. It selectively picks accepted paging properties from a
Copy link
Member

Choose a reason for hiding this comment

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

nit: Page setting declarations used in HTTP operations would lead to misleading.

Suggested change
* for page settings used in HTTP operations. It selectively picks accepted paging properties from a
* This file defines helper functions and a component to generate TypeScript interface declarations
* for page settings given the HTTP operation and paging details. It selectively picks accepted paging properties from a

* needed to send requests and process responses.
*
* @param httpOperation - The HTTP operation to handle.
* @returns A list of generated components and function declarations for the operation.
Copy link
Member

@MaryGao MaryGao Apr 10, 2025

Choose a reason for hiding this comment

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

nit: the return type is not accurate.

Suggested change
* @returns A list of generated components and function declarations for the operation.
* @returns A JSX list element representing paging relevant interfaces and functions.

@@ -49,12 +73,13 @@ export const PaginatedOperationHandler: OperationHandler = {
const operationRefkey = ay.refkey(httpOperation.operation);
const returnType = ay.code`${getPagedAsyncIterableIteratorRefkey()}<${getPageItemTypeName(pagingOperation)},${getPageResponseTypeRefkey(httpOperation)},${getPageSettingsTypeRefkey(httpOperation)}>`;
const clientContextInterfaceRef = getClientcontextDeclarationRef(client);

Copy link
Member

Choose a reason for hiding this comment

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

hah, AI seems talkative‌ in other places, why is it so solient in this method?

operation: HttpOperation;
pagingOperation: PagingOperation;
operation: HttpOperation; // The HTTP operation for which the page response is defined.
pagingOperation: PagingOperation; // The paging operation containing the output definitions.
Copy link
Member

Choose a reason for hiding this comment

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

is this manually added? the format seems different.

@@ -13,42 +18,96 @@ import {
getOperationParameters,
} from "../../operation-parameters.jsx";

/**
* Properties for the HttpRequestSend component.
* @param httpOperation The HTTP operation to be performed.
Copy link
Member

@MaryGao MaryGao Apr 10, 2025

Choose a reason for hiding this comment

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

is the @param correct here? i notice somewhere else is @property any difference?

* The following JSX elements embed code generation nodes:
* - HttpRequest.Url generates the code for constructing the URL based on the HTTP operation.
* - HttpRequestOptions configures the request options (headers, query parameters, body, etc.) for the HTTP call.
* - Return statement c and sends the request using the provided client instance:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* - Return statement c and sends the request using the provided client instance:
* - A return statement to send the request using the provided client instance:

* - HttpRequest.Url generates the code for constructing the URL based on the HTTP operation.
* - HttpRequestOptions configures the request options (headers, query parameters, body, etc.) for the HTTP call.
* - Return statement c and sends the request using the provided client instance:
* - client.pathUnchecked() is used to select the path without additional type-checking.
Copy link
Member

Choose a reason for hiding this comment

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

interesting, AI even knows our pathUnchecked without type checking.

export interface HttpResponseDeserializeProps {
httpOperation: HttpOperation;
responseRefkey: Refkey;
children?: Children;
}

/**
* Component that generates a function declaration for deserializing HTTP responses.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Component that generates a function declaration for deserializing HTTP responses.
* Component that generates a function declaration for deserializing HTTP responses for given paging operation.

const namePolicy = ts.useTSNamePolicy();
const functionName = namePolicy.getName(httpOperation.operation.name + "Deserialize", "function");

const responseRefkey = refkey();
Copy link
Member

Choose a reason for hiding this comment

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

aha, is this added by AI?

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.

4 participants