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

Use value syntax for @header, and add explode option #6130

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

Conversation

chrisradek
Copy link
Member

@chrisradek chrisradek commented Feb 24, 2025

Fixes #4114

One question is whether to add a new http-specs test for the explode scenarios as part of this PR. Currently there aren't any specs for headers defined as objects - I presume since swagger doesn't allow it.

Related typespec-azure PR: Azure/typespec-azure#2257

@azure-sdk
Copy link
Collaborator

azure-sdk commented Feb 24, 2025

All changed packages have been documented.

  • @typespec/http-specs
  • @typespec/http
  • @typespec/openapi3
Show changes

@typespec/http - feature ✏️

Updates @header decorator to accept values and adds the explode option.

@typespec/http-specs - internal ✏️

Updates http @header usage to value syntax

@typespec/openapi3 - feature ✏️

updates openapi3 to respect @headers explode option and use value syntax

@@ -67,37 +66,37 @@ export const namespace = "TypeSpec.Http";
export const $header: HeaderDecorator = (
context: DecoratorContext,
entity: ModelProperty,
headerNameOrOptions?: StringLiteral | Type,
headerNameOrOptions,
) => {
const options: HeaderFieldOptions = {
type: "header",
name: entity.name.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(),
};
if (headerNameOrOptions) {
Copy link
Member

Choose a reason for hiding this comment

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

i think we also need to deprecate format

@azure-sdk
Copy link
Collaborator

azure-sdk commented Feb 24, 2025

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@header({
format: "csv",
})
@header(#{ format: "csv" })
Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't look like this is actually used in any Azure specs. @header isn't called with options in any typespec file in the azure specs repo. I also wrote a regex to look for any header parameter of type array or object, and came up with 0 hits in the azure specs repo.

What we want is for csv to be the default behavior here, but I'm not sure what work is needed on our emitters to make that the case yet.

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.

Update header decorator to be consistent with new query and path
3 participants