Datamodel-code-generator: Arrays in additionalProperties are ignored

Created on 30 Sep 2020  路  3Comments  路  Source: koxudaxi/datamodel-code-generator

Describe the bug
When using an object with additionalProperties and an array of an item type, the resulting code doesn't reference the generated item type.

To Reproduce

Example schema:

openapi: "3.0.0"
info:
  title: Sample API
  description: API description in Markdown.
  version: 1.0.0
servers: []
paths: {}
components:
  schemas:
    test:
      type: object
      properties:
        broken:
          type: object
          additionalProperties:
            type: array
            items:
              $ref: '#/components/schemas/broken'
    broken:
      type: object
      properties:
        foo:
          type: string
        bar:
          type: integer

Results in the following generated file:

# generated by datamodel-codegen:
#   filename:  tmp.yml
#   timestamp: 2020-09-30T13:47:06+00:00

from __future__ import annotations

from typing import Dict, Optional

from pydantic import BaseModel


class Broken(BaseModel):
    foo: Optional[str] = None
    bar: Optional[int] = None


class Test(BaseModel):
    broken: Optional[Dict[str, Broken]] = None

Used commandline:

$ datamodel-codegen --input test.yml --input-file-type openapi --output test_model.py

Expected behavior

class Test(BaseModel):
    broken: Optional[Dict[str, List[Broken]]] = None

Version:

  • OS: Linux
  • Python Verison: 3.8.5
  • datamodel-code-generator Version: 0.5.30
enhancement released

Most helpful comment

I have released a new version as 0.5.39 :rocket:

All 3 comments

@Echronix
Thank you for creating this issue.
OK, I will implement it.

I just hit this as well again

I have released a new version as 0.5.39 :rocket:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

elonzh picture elonzh  路  4Comments

languitar picture languitar  路  3Comments

MikeZaharov picture MikeZaharov  路  3Comments

FlorianLudwig picture FlorianLudwig  路  3Comments

ioggstream picture ioggstream  路  6Comments