feat: basic support for openapi 3.1#109
Merged
Merged
Conversation
mnahkies
added a commit
that referenced
this pull request
Nov 12, 2023
previously, these would never be marked as optional, even if the key they belonged to wasn't `required` this was made evident whilst testing #109 which relies on `oneOf` to handle arrays of `type` this moves that logic up into the AbstractSchemaBuilder, and applies it more predictably, as well as swapping the order such that `nullable` always comes before `optional`
ac7761d to
bddc979
Compare
mnahkies
added a commit
that referenced
this pull request
Nov 12, 2023
previously, these would never be marked as optional, even if the key they belonged to wasn't `required` this was made evident whilst testing #109 which relies on `oneOf` to handle arrays of `type` this moves that logic up into the `AbstractSchemaBuilder`, and applies it more predictably, as well as swapping the order such that `nullable` always comes before `optional` this means that schemas like: ``` schema: type: object properties: enabled: "$ref": "#/components/schemas/actions-enabled" allowed_actions: "$ref": "#/components/schemas/allowed-actions" required: - enabled ``` will correctly mark `allowed_actions` as optional, and schemas like: ``` setup_intent_payment_method_options: description: '' properties: us_bank_account: anyOf: - $ref: >- #/components/schemas/setup_intent_payment_method_options_us_bank_account - $ref: >- #/components/schemas/setup_intent_type_specific_payment_method_options_client title: SetupIntentPaymentMethodOptions type: object ``` correctly mark `us_bank_account` as optional. note: the typescript types were already correct here. the problem wasn't picked up by typescript because were being stricter on the validation and then passing that to a looser type, eg: passing `T` to a `T | undefined` parameter.
this adds basic support for openapi 3.1 definitions, based on the mgiration blog post from openapis.org. the primary change is allowing `null` as a `type`, and that `type` can be an array. the other changes listed relating to file uploads, and `exclusiveMinimum` aren't applicable as these aren't really supported at all yet (#51, #53) there's probably a bunch of other gaps in general JSON schema support, such as the `if` / `else` things mentioned, but there's relatively few examples of complex `3.1.0` definitions to test against. I stumbled across https://github.com/APIs-guru/openapi-directory looking for samples and I've tested these changes against these definitions: - https://github.com/APIs-guru/openapi-directory/blob/dec74da7a6785d5d5b83bc6a4cebc07336d67ec9/APIs/vercel.com/0.0.1/openapi.yaml - https://github.com/APIs-guru/openapi-directory/blob/dec74da7a6785d5d5b83bc6a4cebc07336d67ec9/APIs/discourse.local/latest/openapi.yaml - https://github.com/APIs-guru/openapi-directory/blob/dec74da7a6785d5d5b83bc6a4cebc07336d67ec9/APIs/adyen.com/CheckoutService/70/openapi.yaml It appears to be giving reasonable output - no compile errors at least, and nothing obviously wrong doing a quick scan of output. ref: https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0
bddc979 to
7073d5d
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
this adds basic support for openapi 3.1 definitions, based on the migration blog post from openapis.org.
the primary change is allowing
nullas atype, and thattypecan be an array.the other changes listed relating to file uploads, and
exclusiveMinimumaren't applicable as these aren't really supported at all yet (#51, #53)there's probably a bunch of other gaps in general JSON schema support, such as the
if/elsethings mentioned, but there's relatively few examples of complex3.1.0definitions to test against.I stumbled across https://github.com/APIs-guru/openapi-directory looking for samples and I've tested these changes against these definitions:
It appears to be giving reasonable output - no compile errors at least, and nothing obviously wrong doing a quick scan of output.
ref: https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0