[typespec-go] Always document raw JSON fields emitted as []byte - #5073
[typespec-go] Always document raw JSON fields emitted as []byte#5073JiaqiZhang-Dev with Copilot wants to merge 6 commits into
Conversation
|
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. |
Co-authored-by: JiaqiZhang-Dev <194873822+JiaqiZhang-Dev@users.noreply.github.com>
…mment Co-authored-by: JiaqiZhang-Dev <194873822+JiaqiZhang-Dev@users.noreply.github.com>
|
All changed packages have been documented.
Show changes
|
Go emitter diffBaseline 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. |
commit: |
|
You can try these changes here
|
| field.docs.description = ""; | ||
| } | ||
| field.docs.description += | ||
| "This field is raw JSON, marshal your data structure into the []byte."; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
@copilot revert the description to the original version: The contents of this field are raw JSON.
There was a problem hiding this comment.
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 []byteThere was a problem hiding this comment.
Correction: the revert is in commit aa2ec5f (not the hash I posted above).
There was a problem hiding this comment.
@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?

Co-authored-by: JiaqiZhang-Dev <194873822+JiaqiZhang-Dev@users.noreply.github.com>
Fields typed as
unknownare emitted as[]bytewhenrawjson-as-bytesis 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@docgave no hint that the[]bytemust contain raw JSON.Changes
src/codegen/core/models.ts: Append the raw-JSON note for everyrawJSON-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:fixchangelog entry for@azure-tools/typespec-go.Result