-
Notifications
You must be signed in to change notification settings - Fork 0
Fix OpenAPI 3.0 sign schema and setup payload error reporting #3
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,12 @@ class HttpError extends Error { | |
| } | ||
| } | ||
|
|
||
| class InvalidPayloadError extends Error { | ||
| constructor(message: string) { | ||
| super(message); | ||
| } | ||
| } | ||
|
|
||
| const FETCH_TIMEOUT_MS = 30_000; | ||
|
|
||
| function isTimeoutError(e: unknown): e is Error { | ||
|
|
@@ -114,7 +120,9 @@ export async function runSetup(argv: string[]): Promise<void> { | |
| } | ||
| const payload = await res.json(); | ||
| if (!isCreateWorkspacePayload(payload)) { | ||
| throw new Error("Invalid workspace creation response"); | ||
| throw new InvalidPayloadError( | ||
| "POST /v1/workspaces returned an invalid payload.", | ||
| ); | ||
|
Comment on lines
+123
to
+125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-JSON success payloads are still reported as “network error.”
💡 Suggested fix- const payload = await res.json();
+ let payload: unknown;
+ try {
+ payload = await res.json();
+ } catch {
+ throw new InvalidPayloadError(
+ "POST /v1/workspaces returned a non-JSON payload.",
+ );
+ }
if (!isCreateWorkspacePayload(payload)) {
throw new InvalidPayloadError(
"POST /v1/workspaces returned an invalid payload.",
);
}🤖 Prompt for AI Agents |
||
| } | ||
| created = payload; | ||
| console.log(c.green + "✓" + c.reset); | ||
|
|
@@ -128,6 +136,8 @@ export async function runSetup(argv: string[]): Promise<void> { | |
| console.error( | ||
| fail(`POST /v1/workspaces timed out after ${FETCH_TIMEOUT_MS}ms.`), | ||
| ); | ||
| } else if (e instanceof InvalidPayloadError) { | ||
| console.error(fail(e.message)); | ||
| } else { | ||
| console.error( | ||
| fail( | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧩 Analysis chain
🌐 Web query:
OpenAPI 3.0.x nullable true enum specification null validation💡 Result:
In OpenAPI 3.0.x,
nullable: truemeansnullis added to the allowed type, but all other schema constraints still apply—and those constraints can still rejectnull(the spec explicitly calls this out). So if you also have anenum, validation will only pass for values in thatenum; thereforenullmust be explicitly present in theenumlist fornullto validate. [1][2]Example (OAS 3.0.x):
Many linters/validators enforce this behavior (nullable + enum ⇒ enum must contain
null). [2][3]Sources: OpenAPI Spec v3.0.3 on
nullablesemantics and constraints [1]; Swagger docs on “Nullable enums” [2]; vacuum linter rulenullable-enum-contains-null[3].nullable: truewithenum: [false]will rejectnullvalues.In OpenAPI 3.0.x, when both
nullable: trueandenumare specified,nullmust be explicitly included in the enum array for null validation to pass. The current definition will reject null despite the nullable constraint, causing validator and client-generator mismatches.Add
nullto the enum:Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents