예제 #1
0
 def generate_constructor(self, schemas, indentation):
     constructor_params = [" " * indentation + "def __init__(self"]
     ignore = [p for p in TO_EXCLUDE]
     for schema in schemas:
         for prop_name, prop in self._get_schema_properties(schema).items():
             prop_name = utils.to_snake_case(prop_name)
             req = " = None"  # TODO: check if prop is required or not
             if prop_name not in ignore:
                 constructor_params.append("{}: {}{}".format(
                     prop_name, utils.get_type_hint(prop), req))
                 ignore.append(prop_name)
     constructor_params = ", ".join(
         constructor_params) + ", cognite_client = None):"
     constructor_body = ""
     ignore = [p for p in TO_EXCLUDE]
     for schema in schemas:
         for prop_name, prop in self._get_schema_properties(schema).items():
             prop_name = utils.to_snake_case(prop_name)
             if prop_name not in ignore:
                 constructor_body += " " * (indentation +
                                            4) + "self.{} = {}\n".format(
                                                prop_name, prop_name)
                 ignore.append(prop_name)
     constructor_body += " " * (
         indentation + 4) + "self._cognite_client = cognite_client\n"
     return constructor_params + "\n" + constructor_body[:-1]
예제 #2
0
 def _get_type_hint_with_marker(self, prop):
     res = utils.get_type_hint(prop)
     if res == "Dict[str, Any]":
         name = self._spec.components.schemas.rev_get(prop)
         if name != None and name[-8:] == "Metadata":
             return "Dict[str, str]", False
         if name != None and name == "NodeProperties3D":
             return "Dict[str, Dict[str, str]]", False
         if name != None and name in CLASS_NAME_OVERRIDE:
             return CLASS_NAME_OVERRIDE[name], True
         elif name != None and name[:1].isupper():
             return name, True
     return res, False
예제 #3
0
 def generate_docstring(self, schemas, indentation):
     docstring = " " * indentation + '"""{}\n\n'.format(
         self._get_schema_description(schemas[0]))
     docstring += " " * indentation + "Args:\n"
     ignore = [p for p in TO_EXCLUDE]
     for schema in schemas:
         for prop_name, prop in self._get_schema_properties(schema).items():
             if prop_name not in ignore:
                 docstring += " " * (indentation +
                                     4) + "{} ({}): {}\n".format(
                                         utils.to_snake_case(prop_name),
                                         utils.get_type_hint(prop),
                                         self._get_schema_description(prop))
                 ignore.append(prop_name)
     docstring += (
         " " * (indentation + 4) +
         "cognite_client (CogniteClient): The client to associate with this object.\n"
     )
     docstring += " " * indentation + '"""'
     return docstring