Skip to content

Add support for custom JSONSchemer configuration#318

Merged
ahx merged 1 commit intoahx:global-json-schemer-configfrom
moberegger:moberegger/respect-json_schemer-global-config
Jan 22, 2025
Merged

Add support for custom JSONSchemer configuration#318
ahx merged 1 commit intoahx:global-json-schemer-configfrom
moberegger:moberegger/respect-json_schemer-global-config

Conversation

@moberegger
Copy link
Copy Markdown
Contributor

@moberegger moberegger commented Jan 22, 2025

A small change to make it so that the global JSONSchemer.configuration is respected when openapi_first builds its router. I made it so that openapi_first will first clone the configuration before making the changes it needs to so that it avoids adjusting the global configuration in case something else in a dev's project is using it.

This useful for something like supporting custom formats. For example, I can now do something like

JSONSchemer.configure do |config|
  config.formats = { 'uuid' => ->(instance, format) { Utils.is_uuid?(instance) } }
end

OpenapiFirst.load('openapi.yaml')

and openapi_first will pick up that configuration and apply it to the JSONSchemer.schemas it creates as it builds the router, which allows it to work with my custom format.

Prior to version 2.2, this would work. Recent changes made it so that a new JSONSchemer::Configuration instance was created, so any prior changes made to JSONSchemer.configuration would no longer be applied.

@moberegger moberegger requested a review from ahx as a code owner January 22, 2025 17:56
@ahx
Copy link
Copy Markdown
Owner

ahx commented Jan 22, 2025

Can you add a test for this so we avoid breaking this (again) in the future?

ahx added a commit that referenced this pull request Jan 22, 2025
@ahx ahx changed the base branch from main to global-json-schemer-config January 22, 2025 20:18
@ahx ahx merged commit 81f5100 into ahx:global-json-schemer-config Jan 22, 2025
@ahx
Copy link
Copy Markdown
Owner

ahx commented Jan 22, 2025

I am struggling with finding a place to test this, but I just added something on another branch I will merge this to.
Thank you. This seems super useful.

@moberegger moberegger deleted the moberegger/respect-json_schemer-global-config branch January 22, 2025 20:33
ahx added a commit that referenced this pull request Jan 22, 2025
- Respect global JSONSchemer configuration (#318)
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