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

Add HTTP language support #5568

Open
4 tasks
koros opened this issue Oct 9, 2024 · 8 comments
Open
4 tasks

Add HTTP language support #5568

koros opened this issue Oct 9, 2024 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@koros
Copy link
Contributor

koros commented Oct 9, 2024

Add HTTP as a supported language for snippet generation.

Task List

  • Adapt the generated RequestBuilder class to produce .http snippet files.
  • Exclude unnecessary generated code not used by HTTP snippets, such as Models and Utility classes.
  • Serialize models into JSON to populate the RequestBody object for POST operations, handling edge cases like inheritance and union classes.
  • Generate a settings.json file — brainstorm to define its content and determine the source of this information.
@koros koros added the status:waiting-for-triage An issue that is yet to be reviewed or assigned label Oct 9, 2024
@koros koros self-assigned this Oct 9, 2024
@koros koros added this to Kiota Oct 9, 2024
@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota Oct 9, 2024
@koros koros moved this from Needs Triage 🔍 to In Progress 🚧 in Kiota Oct 9, 2024
@koros koros added enhancement New feature or request and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Oct 9, 2024
@koros koros changed the title Add HTTP as one of the languages Add HTTP language support Oct 9, 2024
@koros
Copy link
Contributor Author

koros commented Oct 15, 2024

Overview

This project builds upon the existing logic, which generates a request builder for each path segment. The goal is to enhance the current structure by making a few modifications to generate:

  • URL Templates for each path
  • Supported HTTP operations (GET, POST, PATCH, etc.)
  • A Request Body placeholder, for example:
    Content-Type: application/json
    
    {
      "userId": 0,
      "id": 0,
      "title": "string",
      "body": "string"
    }

Approach

To achieve this, follow these steps:

  1. Identify RequestBuilder Classes

    • Select all classes of type CodeClassKind.RequestBuilder.
  2. Extract URL Templates and HTTP Operations

    • From each class's InnerChildElements property:
      • Extract the URLTemplate by selecting the CodeProperty of type CodePropertyKind.UrlTemplate.
      • Extract supported HTTP operations by selecting all Kiota.Builder.CodeDOM.CodeElement elements of type CodeMethod whose kind is CodeMethodKind.RequestExecutor.
  3. Map HTTP Methods and Request Body

The following table summarizes how to map each method:

Property Mapping
Name Maps to HTTP operation in the snippet file (e.g., GET, POST, PATCH)
RequestBody If a parameter of kind CodeParameterKind.RequestBody exists, map it to the request body
  1. Generate Request Body Placeholders
    • If the request body parameter is present, construct the placeholder JSON by selecting all properties of kind CodePropertyKind.Custom from the Type.TypeDefinition of the parameter.

The following table explains how to map each property in the request body:

Property Mapping
Name Maps to the field name (e.g., postTitle)
Type.Name Maps to the field type (e.g., string, number, boolean)
  1. Extract Query Parameters
    To extract query parameters, follow these steps:

    • Select all classes of kind CodeClassKind.QueryParameters. These classes contain information about the query parameters for each request.
    • From each class's InnerChildElements property, select all properties of kind CodePropertyKind.QueryParameter.

    Once you've accessed these properties, use the following mapping to handle query parameters:

    Property Mapping
    Name Maps to the query parameter name (e.g., userId, filter)

    Additionally, to extract path parameters from the request URL (if present), select the properties of kind CodePropertyKind.PathParameters.

@calebkiage
Copy link
Contributor

This is a great start, could you add information about the mapping between parameters and http snippet variables? I think we also wanted to map descriptions

@koros
Copy link
Contributor Author

koros commented Oct 15, 2024

I'm unsure whether we will be using variables. @darrelmiller, could you please confirm? From our call, I recall you mentioning that we should remove the double curly braces, which suggests users will input the actual values directly. Based on that, my understanding is that the URLs will resemble what's in the documentation, such as:

GET https://graph.microsoft.com/v1.0/directory/deletedItems/{object-id}

@maisarissi
Copy link
Contributor

I have added a comment here: #5543 (comment) that I believe we should take into consideration when http is the language.

@sebastienlevert
Copy link
Contributor

sebastienlevert commented Oct 15, 2024

We need variables when required. Else, we only use a comment that "hints" the URI template so devs can play around. Please refer to #5543. Also adding @baywet to this thread for validation of the design.

@petrhollayms
Copy link
Contributor

@calebkiage is working with Koros now, so looking forward for his review first :-)

@calebkiage
Copy link
Contributor

My remarks:

  1. Will a single request builder map to 1 http file? I assume yes? If not, maybe we should add a mapping of the file and folder structure as well?
  2. In the table defined in section 3. Map HTTP Methods and Request Body, where will you get the Name value from? I'm assuming the CodeMethod?
  3. Is there a way to make it easier for consumers of the snippets to set the values of the body? Imagine if we have many fields in the object. This may be post-mvp. cc: @maisarissi

@koros
Copy link
Contributor Author

koros commented Oct 15, 2024

@calebkiage

  1. The mapping between snippets and the request builder is already 1:1, so based on the current logic, no further modifications are required.
  2. Yes, the properties are derived from the selected method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In Progress 🚧
Development

No branches or pull requests

5 participants