-
Notifications
You must be signed in to change notification settings - Fork 283
Fix invalid OpenAPI schema generation for models extending Array #7535
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: chrisradek <14189820+chrisradek@users.noreply.github.com>
required: this.#requiredModelProperties(model, visibility), | ||
properties: this.emitter.emitModelProperties(model), | ||
}); | ||
|
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.
@copilot, we believe this could be simplified.
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.
Simplified the logic by eliminating code duplication. The array extension check and element type extraction are now combined, and I use a ternary operator to create the appropriate schema directly instead of having separate if/else blocks with redundant object schema creation. Commit 1e5abdd.
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.
Never mind, go back to the original commit.
Co-authored-by: richardpark-msft <51494936+richardpark-msft@users.noreply.github.com>
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
When a TypeSpec model extends an Array, the generated OpenAPI schema was invalid because it contained both
type: "object"
andallOf: [{ type: "array", ... }]
. This creates a contradictory schema that violates the OpenAPI specification.Before (Invalid):
Generated:
After (Valid):
Generated:
Solution:
Modified
modelDeclaration
inschema-emitter.ts
to detect when a model extends an array type usingisArrayModelType
. In such cases:allOf
for array extensionsThis ensures that
model A extends Array<T> {}
andmodel A is Array<T> {}
generate identical, valid schemas.Tests Added:
All existing tests pass, confirming no regression in normal model inheritance or array handling.
Fixes #7519.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
http://168.63.129.16:80/machine/
/usr/bin/python3 -u bin/WALinuxAgent-2.13.1.1-py3.9.egg -collect-logs
(http block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.