code: def gen_class(klass: swagger_parser.Class) -> Code:
      required = sorted(
          (k, v) for k, v in klass.params.items() if v.required
      )
      optional = sorted(
          (k, v) for k, v in klass.params.items() if not v.required
      )
  
      out = [f"class {klass.name}(Printable):"]
      if klass.description:
          out += [
              TAB + line if line else ""
              for line in description_to_docstring(klass.description)
          ]
      for k, v in optional:
          out += [
              f'    {k}: "typing.Optional[{annotation(v.type, prequoted=True)}]" = None'
          ]
      out += [""]
      out += ["    def __init__("]
      out += ["        self,"]
      out += ["        *,"]
      for k, v in required + optional:
          out += ["    " + gen_init_param(v)]
      out += ["    ):"]
      for k, _ in required:
          out += [f"        self.{k} = {k}"]
      for k, _ in optional:
          out += [f"        if not isinstance({k}, Unset):"]
          out += [f"            self.{k} = {k}"]
      out += [""]
      out += ["    @classmethod"]
      out += [f'    def from_json(cls, obj: Json) -> "{klass.name}":']
      out += ['        kwargs: "typing.Dict[str, typing.Any]" = {']
      for k, v in required:
          if need_parse(v.type):
              parsed = load(v.type, f'obj["{k}"]')
          else:
              parsed = f'obj["{k}"]'
          out += [f'            "{k}": {parsed},']
      out += ["        }"]
      for k, v in optional:
          if need_parse(v.type):
              parsed = load(v.type, f'obj["{k}"]')
              parsed = parsed + f' if obj["{k}"] is not None else None'
          else:
              parsed = f'obj["{k}"]'
          out += [f'        if "{k}" in obj:']
          out += [f'            kwargs["{k}"] = {parsed}']
      out += ["        return cls(**kwargs)"]
      out += [""]
      out += [
          "    def to_json(self, omit_unset: bool = False) -> typing.Dict[str, typing.Any]:"
      ]
      out += ['        out: "typing.Dict[str, typing.Any]" = {']
      for k, v in required:
          if need_parse(v.type):
              parsed = dump(v.type, f"self.{k}", "omit_unset")
          else:
              parsed = f"self.{k}"
          out.append(f'            "{k}": {parsed},')
      out += ["        }"]
      for k, v in optional:
          if need_parse(v.type):
              parsed = dump(v.type, f"self.{k}", "omit_unset")
              parsed = f"None if self.{k} is None else {parsed}"
          else:
              parsed = f"self.{k}"
          out += [f'        if not omit_unset or "{k}" in vars(self):']
          out += [f'            out["{k}"] = {parsed}']
      out += ["        return out"]
  
      return "\n".join(out)
  
imports: import os
  import typing
  import swagger_parser
  from typing_extensions import assert_never
label_desc: Use image node_id 13 for calling a global function with example usage: gen_class(klass) and returns: str