-
-
Notifications
You must be signed in to change notification settings - Fork 539
Feat: Add support for pattern properties #2288
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
👷 Deploy request for openapi-ts pending review.Visit the deploys page to approve it
|
🦋 Changeset detectedLatest commit: b299279 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
@gzm0 yes please feel free to review! The round-robin assignment was only meant to divide the PR reviews among us evenly, but always feel free to jump in and stamp a PR if you have context/time |
addlTypes.push(transformSchemaObject(v, options)); | ||
} | ||
} | ||
const addlType = addlTypes.length === 0 ? UNKNOWN : tsUnion(addlTypes); |
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'm afraid the logic here is not correct: We need to add UNKNOWN
iff additionalProperties: true
(or it is unset and options.ctx.additionalProperties
is set).
So for example, for the following, we should generate string | unknown
:
type: object
additionalProperties: true
patternProperties:
".*":
type: string
IIUC the current code would only generate string
.
(FWIW: I realize this was wrong in my PR as well).
given: { type: "object", patternProperties: {} }, | ||
want: `{ | ||
[key: string]: unknown; | ||
}`, |
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 don't think this test case is correct. I think the result here should be the empty object.
IIUC openapi-typescript works under the base assumption that the default for additionalProperties
is false (which is not actually the JSON schema default). So in this object type, no keys are allowed:
The additionalProperties keyword is used to control the handling of extra stuff, that is, properties whose names are not listed in the properties keyword or match any of the regular expressions in the patternProperties keyword. By default any additional properties are allowed.
From: https://json-schema.org/understanding-json-schema/reference/object#additionalproperties
@duncanbeevers maybe you can double check my understanding of the --additional-properties
flag?
}, | ||
], | ||
[ | ||
"patternProperties > additional and patterns", |
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.
Could you add test cases with:
additionalProperties: true
?options.additionalProperties = true
?
Changes
Add support for patternProperties in addition to additionalProperties (#754).
Building on the work of @gzm0 in 1901 by adding tests
Ran the command
pnpm run update:examples
which created 129 new files and updated 69, none of which seemed related to this change. Let me know if you wan't me to do it anyways.How to Review
Refer to comments in original PR 1901
Validate tests are satisfactory
Checklist
docs/
updated (if necessary)pnpm run update:examples
run (only applicable for openapi-typescript)