Skip to content

[typespec-go] Always document raw JSON fields emitted as []byte - #5073

Open
JiaqiZhang-Dev with Copilot wants to merge 6 commits into
mainfrom
copilot/add-doc-comment-raw-json-fields
Open

[typespec-go] Always document raw JSON fields emitted as []byte#5073
JiaqiZhang-Dev with Copilot wants to merge 6 commits into
mainfrom
copilot/add-doc-comment-raw-json-fields

Conversation

Copilot AI commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Fields typed as unknown are emitted as []byte when rawjson-as-bytes is enabled, expecting the caller to marshal a data structure into the bytes. The emitter noted "The contents of this field are raw JSON." only when a field had no other doc, so any raw-JSON field carrying its own @doc gave no hint that the []byte must contain raw JSON.

Changes

  • src/codegen/core/models.ts: Append the raw-JSON note for every rawJSON-kind field instead of using it as a fallback description. Follows the existing constant-value pattern — appended on a new line when a description already exists, standalone otherwise.
  • test/unittest/scenarios/rawjson-as-bytes.md: Added a documented raw-JSON field to cover the appended-note case.
  • .chronus: fix changelog entry for @azure-tools/typespec-go.

Result

type ContainsRawJSON struct {
	// REQUIRED; The contents of this field are raw JSON.
	Anything1 []byte

	// Additional properties supplied by the caller.
	// The contents of this field are raw JSON.
	Extras []byte
}

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI linked an issue Jul 28, 2026 that may be closed by this pull request
Co-authored-by: JiaqiZhang-Dev <194873822+JiaqiZhang-Dev@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:go Issues for @azure-tools/typespec-go emitter label Jul 28, 2026
…mment

Co-authored-by: JiaqiZhang-Dev <194873822+JiaqiZhang-Dev@users.noreply.github.com>
Copilot AI changed the title [WIP] Add doc comment for fields that are raw JSON [typespec-go] Always document raw JSON fields emitted as []byte Jul 28, 2026
Copilot AI requested a review from JiaqiZhang-Dev July 28, 2026 05:39
@JiaqiZhang-Dev
JiaqiZhang-Dev marked this pull request as ready for review July 28, 2026 05:57
@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @azure-tools/typespec-go
Show changes

@azure-tools/typespec-go - fix ✏️

Always document raw JSON fields (emitted as []byte) so callers know to marshal their data structure into the bytes.

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Go emitter diff

Baseline gh:f4ad548c39ac22e47f1f98e574b774fb61460fbd vs this PR.

No changes to generated output.

Rendered diff: inline on the run summary, or the emitter-diff-go-html artifact.

Informational check (core/eng/emitter-diff); does not block the PR.

@pkg-pr-new

pkg-pr-new Bot commented Jul 28, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@azure-tools/typespec-go@5073

commit: 43587fd

@azure-sdk-automation

Copy link
Copy Markdown
Contributor

You can try these changes here

🛝 Playground 🌐 Website

field.docs.description = "";
}
field.docs.description +=
"This field is raw JSON, marshal your data structure into the []byte.";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we keep the original message please. It's less delta and is "direction agnostic" (un/marshal).

Have we looked at some examples where this is appended to existing docs?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot revert the description to the original version: The contents of this field are raw JSON.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reverted the message back to The contents of this field are raw JSON. in 30d3b13. The scenario snapshot shows it appended after existing docs, e.g.:

// Additional properties supplied by the caller.
// The contents of this field are raw JSON.
Extras []byte

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correction: the revert is in commit aa2ec5f (not the hash I posted above).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@jhendrixMSFT Yes. Across spec repo, only two services set rawjson-as-bytes: true(monitor/data-plane/Ingestion and monitor/data-plane/OperationalInsights), and both emit into the same package azlogs. So azlogs is the one real package that exercises this path today, and it does have raw-JSON []byte fields that already carry their own doc.

tsp: https://github.com/Azure/azure-rest-api-specs/blob/main/specification/monitor/data-plane/OperationalInsights/models.tsp#L43
sdk: https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/monitor/query/azlogs/models.go#L108

The docs seem to indicate that the content is in JSON format, so I also want to confirm the context of this issue: do we always need to emit the comment, even if the field already has one?
image

Co-authored-by: JiaqiZhang-Dev <194873822+JiaqiZhang-Dev@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:go Issues for @azure-tools/typespec-go emitter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add doc comment for fields that are raw JSON

3 participants