Skip to content
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

Generate POJOs from subschemas defined in 'definitions'/'$defs' section #1523

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

Conversation

unkish
Copy link
Collaborator

@unkish unkish commented May 22, 2023

Closes #1123
Closes #987

@unkish
Copy link
Collaborator Author

unkish commented May 22, 2023

A fairly naïve implementation inspired by #1124.
All props and kudos to Duane Zamrok.

Not supported: defaulting to using the dialect of the parent schema when figuring out whether to use/prefer definitions over $defs.

Feedback/critique is welcomed.

@unkish unkish changed the title Generate objects from subschemas defined in 'definitions'/'$defs' section Generate POJO's from subschemas defined in 'definitions'/'$defs' section May 22, 2023
@unkish unkish changed the title Generate POJO's from subschemas defined in 'definitions'/'$defs' section Generate POJOs from subschemas defined in 'definitions'/'$defs' section May 22, 2023
@lejtemxviw
Copy link

It looks like OAS3 would expect to include the schemas for the spec in components/schemas, rather than definitions - could we modify this change so that the path to look for was customizable, somehow? Or maybe leave this PR as is, but create a new ticket/PR to add that as an improvement to this PR?

@unkish
Copy link
Collaborator Author

unkish commented Jun 1, 2023

@lejtemxviw

It looks like OAS3 would expect to include the schemas for the spec in components/schemas, rather than definitions - could we modify this change so that the path to look for was customizable, somehow

I guess one option could be changing private String getDefinitionsNodeName to protected String getDefinitionsNodeName which would then allow overriding given method in custom SchemaRule.


Please note that handling/processing of oneOf/allOf/anyOf nodes is not in the scope of given request (if OAS3 contains these - they'll be skipped)

@joelittlejohn
Copy link
Owner

I guess if we make this configurable, we need to ensure that you can specify a path to the schemas rather than just a property name. It sounds like oas3 as the node in /components/schemas. I like the idea of making this configurable as $defs was only recently standardised.

@unkish
Copy link
Collaborator Author

unkish commented Aug 2, 2023

  • renamed SchemaRule#getDefinitionsNodeName(JsonNode) to SchemaRule#getDefinitionsNodePath(JsonNode)
  • changed access modifier of SchemaRule#getDefinitionsNodePath(JsonNode) from private to protected
  • added SchemaIT::definitionsFromCustomPathProcessed_when_definitionsNodePathIsOverridden to validate possibility of configuring custom schema "definitions" path through custom RuleFactory

It should be possible to make custom definitions path configurable via config or extension property if needed (currently not implemented)

@unkish
Copy link
Collaborator Author

unkish commented Oct 5, 2023

I like the idea of making this configurable as $defs was only recently standardised

@joelittlejohn what is your vision on having definitions path being configurable ?
Would it be via

  • configuration property
  • extension property
  • both ?

Shall that be addressed within given issue ?

@joelittlejohn
Copy link
Owner

For now I was imagining a configuration property, like definitionsPath (default is as per the JSON schema spec). I think having different definitions paths per document would be a pretty confusing way to do things.

Given that the current behaviour has been in place for so long, I also think we need a new config option to turn this on: generateDefinitions, default false.

@unkish
Copy link
Collaborator Author

unkish commented Oct 7, 2023

For now I was imagining a configuration property, like definitionsPath (default is as per the JSON schema spec)

  1. Would that be per current latest JSON schema spec ? Ie. $defs
  2. Which "format" it would expected to be defined
    1. $defs
    2. /$defs
    3. #/$defs
    4. ...

I think having different definitions paths per document would be a pretty confusing way to do things.

Whilst I do agree that it might be confusing, on the other hand it might as well be not that uncommon.
Note: jsonschema2pojo does not need to support all possible permutations though and given fact could be stated on wiki page.

May I assume that it would mean there will be no need for fallback logic as the behavior will be straight-forward:
if generateDefinitions is true and definitionsPath exists - process it's definitions.

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