-
Notifications
You must be signed in to change notification settings - Fork 74
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
Anonymous models inline support #2072
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, left a few minor comments. I'm really excited to see this working now 😄
}); | ||
}); | ||
describe("happens as a property in response body", async () => { | ||
it("should map empty anonymous model({}) => Record<string, any> & empty named model(A {}) => Record<string, any>", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would call out for this test case
-
For the anonymous empty model
{}
, we take it asRecord<string, any>
. the benefit is the customers could assign objects with properties but we may take potential breaking risk if the contract is changed to e.g{ a?: string }
-
For named empty model
A {}
I prefer to respect the name and structure in typespec, so the model A would be generated in models.ts and be referred in operations.ts. If customers add more optional properties in it would not cause any breakings.
/cc @joheredi Feel free to share your ideas.
|
||
it("should return non-empty anonymous model({ ... })", async () => { | ||
const tspContent = ` | ||
op read(): { foo?: {bar: string | null}}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please notice if the return type is anonymous the inline type would be duplicated in different places.
export async function _readDeserialize(
result: Read200Response
): Promise<{ foo?: { bar: string | null } }>
export async function read(
context: Client,
options: ReadOptions = { requestOptions: {} }
): Promise<{ foo?: { bar: string | null } }>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wonder if you have added test for the sample generation with anonymous model ?
packages/typespec-test/test/openai_generic/generated/typespec-ts/src/rest/models.ts
Show resolved
Hide resolved
Added here abec42a |
fixes #2067