OpenAPITools / OpenAPITools/openapi-generator

[BUG] java: Map<String, Object>, to openapi spec: "additionalProperties": { "type": "object" }, after generated python client, most of the types can't handle

Open
#15,839 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Python Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

in java:
class Tag{
Map<String, Object> attributes;
}
to openapi spec:
{"attributes": { "type": "object",
"additionalProperties": {
"type": "object"
} }
after generated python client, most of the types can't handle

openapi-generator version

6.6.0

OpenAPI declaration file content or url
{
  "openapi": "3.0.1",
  "info": {
    "title": "OpenAPI definition",
    "version": "v0"
  },
  "servers": [
    {
      "url": "http://localhost:8059",
      "description": "Generated server url"
    }
  ],
  "paths": {},
  "components": {
    "schemas": {
      "Tag": {
        "type": "object",
        "properties": {
          "attributes": {
            "type": "object",
            "additionalProperties": {
              "type": "object"
            }
          }
        }
      }
    }
  }
}
Generation Details

java -jar ./openapi-generator-cli.jar generate -i ./nrpservice/nrp/lop/bcommon/openapi.json -g python-nextgen -o ./nrpservice/nrp/pylop1

openapi.json is exactly the content i have pasted above.

Steps to reproduce

import unittest

from openapi_client.models.tag import Tag

class MyTestCase(unittest.TestCase):
def test_tag(self):
tag = Tag();
print(Tag.to_json(tag))
json = '{"attributes":{"height":1}}'
tag1 = Tag.from_json(json)
print("data_class_instance=", tag1)

if name == "main":
unittest.main()

above case will fail by reporting:
File "pydantic/main.py", line 526, in pydantic.main.BaseModel.parse_obj
File "pydantic/main.py", line 341, in pydantic.main.BaseModel.init
pydantic.error_wrappers.ValidationError: 1 validation error for Tag
attributes -> height
value is not a valid dict (type=type_error.dict)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided openapi.json and the python-nextgen generation command, then inspect the generated openapi_client/models/tag.py handling of attributes. Reproduce the failure with Tag.from_json('{"attributes":{"height":1}}'); done means the generated client accepts the demonstrated map value without the reported validation error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, python
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.