podhmo / metashape

0 stars 1 forks source link

when using inputs.openapi, python class is generated even primitive type is passed #99

Open podhmo opened 3 years ago

podhmo commented 3 years ago

https://gist.github.com/podhmo/729fd8b50cd5b6d8c9fe15520a26ee96

podhmo commented 3 years ago
podhmo commented 3 years ago

the one of expected output.

from __future__ import annotations
import typing

class Attachment:
    """
    An object representing a container instance or task attachment.
    """

    details: typing.Optional[typing.List[KeyValuePair]]
    id: typing.Optional[str]
    status: typing.Optional[str]
    type: typing.Optional[str]

class KeyValuePair:
    """
    A key-value pair object.
    """

    name: typing.Optional[str]
    value: typing.Optional[str]
podhmo commented 3 years ago

ah, something like that..

          "value": {
            "allOf": [
              {
                "$ref": "#/components/schemas/String"
              },
              {
                "description": "The value of the key-value pair. For environment variables, this is the value of the environment variable."
              }
            ]
          }
podhmo commented 3 years ago

also

      "TagResourceResponse": {
        "example": {},
        "properties": {},
        "type": "object"
      },
podhmo commented 3 years ago
diff --git a/metashape/inputs/openapi/__init__.py b/metashape/inputs/openapi/__init__.py
index a135b05..980fad7 100644
--- a/metashape/inputs/openapi/__init__.py
+++ b/metashape/inputs/openapi/__init__.py
@@ -225,7 +225,7 @@ class Resolver:
         typ = d.get("type", None)
         if typ in cand:
             return True
-        if self.has_allof(d):
+        if self.has_allof(d) and all("type" in x or "$ref" in x for x in d["allOf"]):
             return True
         return False