Describe the bug
When generating models from openapi yaml that references multiple files with same schemas, and setting --enum-field-as-literal all
following Exception is raised:
python3.10/site-packages/datamodel_code_generator/parser/base.py", line 595, in __delete_duplicate_models child.replace_reference(model.reference) AttributeError: 'BaseModel' object has no attribute 'replace_reference'
To Reproduce
test_openapi.yaml:
openapi: 3.0.1
info:
title: Test
description: Test
version: 0.0.1
servers:
- url: 'https'
paths:
/test:
post:
description: "Test"
operationId: "Test"
parameters: []
requestBody:
description: ""
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/Test"
responses:
default:
description: ""
components:
schemas:
Test:
title: "Test"
type: object
description: ""
properties:
obj1:
$ref: "./schemas1.yaml#/components/schemas/Schema1"
obj2:
$ref: "./schemas2.yaml#/components/schemas/Schema1"
schemas1.yaml:
openapi: 3.0.0
info:
title: Schemas
description: Schemas
version: 1.0.0
paths:
/:
get:
responses:
default:
description: x
components:
schemas:
Object:
description: ""
type: object
properties:
"type":
type: string
enum:
- A1
- A2
- A3
required:
- type
discriminator:
propertyName: type
Schema1:
description: ""
allOf:
- $ref: "#/components/schemas/Object"
- type: "object"
properties:
sth:
type: string
schemas2.yaml:
openapi: 3.0.0
info:
title: Schemas
description: Schemas
version: 1.0.0
paths:
/:
get:
responses:
default:
description: x
components:
schemas:
Object:
description: ""
type: object
properties:
"type":
type: string
enum:
- A1
- A2
- A3
required:
- type
discriminator:
propertyName: type
Schema1:
description: ""
allOf:
- $ref: "#/components/schemas/Object"
- type: "object"
properties:
sth:
type: string
Used commandline:
$ datamodel-codegen --input test_openapi.yaml --output test.py --target-python-version 3.10 --enum-field-as-literal all
Expected behavior
Expected the generation of a pydantic schema
Version:
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too