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

multipart api design (DO NOT MERGE) #987

Closed
wants to merge 12 commits into from
Closed

Conversation

msyyc
Copy link
Member

@msyyc msyyc commented Jun 12, 2024

@microsoft-github-policy-service microsoft-github-policy-service bot added the lib:tcgc Issues for @azure-tools/typespec-client-generator-core library label Jun 12, 2024
@azure-sdk
Copy link
Collaborator

No changes needing a change description found.

@azure-sdk
Copy link
Collaborator

@weidongxu-microsoft
Copy link
Member

I don't have major issue with the design.

1. Model format

```
op upload(
Copy link
Member

@chunyu3 chunyu3 Jun 17, 2024

Choose a reason for hiding this comment

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

Will We not support previous define with @body as following?

op upload(@header `content-type`: "mulitpart/form-data",
@body body: {
   fileName: string,
   headShots: bytes[]
}

Copy link
Member Author

@msyyc msyyc Jun 17, 2024

Choose a reason for hiding this comment

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

For now typespec still supports this format, so TCGC should still support it I think. After all language emitters support httpPart, we may be able to consider whether disable this format.

Copy link
Member

Choose a reason for hiding this comment

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

httpPart is for advanced scenario, we are not planning to remove the @body format. Emitter should not care though, it should be transporte for them, they just ask TCGC for the multipart information

isFilePart: boolean; // whether this part is for file
multi: boolean; // whether this part is multi in request payload
headers: HeaderProperty[]; // relates to custom header
filename?: SdkModelPropertyTypeBase;
Copy link
Member

Choose a reason for hiding this comment

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

filename and contentType is meta-data of file property, Itself is not model property. So maybe we shall not define it as SdkModelPropertyTypeBase?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is TCGC interface which has wrapped original http type and I will make sure it contain all info that language emitters may need.

@msyyc msyyc requested a review from chunyu3 June 17, 2024 07:53

```typescript
exprot interface multipartOptionsType {
isNameDefined: boolean; // whether name is defined in Typespec. For multipart/mixed, name may not be defined for some parts
Copy link
Member

Choose a reason for hiding this comment

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

Why not a string field that may be undefined ?

Copy link
Member Author

@msyyc msyyc Jun 18, 2024

Choose a reason for hiding this comment

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

SdkModelPropertyTypeBase already has required property name. If isNamedDefined is true, emitter shall use name; if false, it means typespec doesn't define name and emitter shall not use the name.
NIT: in Typescript, it is impossible to override the property "name" of base interface to "optional"

@msyyc msyyc requested a review from lmazuel June 18, 2024 05:40
@tadelesh tadelesh removed the lib:tcgc Issues for @azure-tools/typespec-client-generator-core library label Jun 26, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the lib:tcgc Issues for @azure-tools/typespec-client-generator-core library label Jun 26, 2024
msyyc added a commit that referenced this pull request Jul 24, 2024
- fixes part of #960
- Pending on microsoft/typespec#3676

Context: 
Typespec supports 3 kinds of format to define multipart:
1. common
```

op upload(
  @Header `content-type`: "multipart/form-data",
  @Body body: {
    basic: string,
    headShots: bytes[],
  }
): void;
```

2. advanced model format
```
op upload(
  @Header `content-type`: "multipart/form-data",
  @multipartBody body: {
    fullName: HttpPart<string>,
    headShots: HttpPart<bytes[]>
  }
): void;
```

3. advanced array format
```
op upload(
  @Header `content-type`: "multipart/form-data",
  @multipartBody body: [
    // single
    HttpPart<string, #{ name: "fullName" }>,
    HttpPart<bytes[], #{ name: "headShots" }>,
  ]
): void;
```
- This PR is implementation for API design
#987, mainly for 1 and 2
format. Format 3 will be implemented in another PR.
@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 📚 Next docs

@msyyc msyyc closed this Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib:tcgc Issues for @azure-tools/typespec-client-generator-core library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants