Skip to content

Support additional properties in non-legacy Modular#2981

Merged
MaryGao merged 33 commits intoAzure:mainfrom
MaryGao:support-additional-properties
Apr 21, 2025
Merged

Support additional properties in non-legacy Modular#2981
MaryGao merged 33 commits intoAzure:mainfrom
MaryGao:support-additional-properties

Conversation

@MaryGao
Copy link
Copy Markdown
Member

@MaryGao MaryGao commented Jan 8, 2025

fixes #2506
fixes #2471
fixes #2400

design doc

We would have two styles:

  • V1: extend Record<T>
  • V2: additionalProperties bag

And we will have following conclusions:

  • We have a feature flag for whether we use V1 or V2 for Modular.
    • legacyAdditionalProperties: true -> V1
    • legacyAdditionalProperties: false -> V2
  • For the new service, we will enable V2 for Modular by default

Any complex ser/deser logic is not in-scope

@qiaozha qiaozha requested a review from Copilot February 19, 2025 07:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

@qiaozha qiaozha added the p0 priority 0 label Mar 12, 2025
@MaryGao MaryGao changed the title Support additional properties Support additional properties in non-legacy Modular Mar 18, 2025
Comment thread packages/typespec-ts/src/modular/emitModels.ts Outdated
@MaryGao MaryGao marked this pull request as ready for review March 18, 2025 07:10
Comment thread packages/typespec-ts/static/static-helpers/serialization/serialize-record.ts Outdated
@MaryGao MaryGao requested a review from qiaozha April 10, 2025 10:08
}

if (type.baseModel) {
return getAdditionalPropertiesType(type.baseModel);
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.

Could you help double check what the additionalProperties type is for model B? I just wonder if tcgc or compiler has already done the union here or is it something emitter should do?

model A {
  ...Record<string>
}

model B extends A {
  ...Record<bytes>
}

Copy link
Copy Markdown
Member Author

@MaryGao MaryGao Apr 15, 2025

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Our generation is correct but typespec would report errors for non-compile code, let's wait their fix and turn on this case.

Comment thread packages/typespec-ts/src/modular/emitModels.ts
default: paramMessage`Please note the header ${"type"} is not serializable.`
}
},
"compatible-additional-properties": {
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.

I didn't see we enable compatibilityMode option in mgmt plane, will it cause problem?

Copy link
Copy Markdown
Member Author

@MaryGao MaryGao Apr 15, 2025

Choose a reason for hiding this comment

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

No problem for us, I searched in current spec there is no any real additional properties cases yet, that means no extends Record<..> or ...Record<...>.

The case we received for ImpactReporting is a fake case where the payload has the extra layer of additionalProperties explicitly - https://github.com/Azure/azure-rest-api-specs/pull/33352/files#r2011565369.

For long term I would prefer to never turn on compatibilityMode if possible, so finally we could remove this logic and only support for new style which better handles the type check stuff.

Comment thread packages/typespec-ts/static/static-helpers/serialization/serialize-record.ts Outdated
@MaryGao MaryGao requested a review from qiaozha April 15, 2025 08:07
@MaryGao MaryGao merged commit d86a484 into Azure:main Apr 21, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p0 priority 0

Projects

None yet

4 participants