koxudaxi / datamodel-code-generator

Pydantic model and dataclasses.dataclass generator for easy conversion of JSON, OpenAPI, JSON Schema, and YAML data sources.
https://koxudaxi.github.io/datamodel-code-generator/
MIT License
2.44k stars 281 forks source link

fix: external references to parent folder #1999

Closed luca-knaack-webcom closed 3 weeks ago

luca-knaack-webcom commented 3 weeks ago

The current fix for referencing external models in discriminators breaks when presented with a reference to a schema in a parent folder. This becomes evident in a reference like:

"discriminator": {
  "mapping": {
    "d": "../type-4.json",
    "e": "../subfolder/type-5.json"
  },
  "propertyName": "type_"
}

This edge case is fixed in this PR. Furthermore the tests have been extended to capture this case. This PR builds on #1991, a merge should squash commits.

Merging this PR would also resolve #1141.

codecov[bot] commented 3 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Please upload report for BASE (main@b1c0f22). Learn more about missing BASE report.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1999 +/- ## ======================================= Coverage ? 98.85% ======================================= Files ? 37 Lines ? 4202 Branches ? 979 ======================================= Hits ? 4154 Misses ? 30 Partials ? 18 ``` | [Flag](https://app.codecov.io/gh/koxudaxi/datamodel-code-generator/pull/1999/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Koudai+Aono) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/koxudaxi/datamodel-code-generator/pull/1999/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Koudai+Aono) | `98.52% <100.00%> (?)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Koudai+Aono#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codspeed-hq[bot] commented 3 weeks ago

CodSpeed Performance Report

Merging #1999 will not alter performance

Comparing luca-knaack-webcom:main (3d43453) with main (b1c0f22)

Summary

✅ 29 untouched benchmarks