def main(spec_url, spec_path): codegen = CodeGenerator(spec_url, spec_path) codegen_playground = CodeGenerator(PLAYGROUND_SPEC_URL) spec = codegen.open_api_spec print("=" * 100) print("{}: {}".format(spec.info.title, spec.info.version)) print(spec.info.description) print("=" * 100) for root, dirs, files in os.walk("./cognite/client/data_classes"): for file in files: file_path = os.path.join(root, file) if file_path.endswith(".py"): if "relationships" in file_path: print( "* Generating playground code in {}".format(file_path)) codegen_playground.generate(file_path, file_path) else: print("* Generating normal code in {}".format(file_path)) codegen.generate(file_path, file_path)
import argparse import os from openapi.generator import CodeGenerator # DEFAULT_SPEC_URL = "https://storage.googleapis.com/cognitedata-api-docs/dist/v1.json" PLAYGROUND_SPEC_URL = "https://storage.googleapis.com/cognitedata-api-docs/dist/playground.json" if __name__ == "__main__": codegen_playground = CodeGenerator( PLAYGROUND_SPEC_URL, exclude_schemas=["CustomMenuHierarchy", "CustomMenuHierarchyNode"]) spec = codegen_playground.open_api_spec print("=" * 100) print("{}: {}".format(spec.info.title, spec.info.version)) print(spec.info.description) print("=" * 100) for root, dirs, files in os.walk("./cognite/experimental/data_classes"): for file in files: file_path = os.path.join(root, file) if file_path.endswith(".py"): print("* Generating playground code in {}".format(file_path)) codegen_playground.generate(file_path, file_path)
import os from openapi.generator import ClassGenerator, CodeGenerator, UpdateClassGenerator input_path = os.path.join(os.path.dirname(__file__), "input_output/input.py") output_path = os.path.join(os.path.dirname(__file__), "input_output/output.py") output_test_path = os.path.join(os.path.dirname(__file__), "input_output/output_test.py") with open(input_path) as f: INPUT = f.read() with open(output_path) as f: OUTPUT = f.read() if os.getenv("CI") == "1": CODE_GENERATOR = CodeGenerator(spec_path="deref-spec.json") else: CODE_GENERATOR = CodeGenerator( spec_url= "https://storage.googleapis.com/cognitedata-api-docs/dist/v1.json") class TestCodeGenerator: def test_generated_output(self): CODE_GENERATOR.generate(input_path, output_test_path) with open(output_test_path) as f: output = f.read() assert OUTPUT == output def test_output_unchanged_if_regenerated(self): output = CODE_GENERATOR.generate_to_str(output_path) assert OUTPUT == output