-
-
Notifications
You must be signed in to change notification settings - Fork 528
Check result
type before using in
operator
#1724
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
Conversation
Thanks @simensol! This fix looks good, but it needs 2 things to be approved:
|
🦋 Changeset detectedLatest commit: c8475bc The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
I really tried to create a test. But coming from Python, I don't really know the basics of writing TypeScript tests. I managed to run the existing test suite, but I didn't manage to write a test of my change. However, I have created the Changeset as requested. |
If you’re not able to provide a test, could you provide a schema you’re using, or implementation where this fails? Without a test it’s not clear what scenario leads to this error, since this doesn’t happen in the existing tests. |
Sure! Here is a minimal schema that raises the error: openapi: 3.0.3
info:
title: Test API
version: 0.1.0
description: Test
paths:
/guardians/:
get:
operationId: guardians_list
security:
- cookieAuth: []
- basicAuth: []
responses:
"200":
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/Guardian"
components:
schemas:
Guardian:
type: object
properties:
children:
type: array
items:
type: string
format: uuid |
Thanks! And I take it you’re using the Node.js API + Further, is it desirable that in those cases, the default transformer just stop executing if the node has been touched (which I think is what your PR changes, which is preferable to erring out but wanted to double-check)? |
You're correct (I think). I have added some transformers to handle the special formats openapiTS(localPath, {
transform(schemaObject) {
if ("format" in schemaObject) {
if (schemaObject.format === "decimal") {
return schemaObject.nullable ? "number | null" : "number"
} else if (schemaObject.format === "uuid") {
return schemaObject.nullable ? "UUID | null" : "UUID"
}
}
}
}).then((response) => {
// This will not validate the UUID, only give a hint to the developer. See
// <https://github.com/Microsoft/TypeScript/issues/6579#issuecomment-218418435> and
// <https://www.reddit.com/r/typescript/comments/bhvd3w/comment/elw3s61/>.
response = astToString(response).replace(
"export interface paths {",
"export type UUID = string\n\nexport interface paths {"
)
fs.writeFileSync(saveApiTypesFilePath, response)
}) |
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.
Thanks for fixing! Will add tests in a followup.
* Check `result` type before using `in` operator * Create serious-days-live.md
Changes
Make sure
result
is an object before using thein
operator. Fixes the following errors when generating a schema: