datamodel-code-generator icon indicating copy to clipboard operation
datamodel-code-generator copied to clipboard

Can't extract models from openapi via paths and references

Open Wim-De-Clercq opened this issue 11 months ago • 2 comments
trafficstars

Describe the bug When trying to extract models from openapi, where the main openapi schema itself does not contain traditional components/schemas it does not seem to behave correctly. No models are found, or otherwise references don't get resolved properly.

To Reproduce

Example schema: Please see the data in this commit https://github.com/Wim-De-Clercq/testingrepo/commit/1c0c8e49f976b577f951350aca6484199c2fd979

It has a little test as well, although nothing is truly asserted.

Expected behavior I expect the schemas within ./cat/schemas.yaml to be turned into models.

Version:

  • OS: Kubuntu 24.04
  • Python version: 3.11
  • datamodel-code-generator version: main branch.

Additional context The test in my commit keeps on complaining about Models not found in the input data.

I actually come from a larger project and tried to reproduce it in a small test. In my large project - with in my eyes a similar setup - I however end up with file not found errors. So I'm pretty sure the ref resolving has problems as well with this kind of setup. Somewhere beyond this test. But at the moment I keep on getting stuck on this error to try reproducing it further.

Wim-De-Clercq avatar Dec 05 '24 12:12 Wim-De-Clercq

I have the same issue, I cannot generate models from paths and also get Models not found in the input data message..

bevanwsjones avatar May 05 '25 18:05 bevanwsjones

For what it's worth, the way we workaround this at the moment is to use redocly cli to merge the split openapi into a single openapi file and then process the generated large file.

npx @redocly/cli@latest bundle openapi.yaml -o /tmp/openapi.yaml
datamodel-codegen --input /tmp/openapi.yaml

Wim-De-Clercq avatar May 06 '25 07:05 Wim-De-Clercq

Hi, I had the same problem. I merged my two openapi files into a single file to make it work.

JulesPeignier avatar Sep 24 '25 08:09 JulesPeignier