Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

tsp, TCGC adoption, Handle optional content-type #2930

Open
1 of 3 tasks
Tracked by #2931
haolingdong-msft opened this issue Aug 21, 2024 · 2 comments
Open
1 of 3 tasks
Tracked by #2931

tsp, TCGC adoption, Handle optional content-type #2930

haolingdong-msft opened this issue Aug 21, 2024 · 2 comments
Assignees

Comments

@haolingdong-msft
Copy link
Member

haolingdong-msft commented Aug 21, 2024

Will need to modify codegen to support adding the javadoc to let user input content-type.
Link #2861 (comment)

Depends on TCGC issue: Azure/typespec-azure#1259

Currently in codegen we get content types from requests.protocol.http.mediaTypes. Not from the values of contentType constant.
We need to pay attention to is single optional content type and multiple optional content types cases.

model ImageRequest {
  @body body?: bytes;
  @header contentType?: "image/png";
}
  @post
  op upload(...ImageRequest): void;
model ImageRequest {
  @body body?: bytes;
  @header contentType?: "image/png" | "image/jpeg";
}
  @post
  op upload(...ImageRequest): void;

Tasks

TCGC dependency

  1. lib:tcgc
    haolingdong-msft
@weidongxu-microsoft
Copy link
Member

weidongxu-microsoft commented Aug 21, 2024

In swagger, if body is optional, it can still specify the media type via produces keyword (not content-type header parameter).

Not sure how typespec does this, e.g.

model ImageRequest {
  @body body?: bytes;
  @header contentType?: "image/png" | "image/jpeg";
}

@post
op upload(...ImageRequest): void;

and what TCGC should give.

@haolingdong-msft
Copy link
Member Author

haolingdong-msft commented Aug 22, 2024

In swagger, if body is optional, it can still specify the media type via produces keyword (not content-type header parameter).

Not sure how typespec does this, e.g.

model ImageRequest {
  @body body?: bytes;
  @header contentType?: "image/png" | "image/jpeg";
}

@post
op upload(...ImageRequest): void;

and what TCGC should give.

codegen should return optional content type whose value is ["image/png", "image/jpeg"]

Current behavior for optional content type:

  1. content type is single
model ImageRequest {
  @body body?: bytes;
  @header contentType?: "image/png";
}

@post
op upload(...ImageRequest): void;

output code looks good:
image

  1. content type is multiple
model ImageRequest {
  @body body?: bytes;
  @header contentType?: "image/png" | "image/jpeg";
}

@post
op upload(...ImageRequest): void;

output code does not suggested allowed values for content-type
image

So the current handling for multiple content type will need enhancement.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants