Skip to content

Commit

Permalink
Allow non form data model (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
iscai-msft authored Jan 31, 2024
1 parent b53e3dd commit 1f1864a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/beige-geese-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@azure-tools/typespec-client-generator-core": patch
---

fix incorrect linter error for models not directly used in multipart operations
2 changes: 1 addition & 1 deletion packages/typespec-client-generator-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ export function getSdkModel(context: SdkContext, type: Model, operation?: Operat
: false;
if (sdkType) {
updateModelsMap(context, type, sdkType, operation);
if (isFormDataType !== sdkType.isFormDataType) {
if (httpOperation && isFormDataType !== sdkType.isFormDataType) {
// This means we have a model that is used both for formdata input and for regular body input
reportDiagnostic(context.program, {
code: "conflicting-multipart-model-usage",
Expand Down
24 changes: 24 additions & 0 deletions packages/typespec-client-generator-core/test/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2060,6 +2060,30 @@ describe("typespec-client-generator-core: types", () => {
strictEqual(modelB.properties.length, 1);
strictEqual(modelB.properties[0].type.kind, "bytes");
});

it("multipart with non-formdata model property", async function () {
await runner.compileWithBuiltInService(
`
model Address {
city: string;
}
model AddressFirstAppearance {
address: Address;
}
@usage(Usage.input | Usage.output)
@access(Access.public)
model AddressSecondAppearance {
address: Address;
}
@put op multipartOne(@header contentType: "multipart/form-data", @body body: AddressFirstAppearance): void;
`
);
const models = Array.from(getAllModels(runner.context));
strictEqual(models.length, 3);
});
});
describe("SdkTupleType", () => {
it("model with tupled properties", async function () {
Expand Down

0 comments on commit 1f1864a

Please sign in to comment.