datamodel-code-generator
datamodel-code-generator copied to clipboard
$refs to object properties break the parser
trafficstars
Describe the bug The parser raises an error if any models contain references to object properties, rather than the top-level objects.
To Reproduce
Example schema:
openapi: "3.0.3"
info:
title: Example
version: 1.0.0
paths: {}
components:
schemas:
Id:
type: string
Parent:
type: object
properties:
id:
$ref: "#/components/schemas/Id"
name:
type: string
Child:
type: object
properties:
id:
$ref: "#/components/schemas/Id"
parent_id:
$ref: "#/components/schemas/Parent/properties/id"
name:
type: string
This will fail because parent_id points to a property, rather than a schema object.
Used commandline:
$ datamodel-codegen --input ./example.yaml --target-python-version 3.9 --validation
Expected behavior I see two options:
- Generate two models, with
parent_idinChildduplicating theidfield inParent. (Probably best for standard types.) - Generate three models,
Parent,Parent.Id,Child. (Probably best if the referenced field is anobject.)
Version:
- OS: iOS
- Python version: 3.9
- datamodel-code-generator version: 0.11.20
@mfulgo Thank you for creating the issue. But, It's difficult to implement from the current code. I didn't expect the way to refer to an object's property 😅 I will think how to fix the problem.
@mfulgo
I'm sorry for my too late reply.
I have released the fixed version 0.16.0
Thank you very much!!