Skip to content

Add support for specifying JSON schema dialects (fixes #202) #401

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ayushshrivastv
Copy link
Contributor

@ayushshrivastv ayushshrivastv commented Mar 11, 2025

This pull request adds support for specifying JSON Schema dialects in OpenAPI documents, as per issue #202. Now, OpenAPI documents can declare JSON Schema dialects at both the document root and individual schema levels. You can use the jsonSchemaDialect and $schema keywords, respectively.

The root document level changes in OpenAPI.swift
The schema level changes in JSONSchema.swift

The changes accurately implement the ability to specify JSON schema dialects at both

Document level (via jsonSchemaDialect)
Individual schema level (via schemaDialect)

Both implementations use

URL type for storing the dialect.
Optionally, include additional properties.
Use “$schema” as the coding key.
Ensure support for these properties in the corresponding initializers.

Add support for specifying JSON Schema dialects at both document root and schema levels.
This allows OpenAPI documents to declare which JSON Schema dialect they use via the
 keyword.

Add jsonSchemaDialect property to Document struct
Add schemaDialect property to JSONSchema.CoreContext
Add  coding key for encoding/decoding

Resolves mattpolzin#202
@ayushshrivastv
Copy link
Contributor Author

ayushshrivastv commented Mar 11, 2025

There might be a few minor flaws or edge cases that could arise while running it, I’d be happy to dig deeper and help improve it further!

@mattpolzin mattpolzin self-requested a review March 14, 2025 22:07
@ayushshrivastv
Copy link
Contributor Author

ayushshrivastv commented Mar 18, 2025

In the meantime, while I’m familiarizing myself with the codebase, I’ve discovered a more efficient way to add the JSON schema dialect. I plan to submit another commit for this improvement. Additionally, I’m seeking a more efficient way to structure and write the code.

Thank you!

@mattpolzin
Copy link
Owner

This PR is going to need a bit of attention. I see you've added OpenAPI.Document to the root openapi namespace file instead of modifying the existing Document struct. I also see tons of preferential changes (including whitespace changes in the schema file. Please undo those changes leaving only the changes necessary to implement new functionality.

@ayushshrivastv
Copy link
Contributor Author

This PR is going to need a bit of attention. I see you've added OpenAPI.Document to the root openapi namespace file instead of modifying the existing Document struct. I also see tons of preferential changes (including whitespace changes in the schema file. Please undo those changes leaving only the changes necessary to implement new functionality.

Yes, I’ve reopened this issue and am currently working on incorporating support for specifying JSON schema dialects into the existing codebase in a new commit. Currently, there are some linter errors. Once the implementation is fully functional, I’ll commit this pull request. The previous commit is a month old. I’ve just merged the commit to be synchronised with the main branch. Thank You!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants