From 229c01c7a2343ed605db8cfdeffc6c454c4be49a Mon Sep 17 00:00:00 2001 From: forozco Date: Sat, 21 Jul 2018 15:54:43 +0100 Subject: [PATCH 1/5] consolidate to single file per package --- .../python/ConjurePythonGenerator.java | 130 +-- .../conjure/python/PythonFileGenerator.java | 18 - .../ClientGenerator.java} | 56 +- .../conjure/python/poet/PythonAlias.java | 3 +- .../conjure/python/poet/PythonAll.java | 8 +- .../conjure/python/poet/PythonBean.java | 9 + .../conjure/python/poet/PythonClass.java | 6 +- .../conjure/python/poet/PythonEnum.java | 7 +- .../conjure/python/poet/PythonFile.java | 34 +- .../conjure/python/poet/PythonLine.java | 6 - .../conjure/python/poet/PythonMetaYaml.java | 4 +- .../conjure/python/poet/PythonService.java | 11 + .../conjure/python/poet/PythonSetup.java | 9 +- .../poet/PythonUnionTypeDefinition.java | 18 +- ...rPython.java => DefaultBeanGenerator.java} | 176 ++-- .../python/types/DefaultTypeNameVisitor.java | 13 +- .../python/types/MyPyTypeNameVisitor.java | 13 +- .../python/types/PythonBeanGenerator.java | 33 + .../conjure/python/util/ImportsVisitor.java | 116 --- .../conjure/python/util/TypeNameVisitor.java | 55 -- .../python/ConjurePythonGeneratorTest.java | 7 +- .../services/expected/conda_recipe/meta.yaml | 1 + .../services/expected/package/__init__.py | 1 + .../expected/package/another/TestService.py | 439 --------- .../expected/package/another/__init__.py | 440 ++++++++- .../package/product/CreateDatasetRequest.py | 31 - .../expected/package/product/__init__.py | 39 +- .../product_datasets/BackingFileSystem.py | 42 - .../package/product_datasets/Dataset.py | 32 - .../package/product_datasets/__init__.py | 79 +- .../types/expected/conda_recipe/meta.yaml | 1 + .../types/expected/package/__init__.py | 1 + .../expected/package/another/TestService.py | 439 --------- .../expected/package/another/__init__.py | 440 ++++++++- .../DeeplyNestedService.py | 35 - .../nested_deeply_nested_service/__init__.py | 43 +- .../nested_service/SimpleNestedService.py | 35 - .../package/nested_service/SimpleObject.py | 23 - .../package/nested_service/__init__.py | 67 +- .../nested_service2/SimpleNestedService2.py | 35 - .../package/nested_service2/__init__.py | 43 +- .../package/product/AliasAsMapKeyExample.py | 81 -- .../expected/package/product/AnyExample.py | 24 - .../expected/package/product/AnyMapExample.py | 26 - .../product/BearerTokenAliasExample.py | 3 - .../package/product/BearerTokenExample.py | 23 - .../package/product/BinaryAliasExample.py | 4 - .../expected/package/product/BinaryExample.py | 24 - .../package/product/BooleanAliasExample.py | 3 - .../package/product/BooleanExample.py | 23 - .../package/product/CreateDatasetRequest.py | 31 - .../package/product/DateTimeAliasExample.py | 3 - .../package/product/DateTimeExample.py | 23 - .../package/product/DoubleAliasExample.py | 3 - .../expected/package/product/DoubleExample.py | 23 - .../package/product/EmptyObjectExample.py | 13 - .../expected/package/product/EnumExample.py | 15 - .../package/product/EnumFieldExample.py | 24 - .../package/product/IntegerAliasExample.py | 3 - .../package/product/IntegerExample.py | 23 - .../expected/package/product/ListExample.py | 41 - .../package/product/ManyFieldExample.py | 95 -- .../package/product/MapAliasExample.py | 6 - .../expected/package/product/MapExample.py | 25 - .../package/product/OptionalExample.py | 25 - .../product/PrimitiveOptionalsExample.py | 73 -- .../package/product/ReferenceAliasExample.py | 4 - .../package/product/ReservedKeyExample.py | 47 - .../package/product/RidAliasExample.py | 3 - .../expected/package/product/RidExample.py | 23 - .../package/product/SafeLongAliasExample.py | 3 - .../package/product/SafeLongExample.py | 23 - .../expected/package/product/SetExample.py | 33 - .../package/product/StringAliasExample.py | 3 - .../expected/package/product/StringExample.py | 23 - .../package/product/UnionTypeExample.py | 92 -- .../package/product/UuidAliasExample.py | 3 - .../expected/package/product/UuidExample.py | 23 - .../expected/package/product/__init__.py | 875 ++++++++++++++++-- .../product_datasets/BackingFileSystem.py | 42 - .../package/product_datasets/Dataset.py | 32 - .../package/product_datasets/__init__.py | 79 +- .../with_imports/AliasImportedObject.py | 4 - .../AliasImportedPrimitiveAlias.py | 4 - .../AliasImportedReferenceAlias.py | 4 - .../with_imports/ComplexObjectWithImports.py | 32 - .../package/with_imports/ImportService.py | 37 - .../with_imports/ImportedAliasInMaps.py | 27 - .../package/with_imports/UnionWithImports.py | 38 - .../expected/package/with_imports/__init__.py | 155 +++- .../conjure/python/cli/ConjurePythonCli.java | 9 +- 91 files changed, 2452 insertions(+), 2801 deletions(-) delete mode 100644 conjure-python-core/src/main/java/com/palantir/conjure/python/PythonFileGenerator.java rename conjure-python-core/src/main/java/com/palantir/conjure/python/{service/ServiceGeneratorPython.java => client/ClientGenerator.java} (71%) rename conjure-python-core/src/main/java/com/palantir/conjure/python/types/{DefaultBeanGeneratorPython.java => DefaultBeanGenerator.java} (51%) create mode 100644 conjure-python-core/src/main/java/com/palantir/conjure/python/types/PythonBeanGenerator.java delete mode 100644 conjure-python-core/src/main/java/com/palantir/conjure/python/util/ImportsVisitor.java delete mode 100644 conjure-python-core/src/main/java/com/palantir/conjure/python/util/TypeNameVisitor.java delete mode 100644 conjure-python-core/src/test/resources/services/expected/package/another/TestService.py delete mode 100644 conjure-python-core/src/test/resources/services/expected/package/product/CreateDatasetRequest.py delete mode 100644 conjure-python-core/src/test/resources/services/expected/package/product_datasets/BackingFileSystem.py delete mode 100644 conjure-python-core/src/test/resources/services/expected/package/product_datasets/Dataset.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/another/TestService.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/nested_deeply_nested_service/DeeplyNestedService.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/nested_service/SimpleNestedService.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/nested_service/SimpleObject.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/nested_service2/SimpleNestedService2.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/AliasAsMapKeyExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/AnyExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/AnyMapExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/BearerTokenAliasExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/BearerTokenExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/BinaryAliasExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/BinaryExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/BooleanAliasExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/BooleanExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/CreateDatasetRequest.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/DateTimeAliasExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/DateTimeExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/DoubleAliasExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/DoubleExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/EmptyObjectExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/EnumExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/EnumFieldExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/IntegerAliasExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/IntegerExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/ListExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/ManyFieldExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/MapAliasExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/MapExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/OptionalExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/PrimitiveOptionalsExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/ReferenceAliasExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/ReservedKeyExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/RidAliasExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/RidExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/SafeLongAliasExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/SafeLongExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/SetExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/StringAliasExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/StringExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/UnionTypeExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/UuidAliasExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product/UuidExample.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product_datasets/BackingFileSystem.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/product_datasets/Dataset.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/with_imports/AliasImportedObject.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/with_imports/AliasImportedPrimitiveAlias.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/with_imports/AliasImportedReferenceAlias.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/with_imports/ComplexObjectWithImports.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/with_imports/ImportService.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/with_imports/ImportedAliasInMaps.py delete mode 100644 conjure-python-core/src/test/resources/types/expected/package/with_imports/UnionWithImports.py diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/ConjurePythonGenerator.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/ConjurePythonGenerator.java index 66a1adaed..662d1a0fb 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/ConjurePythonGenerator.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/ConjurePythonGenerator.java @@ -16,40 +16,35 @@ package com.palantir.conjure.python; -import com.google.common.collect.ImmutableList; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import com.palantir.conjure.python.client.ClientGenerator; import com.palantir.conjure.python.poet.PythonAll; import com.palantir.conjure.python.poet.PythonClass; -import com.palantir.conjure.python.poet.PythonClassName; import com.palantir.conjure.python.poet.PythonFile; -import com.palantir.conjure.python.poet.PythonImport; import com.palantir.conjure.python.poet.PythonLine; import com.palantir.conjure.python.poet.PythonMetaYaml; import com.palantir.conjure.python.poet.PythonSetup; -import com.palantir.conjure.python.util.TypeNameVisitor; +import com.palantir.conjure.python.types.PythonBeanGenerator; import com.palantir.conjure.spec.ConjureDefinition; -import com.palantir.conjure.spec.ServiceDefinition; import com.palantir.conjure.spec.TypeDefinition; -import com.palantir.conjure.spec.TypeName; -import java.util.HashMap; +import java.nio.file.Path; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; public final class ConjurePythonGenerator { - private PythonFileGenerator beanGenerator; - private PythonFileGenerator serviceGenerator; + private final PythonBeanGenerator beanGenerator; + private final ClientGenerator clientGenerator; private final GeneratorConfiguration config; - public ConjurePythonGenerator( - PythonFileGenerator beanGenerator, - PythonFileGenerator serviceGenerator, + public ConjurePythonGenerator(PythonBeanGenerator beanGenerator, ClientGenerator clientGenerator, GeneratorConfiguration config) { this.beanGenerator = beanGenerator; - this.serviceGenerator = serviceGenerator; + this.clientGenerator = clientGenerator; this.config = config; } @@ -62,10 +57,7 @@ public void write(ConjureDefinition conjureDefinition, PythonFileWriter writer) } public List generate(ConjureDefinition conjureDefinition) { - Map knownTypes = new HashMap<>(); - TypeDefinition.Visitor indexingVisitor = new TypeNameVisitor(); - conjureDefinition.getTypes() - .forEach(typeDefinition -> knownTypes.put(typeDefinition.accept(indexingVisitor), typeDefinition)); + List types = conjureDefinition.getTypes(); String pythonicPackageName = config.packageName().replace('-', '_'); PackageNameProcessor packageNameProcessor = PackageNameProcessor.builder() @@ -74,70 +66,81 @@ public List generate(ConjureDefinition conjureDefinition) { .addProcessors(new TopLevelAddingPackageNameProcessor(pythonicPackageName)) .build(); - List beanClasses = knownTypes.values() + List beanClasses = types .stream() - .map(objectDefinition -> beanGenerator.generateFile(knownTypes, packageNameProcessor, objectDefinition)) + .map(objectDefinition -> beanGenerator.generateObject(types, packageNameProcessor, objectDefinition)) .collect(Collectors.toList()); - List serviceClasses = conjureDefinition.getServices() + List serviceClasses = conjureDefinition.getServices() .stream() - .map(serviceDef -> serviceGenerator.generateFile(knownTypes, packageNameProcessor, serviceDef)) + .map(serviceDef -> clientGenerator.generateClient(types, packageNameProcessor, serviceDef)) .collect(Collectors.toList()); - Map> filesByPackageName = Stream.concat(beanClasses.stream(), serviceClasses.stream()) - .collect(Collectors.groupingBy(PythonFile::packageName)); + Map> classesByPackageName = + Stream.concat(beanClasses.stream(), serviceClasses.stream()) + .collect(Collectors.groupingBy(PythonClass::packageName)); - List moduleInitFiles = filesByPackageName.entrySet() + // group into files + List pythonFiles = classesByPackageName.entrySet() .stream() - .map(entry -> buildModuleInit(entry.getKey(), entry.getValue())) + .map(entry -> PythonFile.builder() + .packageName(entry.getKey()) + .addAllImports(entry.getValue() + .stream() + .flatMap(pt -> pt.requiredImports().stream()) + .collect(Collectors.toSet())) + .addAllContents(entry.getValue())) .collect(Collectors.toList()); - List rootInit = ImmutableList.of(buildRootInit(pythonicPackageName, filesByPackageName.keySet())); + Map> initDefinitions = Maps.newHashMap(); + pythonFiles.stream() + .flatMap(f -> getIntermediateInitPaths(f.build()).entrySet().stream()) + .forEach(e -> initDefinitions.merge(e.getKey(), e.getValue(), (v1, v2) -> { + Set combined = Sets.newHashSet(v1); + combined.addAll(v2); + return combined; + })); + List initFiles = initDefinitions.entrySet().stream() + .map(e -> buildInitPythonFile(e.getKey(), e.getValue())) + .filter(f -> !classesByPackageName.keySet().contains(f.build().packageName())) + .collect(Collectors.toList()); - return Stream.of( - beanClasses.stream(), - serviceClasses.stream(), - moduleInitFiles.stream(), - rootInit.stream()) - .flatMap(Function.identity()) + return Stream.concat(pythonFiles.stream(), initFiles.stream()) + .map(f -> { + if (f.build().packageName().indexOf('.') < 0) { + f.addContents(versionAttribute(f.build().packageName())); + } + return f; + }) + .map(PythonFile.Builder::build) .collect(Collectors.toList()); } - private PythonFile buildModuleInit(String packageName, List moduleFiles) { - return PythonFile.builder() + private static Map> getIntermediateInitPaths(PythonFile pythonFile) { + Path filePath = PythonFileWriter.getPath(pythonFile).getParent(); + Map> initFiles = Maps.newHashMap(); + while (filePath.getParent() != null) { + initFiles.put(filePath.getParent(), Sets.newHashSet(filePath.getFileName())); + filePath = filePath.getParent(); + } + return initFiles; + } + + private PythonFile.Builder buildInitPythonFile(Path module, Set submodules) { + String packageName = module.toString().replace('/', '.'); + PythonAll all = PythonAll.builder() .packageName(packageName) - .fileName("__init__.py") - .imports(moduleFiles.stream() - .flatMap(file -> file.contents().stream() - .map(pythonClass -> PythonImport.of( - PythonClassName.of( - // File has a file extension .py - "." + file.fileName().substring(0, file.fileName().length() - 3), - pythonClass.className())))) - .collect(Collectors.toList())) - .addContents(PythonAll.builder() - .addAllContents(moduleFiles.stream() - .flatMap(file -> file.contents().stream()) - .map(PythonClass::className) - .sorted() - .collect(Collectors.toList())) - .build()) + .addAllContents(submodules.stream().map(m -> m.toString()).sorted().collect(Collectors.toList())) .build(); + return PythonFile.builder() + .packageName(packageName) + .addContents(all); } - private PythonFile buildRootInit(String packageName, Set submodules) { - return PythonFile.builder() + private PythonClass versionAttribute(String packageName) { + return PythonLine.builder() + .text(String.format("__version__ = \"%s\"", config.packageVersion())) .packageName(packageName) - .fileName("__init__.py") - .addContents(PythonAll.builder() - .addAllContents(submodules.stream() - .map(packagePath -> packagePath.substring(packageName.length() + 1)) - .sorted() - .collect(Collectors.toList())) - .build()) - .addContents(PythonLine.builder() - .text(String.format("__version__ = \"%s\"", config.packageVersion())) - .build()) .build(); } @@ -155,6 +158,7 @@ private PythonFile buildPythonSetupFile() { return PythonFile.builder() .fileName("setup.py") + .addAllImports(setup.requiredImports()) .addContents(setup) .build(); } diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/PythonFileGenerator.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/PythonFileGenerator.java deleted file mode 100644 index e187002ed..000000000 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/PythonFileGenerator.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * (c) Copyright 2018 Palantir Technologies Inc. All rights reserved. - */ - -package com.palantir.conjure.python; - -import com.palantir.conjure.python.poet.PythonFile; -import com.palantir.conjure.spec.TypeDefinition; -import com.palantir.conjure.spec.TypeName; -import java.util.Map; - -public interface PythonFileGenerator { - - PythonFile generateFile( - Map types, - PackageNameProcessor packageNameProvider, - T definition); -} diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/service/ServiceGeneratorPython.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/client/ClientGenerator.java similarity index 71% rename from conjure-python-core/src/main/java/com/palantir/conjure/python/service/ServiceGeneratorPython.java rename to conjure-python-core/src/main/java/com/palantir/conjure/python/client/ClientGenerator.java index c47e107b0..97e83a1c8 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/service/ServiceGeneratorPython.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/client/ClientGenerator.java @@ -14,53 +14,50 @@ * limitations under the License. */ -package com.palantir.conjure.python.service; +package com.palantir.conjure.python.client; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; import com.palantir.conjure.python.PackageNameProcessor; -import com.palantir.conjure.python.PythonFileGenerator; +import com.palantir.conjure.python.poet.PythonClass; +import com.palantir.conjure.python.poet.PythonClassName; import com.palantir.conjure.python.poet.PythonEndpointDefinition; import com.palantir.conjure.python.poet.PythonEndpointDefinition.PythonEndpointParam; -import com.palantir.conjure.python.poet.PythonFile; import com.palantir.conjure.python.poet.PythonImport; import com.palantir.conjure.python.poet.PythonService; import com.palantir.conjure.python.types.DefaultTypeNameVisitor; import com.palantir.conjure.python.types.MyPyTypeNameVisitor; +import com.palantir.conjure.python.types.ReferencedTypeNameVisitor; import com.palantir.conjure.python.types.TypeMapper; import com.palantir.conjure.python.util.CaseConverter; -import com.palantir.conjure.python.util.ImportsVisitor; import com.palantir.conjure.spec.PrimitiveType; import com.palantir.conjure.spec.ServiceDefinition; -import com.palantir.conjure.spec.Type; import com.palantir.conjure.spec.TypeDefinition; -import com.palantir.conjure.spec.TypeName; import com.palantir.conjure.visitor.TypeVisitor; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; -public final class ServiceGeneratorPython implements PythonFileGenerator { +public final class ClientGenerator { - @Override - public PythonFile generateFile( - Map types, - PackageNameProcessor packageNameProcessor, + public PythonClass generateClient( + List types, + PackageNameProcessor packageNameProvider, ServiceDefinition serviceDefinition) { - ImportsVisitor importsVisitor = new ImportsVisitor( - serviceDefinition.getServiceName(), packageNameProcessor, types); - TypeMapper mapper = new TypeMapper(new DefaultTypeNameVisitor(types.keySet())); - TypeMapper myPyMapper = new TypeMapper(new MyPyTypeNameVisitor(types.keySet())); - String packageName = packageNameProcessor.getPackageName(serviceDefinition.getServiceName().getPackage()); + TypeMapper mapper = new TypeMapper(new DefaultTypeNameVisitor(types)); + TypeMapper myPyMapper = new TypeMapper(new MyPyTypeNameVisitor(types)); + ReferencedTypeNameVisitor referencedTypeNameVisitor = new ReferencedTypeNameVisitor(types, packageNameProvider); - Builder referencedTypesBuilder = ImmutableSet.builder(); + Builder referencedTypesBuilder = ImmutableSet.builder(); List endpoints = serviceDefinition.getEndpoints() .stream() .map(ed -> { - ed.getReturns().ifPresent(referencedTypesBuilder::add); - ed.getArgs().forEach(arg -> referencedTypesBuilder.add(arg.getType())); + ed.getReturns() + .ifPresent(returnType -> referencedTypesBuilder.addAll( + returnType.accept(referencedTypeNameVisitor))); + ed.getArgs().forEach(arg -> referencedTypesBuilder.addAll( + arg.getType().accept(referencedTypeNameVisitor))); List params = ed.getArgs() .stream() @@ -94,20 +91,21 @@ public PythonFile generateFile( }) .collect(Collectors.toList()); + String packageName = + packageNameProvider.getPackageName(serviceDefinition.getServiceName().getPackage()); List imports = referencedTypesBuilder.build() .stream() - .flatMap(entry -> entry.accept(importsVisitor).stream()) + .filter(entry -> !entry.conjurePackage().equals(packageName)) // don't need to import if in this file + .map(className -> PythonImport.of(className, packageName)) .collect(Collectors.toList()); - return PythonFile.builder() - .fileName(String.format("%s.py", serviceDefinition.getServiceName().getName())) + return PythonService.builder() .packageName(packageName) - .imports(imports) - .addContents(PythonService.builder() - .className(serviceDefinition.getServiceName().getName()) - .docs(serviceDefinition.getDocs()) - .addAllEndpointDefinitions(endpoints) - .build()) + .addAllRequiredImports(PythonService.DEFAULT_IMPORTS) + .addAllRequiredImports(imports) + .className(serviceDefinition.getServiceName().getName()) + .docs(serviceDefinition.getDocs()) + .addAllEndpointDefinitions(endpoints) .build(); } } diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonAlias.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonAlias.java index 2cb3186a4..ea762f209 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonAlias.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonAlias.java @@ -20,11 +20,12 @@ @Value.Immutable public interface PythonAlias extends PythonClass { + String aliasName(); String aliasTarget(); @Override default void emit(PythonPoetWriter poetWriter) { - poetWriter.writeIndentedLine(String.format("%s = %s", className(), aliasTarget())); + poetWriter.writeIndentedLine(String.format("%s = %s", aliasName(), aliasTarget())); poetWriter.writeLine(); } diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonAll.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonAll.java index 0e7f9f827..654fe1d93 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonAll.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonAll.java @@ -11,18 +11,12 @@ public interface PythonAll extends PythonClass { List contents(); - @Override - @Value.Default - default String className() { - return ""; - } - @Override default void emit(PythonPoetWriter poetWriter) { poetWriter.maintainingIndent(() -> { poetWriter.writeIndentedLine("__all__ = ["); poetWriter.increaseIndent(); - contents().stream().forEach(a -> poetWriter.writeIndentedLine("'%s',", a)); + contents().forEach(a -> poetWriter.writeIndentedLine("'%s',", a)); poetWriter.decreaseIndent(); poetWriter.writeIndentedLine("]"); poetWriter.writeLine(); diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonBean.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonBean.java index 50e7a45e2..de7878b32 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonBean.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonBean.java @@ -29,6 +29,11 @@ public interface PythonBean extends PythonClass { ImmutableSet DEFAULT_IMPORTS = ImmutableSet.of( + PythonImport.of(PythonClassName.of("typing", "List")), + PythonImport.of(PythonClassName.of("typing", "Set")), + PythonImport.of(PythonClassName.of("typing", "Dict")), + PythonImport.of(PythonClassName.of("typing", "Tuple")), + PythonImport.of(PythonClassName.of("typing", "Optional")), PythonImport.of(PythonClassName.of("conjure_python_client", "ConjureBeanType")), PythonImport.of(PythonClassName.of("conjure_python_client", "ConjureFieldDefinition"))); @@ -38,6 +43,10 @@ default Set requiredImports() { return DEFAULT_IMPORTS; } + String className(); + + Optional docs(); + List fields(); @Override diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonClass.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonClass.java index c74b6f63a..e66ccac67 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonClass.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonClass.java @@ -16,16 +16,12 @@ package com.palantir.conjure.python.poet; -import com.palantir.conjure.spec.Documentation; -import java.util.Optional; import java.util.Set; public interface PythonClass extends Emittable { - String className(); - Set requiredImports(); - Optional docs(); + String packageName(); } diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonEnum.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonEnum.java index 209d8688e..5141df0ce 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonEnum.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonEnum.java @@ -28,14 +28,17 @@ public interface PythonEnum extends PythonClass { ImmutableSet DEFAULT_IMPORTS = ImmutableSet.of( - PythonImport.of(PythonClassName.of("conjure_python_client", "ConjureEnumType"))); + PythonImport.of(PythonClassName.of("conjure_python_client", "*"))); @Override - @Value.Default default Set requiredImports() { return DEFAULT_IMPORTS; } + String className(); + + Optional docs(); + List values(); @Override diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonFile.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonFile.java index eecc24cb9..250d227bc 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonFile.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonFile.java @@ -16,7 +16,7 @@ package com.palantir.conjure.python.poet; -import com.google.common.collect.Streams; +import java.util.Comparator; import java.util.List; import java.util.Set; import org.immutables.value.Value; @@ -29,7 +29,10 @@ default String packageName() { return ""; } - String fileName(); + @Value.Default + default String fileName() { + return "__init__.py"; + } Set imports(); @@ -38,14 +41,13 @@ default String packageName() { @Override default void emit(PythonPoetWriter poetWriter) { poetWriter.maintainingIndent(() -> { - Streams.concat(imports().stream(), contents().stream() - .flatMap(pythonClass -> pythonClass.requiredImports().stream())) - .distinct() - .sorted() - .forEach(poetWriter::emit); - + if (packageName().length() > 0) { + poetWriter.writeLine(String.format("# this is package %s", packageName())); + } + imports().stream().sorted().forEach(poetWriter::emit); poetWriter.writeLine(); - contents().stream().forEach(poetWriter::emit); + + contents().stream().sorted(new PythonClassSerializationComparator()).forEach(poetWriter::emit); }); } @@ -54,4 +56,18 @@ class Builder extends ImmutablePythonFile.Builder {} static Builder builder() { return new Builder(); } + + class PythonClassSerializationComparator implements Comparator { + @Override + public int compare(PythonClass pc1, PythonClass pc2) { + // PythonAlias type objects should always go last + if (pc1 instanceof PythonAlias && !(pc2 instanceof PythonAlias)) { + return 1; + } else if (!(pc1 instanceof PythonAlias) && pc2 instanceof PythonAlias) { + return -1; + } else { + return 0; + } + } + } } diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonLine.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonLine.java index eeb953ac4..8f7b9a8f0 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonLine.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonLine.java @@ -10,12 +10,6 @@ public interface PythonLine extends PythonClass { String text(); - @Override - @Value.Default - default String className() { - return ""; - } - @Override default void emit(PythonPoetWriter poetWriter) { poetWriter.writeIndentedLine(text()); diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonMetaYaml.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonMetaYaml.java index d59b60247..8408204b9 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonMetaYaml.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonMetaYaml.java @@ -11,8 +11,8 @@ public interface PythonMetaYaml extends PythonClass { @Override - default String className() { - return ""; + default String packageName() { + return "conda_recipe"; } String condaPackageName(); diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonService.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonService.java index dac8fc778..fbd9610ae 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonService.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonService.java @@ -17,7 +17,9 @@ package com.palantir.conjure.python.poet; import com.google.common.collect.ImmutableSet; +import com.palantir.conjure.spec.Documentation; import java.util.List; +import java.util.Optional; import java.util.Set; import org.immutables.value.Value; @@ -25,6 +27,11 @@ public interface PythonService extends PythonClass { ImmutableSet DEFAULT_IMPORTS = ImmutableSet.of( + PythonImport.of(PythonClassName.of("typing", "List")), + PythonImport.of(PythonClassName.of("typing", "Set")), + PythonImport.of(PythonClassName.of("typing", "Dict")), + PythonImport.of(PythonClassName.of("typing", "Tuple")), + PythonImport.of(PythonClassName.of("typing", "Optional")), PythonImport.of(PythonClassName.of("conjure_python_client", "ConjureEncoder")), PythonImport.of(PythonClassName.of("conjure_python_client", "ConjureDecoder")), PythonImport.of(PythonClassName.of("conjure_python_client", "Service"))); @@ -35,6 +42,10 @@ default Set requiredImports() { return DEFAULT_IMPORTS; } + String className(); + + Optional docs(); + List endpointDefinitions(); @Override diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonSetup.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonSetup.java index 41135a55f..aefb2c13d 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonSetup.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonSetup.java @@ -19,14 +19,13 @@ public interface PythonSetup extends PythonClass { @Override @Value.Default - default String className() { - return ""; + default Set requiredImports() { + return DEFAULT_IMPORTS; } @Override - @Value.Default - default Set requiredImports() { - return DEFAULT_IMPORTS; + default String packageName() { + return ""; } Map options(); diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonUnionTypeDefinition.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonUnionTypeDefinition.java index 1f58531da..ee80ef8fe 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonUnionTypeDefinition.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonUnionTypeDefinition.java @@ -19,7 +19,9 @@ import com.google.common.base.Joiner; import com.google.common.collect.ImmutableSet; import com.palantir.conjure.python.poet.PythonBean.PythonField; +import com.palantir.conjure.spec.Documentation; import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import org.immutables.value.Value; @@ -28,8 +30,13 @@ public interface PythonUnionTypeDefinition extends PythonClass { ImmutableSet DEFAULT_IMPORTS = ImmutableSet.of( - PythonImport.of(PythonClassName.of("conjure_python_client", "ConjureUnionType")), - PythonImport.of(PythonClassName.of("conjure_python_client", "ConjureFieldDefinition"))); + PythonImport.of(PythonClassName.of("typing", "List")), + PythonImport.of(PythonClassName.of("typing", "Set")), + PythonImport.of(PythonClassName.of("typing", "Dict")), + PythonImport.of(PythonClassName.of("typing", "Tuple")), + PythonImport.of(PythonClassName.of("typing", "Optional")), + PythonImport.of(PythonClassName.of("conjure_python_client", "*"))); + @Override @Value.Default @@ -37,6 +44,13 @@ default Set requiredImports() { return DEFAULT_IMPORTS; } + String className(); + + Optional docs(); + + /** + * The options in the union. + */ List options(); @Override diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/types/DefaultBeanGeneratorPython.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/types/DefaultBeanGenerator.java similarity index 51% rename from conjure-python-core/src/main/java/com/palantir/conjure/python/types/DefaultBeanGeneratorPython.java rename to conjure-python-core/src/main/java/com/palantir/conjure/python/types/DefaultBeanGenerator.java index 069b2c2ce..0876821a2 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/types/DefaultBeanGeneratorPython.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/types/DefaultBeanGenerator.java @@ -16,98 +16,65 @@ package com.palantir.conjure.python.types; +import com.google.common.collect.ImmutableSet; import com.palantir.conjure.python.PackageNameProcessor; -import com.palantir.conjure.python.PythonFileGenerator; import com.palantir.conjure.python.poet.PythonAlias; import com.palantir.conjure.python.poet.PythonBean; import com.palantir.conjure.python.poet.PythonBean.PythonField; +import com.palantir.conjure.python.poet.PythonClass; import com.palantir.conjure.python.poet.PythonEnum; import com.palantir.conjure.python.poet.PythonEnum.PythonEnumValue; -import com.palantir.conjure.python.poet.PythonFile; import com.palantir.conjure.python.poet.PythonImport; import com.palantir.conjure.python.poet.PythonUnionTypeDefinition; import com.palantir.conjure.python.util.CaseConverter; -import com.palantir.conjure.python.util.ImportsVisitor; import com.palantir.conjure.spec.AliasDefinition; import com.palantir.conjure.spec.EnumDefinition; import com.palantir.conjure.spec.ObjectDefinition; import com.palantir.conjure.spec.Type; import com.palantir.conjure.spec.TypeDefinition; -import com.palantir.conjure.spec.TypeName; import com.palantir.conjure.spec.UnionDefinition; import com.palantir.conjure.visitor.TypeDefinitionVisitor; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -public final class DefaultBeanGeneratorPython implements PythonFileGenerator { +public final class DefaultBeanGenerator implements PythonBeanGenerator { + + // TODO(qchen): remove? + private final Set enabledExperimentalFeatures; + + public DefaultBeanGenerator(Set enabledExperimentalFeatures) { + this.enabledExperimentalFeatures = ImmutableSet.copyOf(enabledExperimentalFeatures); + } @Override - public PythonFile generateFile( - Map types, + public PythonClass generateObject(List types, PackageNameProcessor packageNameProcessor, TypeDefinition typeDef) { if (typeDef.accept(TypeDefinitionVisitor.IS_OBJECT)) { return generateObject(types, packageNameProcessor, typeDef.accept(TypeDefinitionVisitor.OBJECT)); } else if (typeDef.accept(TypeDefinitionVisitor.IS_ENUM)) { - return generateEnum(packageNameProcessor, typeDef.accept(TypeDefinitionVisitor.ENUM)); + return generateObject(packageNameProcessor, typeDef.accept(TypeDefinitionVisitor.ENUM)); } else if (typeDef.accept(TypeDefinitionVisitor.IS_UNION)) { - return generateUnion(types, packageNameProcessor, typeDef.accept(TypeDefinitionVisitor.UNION)); + return generateObject(types, packageNameProcessor, typeDef.accept(TypeDefinitionVisitor.UNION)); } else if (typeDef.accept(TypeDefinitionVisitor.IS_ALIAS)) { - return generateAlias(types, packageNameProcessor, typeDef.accept(TypeDefinitionVisitor.ALIAS)); + return generateObject(types, packageNameProcessor, typeDef.accept(TypeDefinitionVisitor.ALIAS)); } else { throw new UnsupportedOperationException("cannot generate type for type def: " + typeDef); } } - private PythonFile generateObject( - Map types, + private PythonClass generateObject( + List types, PackageNameProcessor packageNameProcessor, - ObjectDefinition typeDef) { - - ImportsVisitor importsVisitor = new ImportsVisitor(typeDef.getTypeName(), packageNameProcessor, types); - TypeMapper mapper = new TypeMapper(new DefaultTypeNameVisitor(types.keySet())); - TypeMapper myPyMapper = new TypeMapper(new MyPyTypeNameVisitor(types.keySet())); - String packageName = packageNameProcessor.getPackageName(typeDef.getTypeName().getPackage()); - - Set imports = typeDef.getFields() - .stream() - .flatMap(entry -> entry.getType().accept(importsVisitor).stream()) - .collect(Collectors.toSet()); - - List fields = typeDef.getFields() - .stream() - .map(entry -> PythonField.builder() - .attributeName(CaseConverter.toCase( - entry.getFieldName().get(), CaseConverter.Case.SNAKE_CASE)) - .jsonIdentifier(entry.getFieldName().get()) - .docs(entry.getDocs()) - .pythonType(mapper.getTypeName(entry.getType())) - .myPyType(myPyMapper.getTypeName(entry.getType())) - .build()) - .collect(Collectors.toList()); + UnionDefinition typeDef) { - return PythonFile.builder() - .fileName(String.format("%s.py", typeDef.getTypeName().getName())) - .imports(imports) - .packageName(packageName) - .addContents(PythonBean.builder() - .className(typeDef.getTypeName().getName()) - .docs(typeDef.getDocs()) - .fields(fields) - .build()) - .build(); - } + TypeMapper mapper = new TypeMapper(new DefaultTypeNameVisitor(types)); + TypeMapper myPyMapper = new TypeMapper(new MyPyTypeNameVisitor(types)); - private PythonFile generateUnion( - Map types, - PackageNameProcessor packageNameProcessor, - UnionDefinition typeDef) { + ReferencedTypeNameVisitor referencedTypeNameVisitor = new ReferencedTypeNameVisitor( + types, packageNameProcessor); - ImportsVisitor importsVisitor = new ImportsVisitor(typeDef.getTypeName(), packageNameProcessor, types); - TypeMapper mapper = new TypeMapper(new DefaultTypeNameVisitor(types.keySet())); - TypeMapper myPyMapper = new TypeMapper(new MyPyTypeNameVisitor(types.keySet())); String packageName = packageNameProcessor.getPackageName(typeDef.getTypeName().getPackage()); List options = typeDef.getUnion() @@ -127,56 +94,93 @@ private PythonFile generateUnion( Set imports = typeDef.getUnion() .stream() - .flatMap(entry -> entry.getType().accept(importsVisitor).stream()) + .flatMap(entry -> entry.getType().accept(referencedTypeNameVisitor).stream()) + .filter(entry -> !entry.conjurePackage().equals(packageName)) // don't need to import if in this file + .map(referencedClassName -> PythonImport.of(referencedClassName, packageName)) .collect(Collectors.toSet()); - return PythonFile.builder() - .fileName(String.format("%s.py", typeDef.getTypeName().getName())) - .imports(imports) + return PythonUnionTypeDefinition.builder() .packageName(packageName) - .addContents( - PythonUnionTypeDefinition.builder() - .className(typeDef.getTypeName().getName()) - .docs(typeDef.getDocs()) - .addAllOptions(options) - .build()) + .className(typeDef.getTypeName().getName()) + .docs(typeDef.getDocs()) + .addAllOptions(options) + .addAllRequiredImports(imports) .build(); } - private PythonFile generateEnum(PackageNameProcessor packageNameProcessor, EnumDefinition typeDef) { + private PythonEnum generateObject(PackageNameProcessor packageNameProcessor, EnumDefinition typeDef) { String packageName = packageNameProcessor.getPackageName(typeDef.getTypeName().getPackage()); - return PythonFile.builder() - .fileName(String.format("%s.py", typeDef.getTypeName().getName())) + return PythonEnum.builder() .packageName(packageName) - .addContents(PythonEnum.builder() - .className(typeDef.getTypeName().getName()) - .docs(typeDef.getDocs()) - .values(typeDef.getValues().stream() - .map(value -> PythonEnumValue.of(value.getValue(), value.getDocs())) - .collect(Collectors.toList())) - .build()) + .className(typeDef.getTypeName().getName()) + .docs(typeDef.getDocs()) + .values(typeDef.getValues().stream() + .map(value -> PythonEnumValue.of(value.getValue(), value.getDocs())) + .collect(Collectors.toList())) .build(); } - private PythonFile generateAlias( - Map types, + private PythonBean generateObject( + List types, PackageNameProcessor packageNameProcessor, - AliasDefinition typeDef) { + ObjectDefinition typeDef) { + + TypeMapper mapper = new TypeMapper(new DefaultTypeNameVisitor(types)); + TypeMapper myPyMapper = new TypeMapper(new MyPyTypeNameVisitor(types)); + ReferencedTypeNameVisitor referencedTypeNameVisitor = new ReferencedTypeNameVisitor( + types, packageNameProcessor); - ImportsVisitor importsVisitor = new ImportsVisitor(typeDef.getTypeName(), packageNameProcessor, types); - TypeMapper mapper = new TypeMapper(new DefaultTypeNameVisitor(types.keySet())); String packageName = packageNameProcessor.getPackageName(typeDef.getTypeName().getPackage()); - return PythonFile.builder() - .fileName(String.format("%s.py", typeDef.getTypeName().getName())) - .imports(typeDef.getAlias().accept(importsVisitor)) + Set imports = typeDef.getFields() + .stream() + .flatMap(entry -> entry.getType().accept(referencedTypeNameVisitor).stream()) + .filter(entry -> !entry.conjurePackage().equals(packageName)) // don't need to import if in this file + .map(referencedClassName -> PythonImport.of(referencedClassName, packageName)) + .collect(Collectors.toSet()); + + return PythonBean.builder() + .packageName(packageName) + .addAllRequiredImports(PythonBean.DEFAULT_IMPORTS) + .addAllRequiredImports(imports) + .className(typeDef.getTypeName().getName()) + .docs(typeDef.getDocs()) + .fields(typeDef.getFields() + .stream() + .map(entry -> PythonField.builder() + .attributeName(CaseConverter.toCase( + entry.getFieldName().get(), CaseConverter.Case.SNAKE_CASE)) + .jsonIdentifier(entry.getFieldName().get()) + .docs(entry.getDocs()) + .pythonType(mapper.getTypeName(entry.getType())) + .myPyType(myPyMapper.getTypeName(entry.getType())) + .build()) + .collect(Collectors.toList())) + .build(); + } + + private PythonAlias generateObject( + List types, + PackageNameProcessor packageNameProcessor, + AliasDefinition typeDef) { + TypeMapper mapper = new TypeMapper(new DefaultTypeNameVisitor(types)); + ReferencedTypeNameVisitor referencedTypeNameVisitor = new ReferencedTypeNameVisitor( + types, packageNameProcessor); + String packageName = packageNameProcessor.getPackageName(typeDef.getTypeName().getPackage()); + + Set imports = typeDef.getAlias().accept(referencedTypeNameVisitor) + .stream() + .filter(entry -> !entry.conjurePackage().equals(packageName)) // don't need to import if in this file + .map(referencedClassName -> PythonImport.of(referencedClassName, packageName)) + .collect(Collectors.toSet()); + + return PythonAlias.builder() + .aliasName(typeDef.getTypeName().getName()) + .aliasTarget(mapper.getTypeName(typeDef.getAlias())) .packageName(packageName) - .addContents(PythonAlias.builder() - .className(typeDef.getTypeName().getName()) - .aliasTarget(mapper.getTypeName(typeDef.getAlias())) - .build()) + .addAllRequiredImports(imports) .build(); } diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/types/DefaultTypeNameVisitor.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/types/DefaultTypeNameVisitor.java index 2fa20f234..070ee8e62 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/types/DefaultTypeNameVisitor.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/types/DefaultTypeNameVisitor.java @@ -23,17 +23,22 @@ import com.palantir.conjure.spec.PrimitiveType; import com.palantir.conjure.spec.SetType; import com.palantir.conjure.spec.Type; +import com.palantir.conjure.spec.TypeDefinition; import com.palantir.conjure.spec.TypeName; +import com.palantir.conjure.visitor.TypeDefinitionVisitor; import com.palantir.conjure.visitor.TypeVisitor; +import java.util.List; import java.util.Set; +import java.util.stream.Collectors; public final class DefaultTypeNameVisitor implements Type.Visitor { - private Set types; + private final Set typesByName; - public DefaultTypeNameVisitor(Set types) { - this.types = types; + public DefaultTypeNameVisitor(List types) { + this.typesByName = types.stream().map(type -> + type.accept(TypeDefinitionVisitor.TYPE_NAME)).collect(Collectors.toSet()); } @Override @@ -79,7 +84,7 @@ public String visitPrimitive(PrimitiveType type) { @Override public String visitReference(TypeName type) { - if (types.contains(type)) { + if (typesByName.contains(type)) { return type.getName(); } else { throw new IllegalStateException("unknown type: " + type); diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/types/MyPyTypeNameVisitor.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/types/MyPyTypeNameVisitor.java index 0dbcb99be..203a82d26 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/types/MyPyTypeNameVisitor.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/types/MyPyTypeNameVisitor.java @@ -23,19 +23,24 @@ import com.palantir.conjure.spec.PrimitiveType; import com.palantir.conjure.spec.SetType; import com.palantir.conjure.spec.Type; +import com.palantir.conjure.spec.TypeDefinition; import com.palantir.conjure.spec.TypeName; +import com.palantir.conjure.visitor.TypeDefinitionVisitor; import com.palantir.conjure.visitor.TypeVisitor; +import java.util.List; import java.util.Set; +import java.util.stream.Collectors; /** * The mypy type for the conjure type. */ public final class MyPyTypeNameVisitor implements Type.Visitor { - private Set types; + private final Set typesByName; - public MyPyTypeNameVisitor(Set types) { - this.types = types; + public MyPyTypeNameVisitor(List types) { + this.typesByName = types.stream().map(type -> + type.accept(TypeDefinitionVisitor.TYPE_NAME)).collect(Collectors.toSet()); } @Override @@ -81,7 +86,7 @@ public String visitPrimitive(PrimitiveType type) { @Override public String visitReference(TypeName type) { // Types without namespace are either defined locally in this conjure definition, or raw imports. - if (types.contains(type)) { + if (typesByName.contains(type)) { return type.getName(); } else { throw new IllegalArgumentException("unknown type: " + type); diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/types/PythonBeanGenerator.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/types/PythonBeanGenerator.java new file mode 100644 index 000000000..ad3737f40 --- /dev/null +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/types/PythonBeanGenerator.java @@ -0,0 +1,33 @@ +/* + * (c) Copyright 2018 Palantir Technologies Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.palantir.conjure.python.types; + +import com.palantir.conjure.python.PackageNameProcessor; +import com.palantir.conjure.python.poet.PythonClass; +import com.palantir.conjure.spec.TypeDefinition; +import java.util.List; + +public interface PythonBeanGenerator { + + enum ExperimentalFeatures {} + + PythonClass generateObject( + List types, + PackageNameProcessor packageNameProvider, + TypeDefinition typeDef); + +} diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/util/ImportsVisitor.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/util/ImportsVisitor.java deleted file mode 100644 index 2989df3d1..000000000 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/util/ImportsVisitor.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * (c) Copyright 2018 Palantir Technologies Inc. All rights reserved. - */ - -package com.palantir.conjure.python.util; - -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableSet; -import com.palantir.conjure.python.PackageNameProcessor; -import com.palantir.conjure.python.poet.PythonClassName; -import com.palantir.conjure.python.poet.PythonImport; -import com.palantir.conjure.spec.ExternalReference; -import com.palantir.conjure.spec.ListType; -import com.palantir.conjure.spec.MapType; -import com.palantir.conjure.spec.OptionalType; -import com.palantir.conjure.spec.PrimitiveType; -import com.palantir.conjure.spec.SetType; -import com.palantir.conjure.spec.Type; -import com.palantir.conjure.spec.TypeDefinition; -import com.palantir.conjure.spec.TypeName; -import java.util.Collections; -import java.util.Map; -import java.util.Set; - -public final class ImportsVisitor implements Type.Visitor> { - private TypeName currentType; - private PackageNameProcessor packageNameProcessor; - private Map knownTypes; - - public ImportsVisitor( - TypeName currentType, - PackageNameProcessor packageNameProcessor, - Map knownTypes) { - this.currentType = currentType; - this.packageNameProcessor = packageNameProcessor; - this.knownTypes = knownTypes; - } - - @Override - public Set visitPrimitive(PrimitiveType value) { - if (value.equals(PrimitiveType.ANY)) { - return ImmutableSet.of(PythonImport.of(PythonClassName.of("typing", "Any"))); - } else if (value.equals(PrimitiveType.BINARY)) { - return ImmutableSet.of(PythonImport.of(PythonClassName.of("conjure_python_client", "BinaryType"))); - } - return Collections.emptySet(); - } - - @Override - public Set visitOptional(OptionalType value) { - ImmutableSet.Builder setBuilder = ImmutableSet.builder(); - return setBuilder - .add(PythonImport.of(PythonClassName.of("typing", "Optional"))) - .add(PythonImport.of(PythonClassName.of("conjure_python_client", "OptionalType"))) - .addAll(value.getItemType().accept(this)) - .build(); - } - - @Override - public Set visitList(ListType value) { - ImmutableSet.Builder setBuilder = ImmutableSet.builder(); - return setBuilder - .add(PythonImport.of(PythonClassName.of("typing", "List"))) - .add(PythonImport.of(PythonClassName.of("conjure_python_client", "ListType"))) - .addAll(value.getItemType().accept(this)) - .build(); - } - - @Override - public Set visitSet(SetType value) { - ImmutableSet.Builder setBuilder = ImmutableSet.builder(); - return setBuilder - .add(PythonImport.of(PythonClassName.of("typing", "Set"))) - .add(PythonImport.of(PythonClassName.of("conjure_python_client", "ListType"))) - .addAll(value.getItemType().accept(this)) - .build(); - } - - @Override - public Set visitMap(MapType value) { - ImmutableSet.Builder setBuilder = ImmutableSet.builder(); - return setBuilder - .add(PythonImport.of(PythonClassName.of("typing", "Dict"))) - .add(PythonImport.of(PythonClassName.of("conjure_python_client", "DictType"))) - .addAll(value.getKeyType().accept(this)) - .addAll(value.getValueType().accept(this)) - .build(); - } - - @Override - public Set visitReference(TypeName value) { - Preconditions.checkState(knownTypes.containsKey(value), "Unknown TypeName %s", value); - return ImmutableSet.of(PythonImport.of( - PythonClassName.of(getRelativePath(value), value.getName()))); - } - - @Override - public Set visitExternal(ExternalReference value) { - // TODO(forozco): handle python external references - return Collections.emptySet(); - } - - @Override - public Set visitUnknown(String unknownType) { - return Collections.emptySet(); - } - - private String getRelativePath(TypeName targetType) { - if (targetType.getPackage().equals(currentType.getPackage())) { - return String.format(".%s", targetType.getName()); - } else { - String targetPackageName = packageNameProcessor.getPackageName(targetType.getPackage()).split("\\.")[1]; - return String.format("..%s.%s", targetPackageName, targetType.getName()); - } - } -} diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/util/TypeNameVisitor.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/util/TypeNameVisitor.java deleted file mode 100644 index 90e5f1be7..000000000 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/util/TypeNameVisitor.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * (c) Copyright 2018 Palantir Technologies Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.palantir.conjure.python.util; - -import com.palantir.conjure.spec.AliasDefinition; -import com.palantir.conjure.spec.EnumDefinition; -import com.palantir.conjure.spec.ObjectDefinition; -import com.palantir.conjure.spec.TypeDefinition; -import com.palantir.conjure.spec.TypeName; -import com.palantir.conjure.spec.UnionDefinition; - -public final class TypeNameVisitor implements TypeDefinition.Visitor { - - public TypeNameVisitor() { - } - - @Override - public TypeName visitAlias(AliasDefinition value) { - return value.getTypeName(); - } - - @Override - public TypeName visitEnum(EnumDefinition value) { - return value.getTypeName(); - } - - @Override - public TypeName visitObject(ObjectDefinition value) { - return value.getTypeName(); - } - - @Override - public TypeName visitUnion(UnionDefinition value) { - return value.getTypeName(); - } - - @Override - public TypeName visitUnknown(String unknownType) { - throw new RuntimeException(String.format("Unknown type definition: %s", unknownType)); - } -} diff --git a/conjure-python-core/src/test/java/com/palantir/conjure/python/ConjurePythonGeneratorTest.java b/conjure-python-core/src/test/java/com/palantir/conjure/python/ConjurePythonGeneratorTest.java index cd847ebd0..c22b2ec18 100644 --- a/conjure-python-core/src/test/java/com/palantir/conjure/python/ConjurePythonGeneratorTest.java +++ b/conjure-python-core/src/test/java/com/palantir/conjure/python/ConjurePythonGeneratorTest.java @@ -18,9 +18,10 @@ import static org.assertj.core.api.Assertions.assertThat; +import com.google.common.collect.ImmutableSet; import com.palantir.conjure.defs.Conjure; -import com.palantir.conjure.python.service.ServiceGeneratorPython; -import com.palantir.conjure.python.types.DefaultBeanGeneratorPython; +import com.palantir.conjure.python.client.ClientGenerator; +import com.palantir.conjure.python.types.DefaultBeanGenerator; import com.palantir.conjure.spec.ConjureDefinition; import java.io.File; import java.io.IOException; @@ -38,7 +39,7 @@ public final class ConjurePythonGeneratorTest { private final ConjurePythonGenerator generator = new ConjurePythonGenerator( - new DefaultBeanGeneratorPython(), new ServiceGeneratorPython(), + new DefaultBeanGenerator(ImmutableSet.of()), new ClientGenerator(), GeneratorConfiguration.builder() .packageName("package") .packageVersion("0.0.0") diff --git a/conjure-python-core/src/test/resources/services/expected/conda_recipe/meta.yaml b/conjure-python-core/src/test/resources/services/expected/conda_recipe/meta.yaml index 3a7e708c4..7adff9bff 100644 --- a/conjure-python-core/src/test/resources/services/expected/conda_recipe/meta.yaml +++ b/conjure-python-core/src/test/resources/services/expected/conda_recipe/meta.yaml @@ -1,3 +1,4 @@ +# this is package conda_recipe package: name: package diff --git a/conjure-python-core/src/test/resources/services/expected/package/__init__.py b/conjure-python-core/src/test/resources/services/expected/package/__init__.py index 01cb8dacd..2e28a192d 100644 --- a/conjure-python-core/src/test/resources/services/expected/package/__init__.py +++ b/conjure-python-core/src/test/resources/services/expected/package/__init__.py @@ -1,3 +1,4 @@ +# this is package package __all__ = [ 'another', diff --git a/conjure-python-core/src/test/resources/services/expected/package/another/TestService.py b/conjure-python-core/src/test/resources/services/expected/package/another/TestService.py deleted file mode 100644 index 9ae77a28a..000000000 --- a/conjure-python-core/src/test/resources/services/expected/package/another/TestService.py +++ /dev/null @@ -1,439 +0,0 @@ -from ..product.CreateDatasetRequest import CreateDatasetRequest -from ..product_datasets.BackingFileSystem import BackingFileSystem -from ..product_datasets.Dataset import Dataset -from conjure_python_client import BinaryType -from conjure_python_client import ConjureDecoder -from conjure_python_client import ConjureEncoder -from conjure_python_client import DictType -from conjure_python_client import ListType -from conjure_python_client import OptionalType -from conjure_python_client import Service -from typing import Dict -from typing import Optional -from typing import Set - -class TestService(Service): - """A Markdown description of the service.""" - - def get_file_systems(self, auth_header): - # type: (str) -> Dict[str, BackingFileSystem] - """Returns a mapping from file system id to backing file system configuration.""" - - _headers = { - 'Accept': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/fileSystems' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), DictType(str, BackingFileSystem)) - - def create_dataset(self, auth_header, request, test_header_arg): - # type: (str, CreateDatasetRequest, str) -> Dataset - - _headers = { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - 'Authorization': auth_header, - 'Test-Header': test_header_arg, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - } # type: Dict[str, Any] - - _json = ConjureEncoder().default(request) # type: Any - - _path = '/catalog/datasets' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'POST', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), Dataset) - - def get_dataset(self, auth_header, dataset_rid): - # type: (str, str) -> Optional[Dataset] - - _headers = { - 'Accept': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - 'datasetRid': dataset_rid, - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/datasets/{datasetRid}' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), OptionalType(Dataset)) - - def get_raw_data(self, auth_header, dataset_rid): - # type: (str, str) -> Any - - _headers = { - 'Accept': 'application/octet-stream', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - 'datasetRid': dataset_rid, - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/datasets/{datasetRid}/raw' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - stream=True, - json=_json) - - _raw = _response.raw - _raw.decode_content = True - return _raw - - def maybe_get_raw_data(self, auth_header, dataset_rid): - # type: (str, str) -> Optional[Any] - - _headers = { - 'Accept': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - 'datasetRid': dataset_rid, - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/datasets/{datasetRid}/raw-maybe' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), OptionalType(BinaryType())) - - def upload_raw_data(self, auth_header, input): - # type: (str, Any) -> None - - _headers = { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - } # type: Dict[str, Any] - - _json = ConjureEncoder().default(input) # type: Any - - _path = '/catalog/datasets/upload-raw' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'POST', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - return - - def get_branches(self, auth_header, dataset_rid): - # type: (str, str) -> List[str] - - _headers = { - 'Accept': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - 'datasetRid': dataset_rid, - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/datasets/{datasetRid}/branches' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), ListType(str)) - - def get_branches_deprecated(self, auth_header, dataset_rid): - # type: (str, str) -> List[str] - """Gets all branches of this dataset.""" - - _headers = { - 'Accept': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - 'datasetRid': dataset_rid, - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/datasets/{datasetRid}/branchesDeprecated' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), ListType(str)) - - def resolve_branch(self, auth_header, dataset_rid, branch): - # type: (str, str, str) -> Optional[str] - - _headers = { - 'Accept': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - 'datasetRid': dataset_rid, - 'branch': branch, - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/datasets/{datasetRid}/branches/{branch}/resolve' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), OptionalType(str)) - - def test_param(self, auth_header, dataset_rid): - # type: (str, str) -> Optional[str] - - _headers = { - 'Accept': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - 'datasetRid': dataset_rid, - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/datasets/{datasetRid}/testParam' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), OptionalType(str)) - - def test_query_params(self, auth_header, something, implicit): - # type: (str, str, str) -> int - - _headers = { - 'Accept': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - 'different': something, - 'implicit': implicit, - } # type: Dict[str, Any] - - _path_params = { - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/test-query-params' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), int) - - def test_boolean(self, auth_header): - # type: (str) -> bool - - _headers = { - 'Accept': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/boolean' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), bool) - - def test_double(self, auth_header): - # type: (str) -> float - - _headers = { - 'Accept': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/double' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), float) - - def test_integer(self, auth_header): - # type: (str) -> int - - _headers = { - 'Accept': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/integer' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), int) - diff --git a/conjure-python-core/src/test/resources/services/expected/package/another/__init__.py b/conjure-python-core/src/test/resources/services/expected/package/another/__init__.py index 5465497e8..28d87d22e 100644 --- a/conjure-python-core/src/test/resources/services/expected/package/another/__init__.py +++ b/conjure-python-core/src/test/resources/services/expected/package/another/__init__.py @@ -1,6 +1,438 @@ -from .TestService import TestService +# this is package package.another +from ..product import CreateDatasetRequest +from ..product_datasets import BackingFileSystem +from ..product_datasets import Dataset +from conjure_python_client import ConjureDecoder +from conjure_python_client import ConjureEncoder +from conjure_python_client import Service +from typing import Dict +from typing import List +from typing import Optional +from typing import Set +from typing import Tuple -__all__ = [ - 'TestService', -] +class TestService(Service): + """A Markdown description of the service.""" + + def get_file_systems(self, auth_header): + # type: (str) -> Dict[str, BackingFileSystem] + """Returns a mapping from file system id to backing file system configuration.""" + + _headers = { + 'Accept': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/fileSystems' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), DictType(str, BackingFileSystem)) + + def create_dataset(self, auth_header, request, test_header_arg): + # type: (str, CreateDatasetRequest, str) -> Dataset + + _headers = { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Authorization': auth_header, + 'Test-Header': test_header_arg, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + } # type: Dict[str, Any] + + _json = ConjureEncoder().default(request) # type: Any + + _path = '/catalog/datasets' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'POST', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), Dataset) + + def get_dataset(self, auth_header, dataset_rid): + # type: (str, str) -> Optional[Dataset] + + _headers = { + 'Accept': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + 'datasetRid': dataset_rid, + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/datasets/{datasetRid}' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), OptionalType(Dataset)) + + def get_raw_data(self, auth_header, dataset_rid): + # type: (str, str) -> Any + + _headers = { + 'Accept': 'application/octet-stream', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + 'datasetRid': dataset_rid, + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/datasets/{datasetRid}/raw' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + stream=True, + json=_json) + + _raw = _response.raw + _raw.decode_content = True + return _raw + + def maybe_get_raw_data(self, auth_header, dataset_rid): + # type: (str, str) -> Optional[Any] + + _headers = { + 'Accept': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + 'datasetRid': dataset_rid, + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/datasets/{datasetRid}/raw-maybe' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), OptionalType(BinaryType())) + + def upload_raw_data(self, auth_header, input): + # type: (str, Any) -> None + + _headers = { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + } # type: Dict[str, Any] + + _json = ConjureEncoder().default(input) # type: Any + + _path = '/catalog/datasets/upload-raw' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'POST', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + return + + def get_branches(self, auth_header, dataset_rid): + # type: (str, str) -> List[str] + + _headers = { + 'Accept': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + 'datasetRid': dataset_rid, + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/datasets/{datasetRid}/branches' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), ListType(str)) + + def get_branches_deprecated(self, auth_header, dataset_rid): + # type: (str, str) -> List[str] + """Gets all branches of this dataset.""" + + _headers = { + 'Accept': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + 'datasetRid': dataset_rid, + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/datasets/{datasetRid}/branchesDeprecated' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), ListType(str)) + + def resolve_branch(self, auth_header, dataset_rid, branch): + # type: (str, str, str) -> Optional[str] + + _headers = { + 'Accept': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + 'datasetRid': dataset_rid, + 'branch': branch, + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/datasets/{datasetRid}/branches/{branch}/resolve' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), OptionalType(str)) + + def test_param(self, auth_header, dataset_rid): + # type: (str, str) -> Optional[str] + + _headers = { + 'Accept': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + 'datasetRid': dataset_rid, + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/datasets/{datasetRid}/testParam' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), OptionalType(str)) + + def test_query_params(self, auth_header, something, implicit): + # type: (str, str, str) -> int + + _headers = { + 'Accept': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + 'different': something, + 'implicit': implicit, + } # type: Dict[str, Any] + + _path_params = { + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/test-query-params' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), int) + + def test_boolean(self, auth_header): + # type: (str) -> bool + + _headers = { + 'Accept': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/boolean' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), bool) + + def test_double(self, auth_header): + # type: (str) -> float + + _headers = { + 'Accept': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/double' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), float) + + def test_integer(self, auth_header): + # type: (str) -> int + + _headers = { + 'Accept': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/integer' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), int) diff --git a/conjure-python-core/src/test/resources/services/expected/package/product/CreateDatasetRequest.py b/conjure-python-core/src/test/resources/services/expected/package/product/CreateDatasetRequest.py deleted file mode 100644 index 2287738ae..000000000 --- a/conjure-python-core/src/test/resources/services/expected/package/product/CreateDatasetRequest.py +++ /dev/null @@ -1,31 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition - -class CreateDatasetRequest(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'file_system_id': ConjureFieldDefinition('fileSystemId', str), - 'path': ConjureFieldDefinition('path', str) - } - - _file_system_id = None # type: str - _path = None # type: str - - def __init__(self, file_system_id, path): - # type: (str, str) -> None - self._file_system_id = file_system_id - self._path = path - - @property - def file_system_id(self): - # type: () -> str - return self._file_system_id - - @property - def path(self): - # type: () -> str - return self._path - diff --git a/conjure-python-core/src/test/resources/services/expected/package/product/__init__.py b/conjure-python-core/src/test/resources/services/expected/package/product/__init__.py index b8c6d0f3d..90d9104f7 100644 --- a/conjure-python-core/src/test/resources/services/expected/package/product/__init__.py +++ b/conjure-python-core/src/test/resources/services/expected/package/product/__init__.py @@ -1,6 +1,37 @@ -from .CreateDatasetRequest import CreateDatasetRequest +# this is package package.product +from conjure_python_client import ConjureBeanType +from conjure_python_client import ConjureFieldDefinition +from typing import Dict +from typing import List +from typing import Optional +from typing import Set +from typing import Tuple -__all__ = [ - 'CreateDatasetRequest', -] +class CreateDatasetRequest(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'file_system_id': ConjureFieldDefinition('fileSystemId', str), + 'path': ConjureFieldDefinition('path', str) + } + + _file_system_id = None # type: str + _path = None # type: str + + def __init__(self, file_system_id, path): + # type: (str, str) -> None + self._file_system_id = file_system_id + self._path = path + + @property + def file_system_id(self): + # type: () -> str + return self._file_system_id + + @property + def path(self): + # type: () -> str + return self._path diff --git a/conjure-python-core/src/test/resources/services/expected/package/product_datasets/BackingFileSystem.py b/conjure-python-core/src/test/resources/services/expected/package/product_datasets/BackingFileSystem.py deleted file mode 100644 index 5284e7f0a..000000000 --- a/conjure-python-core/src/test/resources/services/expected/package/product_datasets/BackingFileSystem.py +++ /dev/null @@ -1,42 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition -from conjure_python_client import DictType -from typing import Dict - -class BackingFileSystem(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'file_system_id': ConjureFieldDefinition('fileSystemId', str), - 'base_uri': ConjureFieldDefinition('baseUri', str), - 'configuration': ConjureFieldDefinition('configuration', DictType(str, str)) - } - - _file_system_id = None # type: str - _base_uri = None # type: str - _configuration = None # type: Dict[str, str] - - def __init__(self, file_system_id, base_uri, configuration): - # type: (str, str, Dict[str, str]) -> None - self._file_system_id = file_system_id - self._base_uri = base_uri - self._configuration = configuration - - @property - def file_system_id(self): - # type: () -> str - """The name by which this file system is identified.""" - return self._file_system_id - - @property - def base_uri(self): - # type: () -> str - return self._base_uri - - @property - def configuration(self): - # type: () -> Dict[str, str] - return self._configuration - diff --git a/conjure-python-core/src/test/resources/services/expected/package/product_datasets/Dataset.py b/conjure-python-core/src/test/resources/services/expected/package/product_datasets/Dataset.py deleted file mode 100644 index 37b5cbc04..000000000 --- a/conjure-python-core/src/test/resources/services/expected/package/product_datasets/Dataset.py +++ /dev/null @@ -1,32 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition - -class Dataset(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'file_system_id': ConjureFieldDefinition('fileSystemId', str), - 'rid': ConjureFieldDefinition('rid', str) - } - - _file_system_id = None # type: str - _rid = None # type: str - - def __init__(self, file_system_id, rid): - # type: (str, str) -> None - self._file_system_id = file_system_id - self._rid = rid - - @property - def file_system_id(self): - # type: () -> str - return self._file_system_id - - @property - def rid(self): - # type: () -> str - """Uniquely identifies this dataset.""" - return self._rid - diff --git a/conjure-python-core/src/test/resources/services/expected/package/product_datasets/__init__.py b/conjure-python-core/src/test/resources/services/expected/package/product_datasets/__init__.py index abadae157..ee217316b 100644 --- a/conjure-python-core/src/test/resources/services/expected/package/product_datasets/__init__.py +++ b/conjure-python-core/src/test/resources/services/expected/package/product_datasets/__init__.py @@ -1,8 +1,75 @@ -from .BackingFileSystem import BackingFileSystem -from .Dataset import Dataset +# this is package package.product_datasets +from conjure_python_client import ConjureBeanType +from conjure_python_client import ConjureFieldDefinition +from typing import Dict +from typing import List +from typing import Optional +from typing import Set +from typing import Tuple -__all__ = [ - 'BackingFileSystem', - 'Dataset', -] +class BackingFileSystem(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'file_system_id': ConjureFieldDefinition('fileSystemId', str), + 'base_uri': ConjureFieldDefinition('baseUri', str), + 'configuration': ConjureFieldDefinition('configuration', DictType(str, str)) + } + + _file_system_id = None # type: str + _base_uri = None # type: str + _configuration = None # type: Dict[str, str] + + def __init__(self, file_system_id, base_uri, configuration): + # type: (str, str, Dict[str, str]) -> None + self._file_system_id = file_system_id + self._base_uri = base_uri + self._configuration = configuration + + @property + def file_system_id(self): + # type: () -> str + """The name by which this file system is identified.""" + return self._file_system_id + + @property + def base_uri(self): + # type: () -> str + return self._base_uri + + @property + def configuration(self): + # type: () -> Dict[str, str] + return self._configuration + +class Dataset(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'file_system_id': ConjureFieldDefinition('fileSystemId', str), + 'rid': ConjureFieldDefinition('rid', str) + } + + _file_system_id = None # type: str + _rid = None # type: str + + def __init__(self, file_system_id, rid): + # type: (str, str) -> None + self._file_system_id = file_system_id + self._rid = rid + + @property + def file_system_id(self): + # type: () -> str + return self._file_system_id + + @property + def rid(self): + # type: () -> str + """Uniquely identifies this dataset.""" + return self._rid diff --git a/conjure-python-core/src/test/resources/types/expected/conda_recipe/meta.yaml b/conjure-python-core/src/test/resources/types/expected/conda_recipe/meta.yaml index 3a7e708c4..7adff9bff 100644 --- a/conjure-python-core/src/test/resources/types/expected/conda_recipe/meta.yaml +++ b/conjure-python-core/src/test/resources/types/expected/conda_recipe/meta.yaml @@ -1,3 +1,4 @@ +# this is package conda_recipe package: name: package diff --git a/conjure-python-core/src/test/resources/types/expected/package/__init__.py b/conjure-python-core/src/test/resources/types/expected/package/__init__.py index 023153a0b..8e4c79897 100644 --- a/conjure-python-core/src/test/resources/types/expected/package/__init__.py +++ b/conjure-python-core/src/test/resources/types/expected/package/__init__.py @@ -1,3 +1,4 @@ +# this is package package __all__ = [ 'another', diff --git a/conjure-python-core/src/test/resources/types/expected/package/another/TestService.py b/conjure-python-core/src/test/resources/types/expected/package/another/TestService.py deleted file mode 100644 index 9ae77a28a..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/another/TestService.py +++ /dev/null @@ -1,439 +0,0 @@ -from ..product.CreateDatasetRequest import CreateDatasetRequest -from ..product_datasets.BackingFileSystem import BackingFileSystem -from ..product_datasets.Dataset import Dataset -from conjure_python_client import BinaryType -from conjure_python_client import ConjureDecoder -from conjure_python_client import ConjureEncoder -from conjure_python_client import DictType -from conjure_python_client import ListType -from conjure_python_client import OptionalType -from conjure_python_client import Service -from typing import Dict -from typing import Optional -from typing import Set - -class TestService(Service): - """A Markdown description of the service.""" - - def get_file_systems(self, auth_header): - # type: (str) -> Dict[str, BackingFileSystem] - """Returns a mapping from file system id to backing file system configuration.""" - - _headers = { - 'Accept': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/fileSystems' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), DictType(str, BackingFileSystem)) - - def create_dataset(self, auth_header, request, test_header_arg): - # type: (str, CreateDatasetRequest, str) -> Dataset - - _headers = { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - 'Authorization': auth_header, - 'Test-Header': test_header_arg, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - } # type: Dict[str, Any] - - _json = ConjureEncoder().default(request) # type: Any - - _path = '/catalog/datasets' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'POST', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), Dataset) - - def get_dataset(self, auth_header, dataset_rid): - # type: (str, str) -> Optional[Dataset] - - _headers = { - 'Accept': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - 'datasetRid': dataset_rid, - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/datasets/{datasetRid}' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), OptionalType(Dataset)) - - def get_raw_data(self, auth_header, dataset_rid): - # type: (str, str) -> Any - - _headers = { - 'Accept': 'application/octet-stream', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - 'datasetRid': dataset_rid, - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/datasets/{datasetRid}/raw' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - stream=True, - json=_json) - - _raw = _response.raw - _raw.decode_content = True - return _raw - - def maybe_get_raw_data(self, auth_header, dataset_rid): - # type: (str, str) -> Optional[Any] - - _headers = { - 'Accept': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - 'datasetRid': dataset_rid, - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/datasets/{datasetRid}/raw-maybe' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), OptionalType(BinaryType())) - - def upload_raw_data(self, auth_header, input): - # type: (str, Any) -> None - - _headers = { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - } # type: Dict[str, Any] - - _json = ConjureEncoder().default(input) # type: Any - - _path = '/catalog/datasets/upload-raw' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'POST', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - return - - def get_branches(self, auth_header, dataset_rid): - # type: (str, str) -> List[str] - - _headers = { - 'Accept': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - 'datasetRid': dataset_rid, - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/datasets/{datasetRid}/branches' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), ListType(str)) - - def get_branches_deprecated(self, auth_header, dataset_rid): - # type: (str, str) -> List[str] - """Gets all branches of this dataset.""" - - _headers = { - 'Accept': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - 'datasetRid': dataset_rid, - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/datasets/{datasetRid}/branchesDeprecated' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), ListType(str)) - - def resolve_branch(self, auth_header, dataset_rid, branch): - # type: (str, str, str) -> Optional[str] - - _headers = { - 'Accept': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - 'datasetRid': dataset_rid, - 'branch': branch, - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/datasets/{datasetRid}/branches/{branch}/resolve' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), OptionalType(str)) - - def test_param(self, auth_header, dataset_rid): - # type: (str, str) -> Optional[str] - - _headers = { - 'Accept': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - 'datasetRid': dataset_rid, - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/datasets/{datasetRid}/testParam' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), OptionalType(str)) - - def test_query_params(self, auth_header, something, implicit): - # type: (str, str, str) -> int - - _headers = { - 'Accept': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - 'different': something, - 'implicit': implicit, - } # type: Dict[str, Any] - - _path_params = { - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/test-query-params' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), int) - - def test_boolean(self, auth_header): - # type: (str) -> bool - - _headers = { - 'Accept': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/boolean' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), bool) - - def test_double(self, auth_header): - # type: (str) -> float - - _headers = { - 'Accept': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/double' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), float) - - def test_integer(self, auth_header): - # type: (str) -> int - - _headers = { - 'Accept': 'application/json', - 'Authorization': auth_header, - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - } # type: Dict[str, Any] - - _json = None # type: Any - - _path = '/catalog/integer' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'GET', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), int) - diff --git a/conjure-python-core/src/test/resources/types/expected/package/another/__init__.py b/conjure-python-core/src/test/resources/types/expected/package/another/__init__.py index 5465497e8..28d87d22e 100644 --- a/conjure-python-core/src/test/resources/types/expected/package/another/__init__.py +++ b/conjure-python-core/src/test/resources/types/expected/package/another/__init__.py @@ -1,6 +1,438 @@ -from .TestService import TestService +# this is package package.another +from ..product import CreateDatasetRequest +from ..product_datasets import BackingFileSystem +from ..product_datasets import Dataset +from conjure_python_client import ConjureDecoder +from conjure_python_client import ConjureEncoder +from conjure_python_client import Service +from typing import Dict +from typing import List +from typing import Optional +from typing import Set +from typing import Tuple -__all__ = [ - 'TestService', -] +class TestService(Service): + """A Markdown description of the service.""" + + def get_file_systems(self, auth_header): + # type: (str) -> Dict[str, BackingFileSystem] + """Returns a mapping from file system id to backing file system configuration.""" + + _headers = { + 'Accept': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/fileSystems' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), DictType(str, BackingFileSystem)) + + def create_dataset(self, auth_header, request, test_header_arg): + # type: (str, CreateDatasetRequest, str) -> Dataset + + _headers = { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Authorization': auth_header, + 'Test-Header': test_header_arg, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + } # type: Dict[str, Any] + + _json = ConjureEncoder().default(request) # type: Any + + _path = '/catalog/datasets' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'POST', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), Dataset) + + def get_dataset(self, auth_header, dataset_rid): + # type: (str, str) -> Optional[Dataset] + + _headers = { + 'Accept': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + 'datasetRid': dataset_rid, + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/datasets/{datasetRid}' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), OptionalType(Dataset)) + + def get_raw_data(self, auth_header, dataset_rid): + # type: (str, str) -> Any + + _headers = { + 'Accept': 'application/octet-stream', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + 'datasetRid': dataset_rid, + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/datasets/{datasetRid}/raw' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + stream=True, + json=_json) + + _raw = _response.raw + _raw.decode_content = True + return _raw + + def maybe_get_raw_data(self, auth_header, dataset_rid): + # type: (str, str) -> Optional[Any] + + _headers = { + 'Accept': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + 'datasetRid': dataset_rid, + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/datasets/{datasetRid}/raw-maybe' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), OptionalType(BinaryType())) + + def upload_raw_data(self, auth_header, input): + # type: (str, Any) -> None + + _headers = { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + } # type: Dict[str, Any] + + _json = ConjureEncoder().default(input) # type: Any + + _path = '/catalog/datasets/upload-raw' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'POST', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + return + + def get_branches(self, auth_header, dataset_rid): + # type: (str, str) -> List[str] + + _headers = { + 'Accept': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + 'datasetRid': dataset_rid, + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/datasets/{datasetRid}/branches' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), ListType(str)) + + def get_branches_deprecated(self, auth_header, dataset_rid): + # type: (str, str) -> List[str] + """Gets all branches of this dataset.""" + + _headers = { + 'Accept': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + 'datasetRid': dataset_rid, + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/datasets/{datasetRid}/branchesDeprecated' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), ListType(str)) + + def resolve_branch(self, auth_header, dataset_rid, branch): + # type: (str, str, str) -> Optional[str] + + _headers = { + 'Accept': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + 'datasetRid': dataset_rid, + 'branch': branch, + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/datasets/{datasetRid}/branches/{branch}/resolve' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), OptionalType(str)) + + def test_param(self, auth_header, dataset_rid): + # type: (str, str) -> Optional[str] + + _headers = { + 'Accept': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + 'datasetRid': dataset_rid, + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/datasets/{datasetRid}/testParam' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), OptionalType(str)) + + def test_query_params(self, auth_header, something, implicit): + # type: (str, str, str) -> int + + _headers = { + 'Accept': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + 'different': something, + 'implicit': implicit, + } # type: Dict[str, Any] + + _path_params = { + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/test-query-params' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), int) + + def test_boolean(self, auth_header): + # type: (str) -> bool + + _headers = { + 'Accept': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/boolean' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), bool) + + def test_double(self, auth_header): + # type: (str) -> float + + _headers = { + 'Accept': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/double' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), float) + + def test_integer(self, auth_header): + # type: (str) -> int + + _headers = { + 'Accept': 'application/json', + 'Authorization': auth_header, + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + } # type: Dict[str, Any] + + _json = None # type: Any + + _path = '/catalog/integer' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'GET', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), int) diff --git a/conjure-python-core/src/test/resources/types/expected/package/nested_deeply_nested_service/DeeplyNestedService.py b/conjure-python-core/src/test/resources/types/expected/package/nested_deeply_nested_service/DeeplyNestedService.py deleted file mode 100644 index 03e2a7126..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/nested_deeply_nested_service/DeeplyNestedService.py +++ /dev/null @@ -1,35 +0,0 @@ -from conjure_python_client import ConjureDecoder -from conjure_python_client import ConjureEncoder -from conjure_python_client import Service - -class DeeplyNestedService(Service): - - def test_endpoint(self, string): - # type: (str) -> str - - _headers = { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - } # type: Dict[str, Any] - - _json = ConjureEncoder().default(string) # type: Any - - _path = '/catalog/testEndpoint' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'POST', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), str) - diff --git a/conjure-python-core/src/test/resources/types/expected/package/nested_deeply_nested_service/__init__.py b/conjure-python-core/src/test/resources/types/expected/package/nested_deeply_nested_service/__init__.py index 6e42283a3..a7b9147f0 100644 --- a/conjure-python-core/src/test/resources/types/expected/package/nested_deeply_nested_service/__init__.py +++ b/conjure-python-core/src/test/resources/types/expected/package/nested_deeply_nested_service/__init__.py @@ -1,6 +1,41 @@ -from .DeeplyNestedService import DeeplyNestedService +# this is package package.nested_deeply_nested_service +from conjure_python_client import ConjureDecoder +from conjure_python_client import ConjureEncoder +from conjure_python_client import Service +from typing import Dict +from typing import List +from typing import Optional +from typing import Set +from typing import Tuple -__all__ = [ - 'DeeplyNestedService', -] +class DeeplyNestedService(Service): + + def test_endpoint(self, string): + # type: (str) -> str + + _headers = { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + } # type: Dict[str, Any] + + _json = ConjureEncoder().default(string) # type: Any + + _path = '/catalog/testEndpoint' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'POST', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), str) diff --git a/conjure-python-core/src/test/resources/types/expected/package/nested_service/SimpleNestedService.py b/conjure-python-core/src/test/resources/types/expected/package/nested_service/SimpleNestedService.py deleted file mode 100644 index 26b7b8a9c..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/nested_service/SimpleNestedService.py +++ /dev/null @@ -1,35 +0,0 @@ -from conjure_python_client import ConjureDecoder -from conjure_python_client import ConjureEncoder -from conjure_python_client import Service - -class SimpleNestedService(Service): - - def test_endpoint(self, string): - # type: (str) -> str - - _headers = { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - } # type: Dict[str, Any] - - _json = ConjureEncoder().default(string) # type: Any - - _path = '/catalog/testEndpoint' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'POST', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), str) - diff --git a/conjure-python-core/src/test/resources/types/expected/package/nested_service/SimpleObject.py b/conjure-python-core/src/test/resources/types/expected/package/nested_service/SimpleObject.py deleted file mode 100644 index a27cea9d1..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/nested_service/SimpleObject.py +++ /dev/null @@ -1,23 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition - -class SimpleObject(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'string': ConjureFieldDefinition('string', str) - } - - _string = None # type: str - - def __init__(self, string): - # type: (str) -> None - self._string = string - - @property - def string(self): - # type: () -> str - return self._string - diff --git a/conjure-python-core/src/test/resources/types/expected/package/nested_service/__init__.py b/conjure-python-core/src/test/resources/types/expected/package/nested_service/__init__.py index 53b879d61..921540efa 100644 --- a/conjure-python-core/src/test/resources/types/expected/package/nested_service/__init__.py +++ b/conjure-python-core/src/test/resources/types/expected/package/nested_service/__init__.py @@ -1,8 +1,63 @@ -from .SimpleNestedService import SimpleNestedService -from .SimpleObject import SimpleObject +# this is package package.nested_service +from conjure_python_client import ConjureBeanType +from conjure_python_client import ConjureDecoder +from conjure_python_client import ConjureEncoder +from conjure_python_client import ConjureFieldDefinition +from conjure_python_client import Service +from typing import Dict +from typing import List +from typing import Optional +from typing import Set +from typing import Tuple -__all__ = [ - 'SimpleNestedService', - 'SimpleObject', -] +class SimpleObject(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'string': ConjureFieldDefinition('string', str) + } + + _string = None # type: str + + def __init__(self, string): + # type: (str) -> None + self._string = string + + @property + def string(self): + # type: () -> str + return self._string + +class SimpleNestedService(Service): + + def test_endpoint(self, string): + # type: (str) -> str + + _headers = { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + } # type: Dict[str, Any] + + _json = ConjureEncoder().default(string) # type: Any + + _path = '/catalog/testEndpoint' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'POST', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), str) diff --git a/conjure-python-core/src/test/resources/types/expected/package/nested_service2/SimpleNestedService2.py b/conjure-python-core/src/test/resources/types/expected/package/nested_service2/SimpleNestedService2.py deleted file mode 100644 index 541ca763e..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/nested_service2/SimpleNestedService2.py +++ /dev/null @@ -1,35 +0,0 @@ -from conjure_python_client import ConjureDecoder -from conjure_python_client import ConjureEncoder -from conjure_python_client import Service - -class SimpleNestedService2(Service): - - def test_endpoint(self, string): - # type: (str) -> str - - _headers = { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - } # type: Dict[str, Any] - - _json = ConjureEncoder().default(string) # type: Any - - _path = '/catalog/testEndpoint' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'POST', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), str) - diff --git a/conjure-python-core/src/test/resources/types/expected/package/nested_service2/__init__.py b/conjure-python-core/src/test/resources/types/expected/package/nested_service2/__init__.py index 1ea302491..2282c445f 100644 --- a/conjure-python-core/src/test/resources/types/expected/package/nested_service2/__init__.py +++ b/conjure-python-core/src/test/resources/types/expected/package/nested_service2/__init__.py @@ -1,6 +1,41 @@ -from .SimpleNestedService2 import SimpleNestedService2 +# this is package package.nested_service2 +from conjure_python_client import ConjureDecoder +from conjure_python_client import ConjureEncoder +from conjure_python_client import Service +from typing import Dict +from typing import List +from typing import Optional +from typing import Set +from typing import Tuple -__all__ = [ - 'SimpleNestedService2', -] +class SimpleNestedService2(Service): + + def test_endpoint(self, string): + # type: (str) -> str + + _headers = { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + } # type: Dict[str, Any] + + _json = ConjureEncoder().default(string) # type: Any + + _path = '/catalog/testEndpoint' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'POST', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), str) diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/AliasAsMapKeyExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/AliasAsMapKeyExample.py deleted file mode 100644 index f6f9f9e64..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/AliasAsMapKeyExample.py +++ /dev/null @@ -1,81 +0,0 @@ -from .BearerTokenAliasExample import BearerTokenAliasExample -from .DateTimeAliasExample import DateTimeAliasExample -from .IntegerAliasExample import IntegerAliasExample -from .ManyFieldExample import ManyFieldExample -from .RidAliasExample import RidAliasExample -from .SafeLongAliasExample import SafeLongAliasExample -from .StringAliasExample import StringAliasExample -from .UuidAliasExample import UuidAliasExample -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition -from conjure_python_client import DictType -from typing import Dict - -class AliasAsMapKeyExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'strings': ConjureFieldDefinition('strings', DictType(StringAliasExample, ManyFieldExample)), - 'rids': ConjureFieldDefinition('rids', DictType(RidAliasExample, ManyFieldExample)), - 'bearertokens': ConjureFieldDefinition('bearertokens', DictType(BearerTokenAliasExample, ManyFieldExample)), - 'integers': ConjureFieldDefinition('integers', DictType(IntegerAliasExample, ManyFieldExample)), - 'safelongs': ConjureFieldDefinition('safelongs', DictType(SafeLongAliasExample, ManyFieldExample)), - 'datetimes': ConjureFieldDefinition('datetimes', DictType(DateTimeAliasExample, ManyFieldExample)), - 'uuids': ConjureFieldDefinition('uuids', DictType(UuidAliasExample, ManyFieldExample)) - } - - _strings = None # type: Dict[StringAliasExample, ManyFieldExample] - _rids = None # type: Dict[RidAliasExample, ManyFieldExample] - _bearertokens = None # type: Dict[BearerTokenAliasExample, ManyFieldExample] - _integers = None # type: Dict[IntegerAliasExample, ManyFieldExample] - _safelongs = None # type: Dict[SafeLongAliasExample, ManyFieldExample] - _datetimes = None # type: Dict[DateTimeAliasExample, ManyFieldExample] - _uuids = None # type: Dict[UuidAliasExample, ManyFieldExample] - - def __init__(self, strings, rids, bearertokens, integers, safelongs, datetimes, uuids): - # type: (Dict[StringAliasExample, ManyFieldExample], Dict[RidAliasExample, ManyFieldExample], Dict[BearerTokenAliasExample, ManyFieldExample], Dict[IntegerAliasExample, ManyFieldExample], Dict[SafeLongAliasExample, ManyFieldExample], Dict[DateTimeAliasExample, ManyFieldExample], Dict[UuidAliasExample, ManyFieldExample]) -> None - self._strings = strings - self._rids = rids - self._bearertokens = bearertokens - self._integers = integers - self._safelongs = safelongs - self._datetimes = datetimes - self._uuids = uuids - - @property - def strings(self): - # type: () -> Dict[StringAliasExample, ManyFieldExample] - return self._strings - - @property - def rids(self): - # type: () -> Dict[RidAliasExample, ManyFieldExample] - return self._rids - - @property - def bearertokens(self): - # type: () -> Dict[BearerTokenAliasExample, ManyFieldExample] - return self._bearertokens - - @property - def integers(self): - # type: () -> Dict[IntegerAliasExample, ManyFieldExample] - return self._integers - - @property - def safelongs(self): - # type: () -> Dict[SafeLongAliasExample, ManyFieldExample] - return self._safelongs - - @property - def datetimes(self): - # type: () -> Dict[DateTimeAliasExample, ManyFieldExample] - return self._datetimes - - @property - def uuids(self): - # type: () -> Dict[UuidAliasExample, ManyFieldExample] - return self._uuids - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/AnyExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/AnyExample.py deleted file mode 100644 index 0cd2e53b6..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/AnyExample.py +++ /dev/null @@ -1,24 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition -from typing import Any - -class AnyExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'any': ConjureFieldDefinition('any', object) - } - - _any = None # type: Any - - def __init__(self, any): - # type: (Any) -> None - self._any = any - - @property - def any(self): - # type: () -> Any - return self._any - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/AnyMapExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/AnyMapExample.py deleted file mode 100644 index 2163eed3f..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/AnyMapExample.py +++ /dev/null @@ -1,26 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition -from conjure_python_client import DictType -from typing import Any -from typing import Dict - -class AnyMapExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'items': ConjureFieldDefinition('items', DictType(str, object)) - } - - _items = None # type: Dict[str, Any] - - def __init__(self, items): - # type: (Dict[str, Any]) -> None - self._items = items - - @property - def items(self): - # type: () -> Dict[str, Any] - return self._items - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/BearerTokenAliasExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/BearerTokenAliasExample.py deleted file mode 100644 index efc60a540..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/BearerTokenAliasExample.py +++ /dev/null @@ -1,3 +0,0 @@ - -BearerTokenAliasExample = str - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/BearerTokenExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/BearerTokenExample.py deleted file mode 100644 index 9ab31cec2..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/BearerTokenExample.py +++ /dev/null @@ -1,23 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition - -class BearerTokenExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'bearer_token_value': ConjureFieldDefinition('bearerTokenValue', str) - } - - _bearer_token_value = None # type: str - - def __init__(self, bearer_token_value): - # type: (str) -> None - self._bearer_token_value = bearer_token_value - - @property - def bearer_token_value(self): - # type: () -> str - return self._bearer_token_value - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/BinaryAliasExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/BinaryAliasExample.py deleted file mode 100644 index e57dcc69f..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/BinaryAliasExample.py +++ /dev/null @@ -1,4 +0,0 @@ -from conjure_python_client import BinaryType - -BinaryAliasExample = BinaryType() - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/BinaryExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/BinaryExample.py deleted file mode 100644 index e73aa7515..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/BinaryExample.py +++ /dev/null @@ -1,24 +0,0 @@ -from conjure_python_client import BinaryType -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition - -class BinaryExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'binary': ConjureFieldDefinition('binary', BinaryType()) - } - - _binary = None # type: Any - - def __init__(self, binary): - # type: (Any) -> None - self._binary = binary - - @property - def binary(self): - # type: () -> Any - return self._binary - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/BooleanAliasExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/BooleanAliasExample.py deleted file mode 100644 index dc4ba7e44..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/BooleanAliasExample.py +++ /dev/null @@ -1,3 +0,0 @@ - -BooleanAliasExample = bool - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/BooleanExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/BooleanExample.py deleted file mode 100644 index dc4b9fa38..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/BooleanExample.py +++ /dev/null @@ -1,23 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition - -class BooleanExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'coin': ConjureFieldDefinition('coin', bool) - } - - _coin = None # type: bool - - def __init__(self, coin): - # type: (bool) -> None - self._coin = coin - - @property - def coin(self): - # type: () -> bool - return self._coin - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/CreateDatasetRequest.py b/conjure-python-core/src/test/resources/types/expected/package/product/CreateDatasetRequest.py deleted file mode 100644 index 2287738ae..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/CreateDatasetRequest.py +++ /dev/null @@ -1,31 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition - -class CreateDatasetRequest(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'file_system_id': ConjureFieldDefinition('fileSystemId', str), - 'path': ConjureFieldDefinition('path', str) - } - - _file_system_id = None # type: str - _path = None # type: str - - def __init__(self, file_system_id, path): - # type: (str, str) -> None - self._file_system_id = file_system_id - self._path = path - - @property - def file_system_id(self): - # type: () -> str - return self._file_system_id - - @property - def path(self): - # type: () -> str - return self._path - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/DateTimeAliasExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/DateTimeAliasExample.py deleted file mode 100644 index 7849e2546..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/DateTimeAliasExample.py +++ /dev/null @@ -1,3 +0,0 @@ - -DateTimeAliasExample = str - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/DateTimeExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/DateTimeExample.py deleted file mode 100644 index 222e4a442..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/DateTimeExample.py +++ /dev/null @@ -1,23 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition - -class DateTimeExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'datetime': ConjureFieldDefinition('datetime', str) - } - - _datetime = None # type: str - - def __init__(self, datetime): - # type: (str) -> None - self._datetime = datetime - - @property - def datetime(self): - # type: () -> str - return self._datetime - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/DoubleAliasExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/DoubleAliasExample.py deleted file mode 100644 index 8bdda955e..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/DoubleAliasExample.py +++ /dev/null @@ -1,3 +0,0 @@ - -DoubleAliasExample = float - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/DoubleExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/DoubleExample.py deleted file mode 100644 index c62912ead..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/DoubleExample.py +++ /dev/null @@ -1,23 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition - -class DoubleExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'double_value': ConjureFieldDefinition('doubleValue', float) - } - - _double_value = None # type: float - - def __init__(self, double_value): - # type: (float) -> None - self._double_value = double_value - - @property - def double_value(self): - # type: () -> float - return self._double_value - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/EmptyObjectExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/EmptyObjectExample.py deleted file mode 100644 index 1f7cee8fa..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/EmptyObjectExample.py +++ /dev/null @@ -1,13 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition - -class EmptyObjectExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - } - - - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/EnumExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/EnumExample.py deleted file mode 100644 index 968983ee7..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/EnumExample.py +++ /dev/null @@ -1,15 +0,0 @@ -from conjure_python_client import ConjureEnumType - -class EnumExample(ConjureEnumType): - """This enumerates the numbers 1:2.""" - - ONE = 'ONE' - '''ONE''' - TWO = 'TWO' - '''TWO''' - UNKNOWN = 'UNKNOWN' - '''UNKNOWN''' - - def __reduce_ex__(self, proto): - return self.__class__, (self.name,) - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/EnumFieldExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/EnumFieldExample.py deleted file mode 100644 index e0125f726..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/EnumFieldExample.py +++ /dev/null @@ -1,24 +0,0 @@ -from .EnumExample import EnumExample -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition - -class EnumFieldExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'enum': ConjureFieldDefinition('enum', EnumExample) - } - - _enum = None # type: EnumExample - - def __init__(self, enum): - # type: (EnumExample) -> None - self._enum = enum - - @property - def enum(self): - # type: () -> EnumExample - return self._enum - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/IntegerAliasExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/IntegerAliasExample.py deleted file mode 100644 index 5fa2fe8b7..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/IntegerAliasExample.py +++ /dev/null @@ -1,3 +0,0 @@ - -IntegerAliasExample = int - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/IntegerExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/IntegerExample.py deleted file mode 100644 index 9814ba03d..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/IntegerExample.py +++ /dev/null @@ -1,23 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition - -class IntegerExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'integer': ConjureFieldDefinition('integer', int) - } - - _integer = None # type: int - - def __init__(self, integer): - # type: (int) -> None - self._integer = integer - - @property - def integer(self): - # type: () -> int - return self._integer - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/ListExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/ListExample.py deleted file mode 100644 index 2c7e779cb..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/ListExample.py +++ /dev/null @@ -1,41 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition -from conjure_python_client import ListType -from typing import List - -class ListExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'items': ConjureFieldDefinition('items', ListType(str)), - 'primitive_items': ConjureFieldDefinition('primitiveItems', ListType(int)), - 'double_items': ConjureFieldDefinition('doubleItems', ListType(float)) - } - - _items = None # type: List[str] - _primitive_items = None # type: List[int] - _double_items = None # type: List[float] - - def __init__(self, items, primitive_items, double_items): - # type: (List[str], List[int], List[float]) -> None - self._items = items - self._primitive_items = primitive_items - self._double_items = double_items - - @property - def items(self): - # type: () -> List[str] - return self._items - - @property - def primitive_items(self): - # type: () -> List[int] - return self._primitive_items - - @property - def double_items(self): - # type: () -> List[float] - return self._double_items - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/ManyFieldExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/ManyFieldExample.py deleted file mode 100644 index 51117562a..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/ManyFieldExample.py +++ /dev/null @@ -1,95 +0,0 @@ -from .StringAliasExample import StringAliasExample -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition -from conjure_python_client import DictType -from conjure_python_client import ListType -from conjure_python_client import OptionalType -from typing import Dict -from typing import List -from typing import Optional -from typing import Set - -class ManyFieldExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'string': ConjureFieldDefinition('string', str), - 'integer': ConjureFieldDefinition('integer', int), - 'double_value': ConjureFieldDefinition('doubleValue', float), - 'optional_item': ConjureFieldDefinition('optionalItem', OptionalType(str)), - 'items': ConjureFieldDefinition('items', ListType(str)), - 'set': ConjureFieldDefinition('set', ListType(str)), - 'map': ConjureFieldDefinition('map', DictType(str, str)), - 'alias': ConjureFieldDefinition('alias', StringAliasExample) - } - - _string = None # type: str - _integer = None # type: int - _double_value = None # type: float - _optional_item = None # type: Optional[str] - _items = None # type: List[str] - _set = None # type: List[str] - _map = None # type: Dict[str, str] - _alias = None # type: StringAliasExample - - def __init__(self, string, integer, double_value, optional_item, items, set, map, alias): - # type: (str, int, float, Optional[str], List[str], List[str], Dict[str, str], StringAliasExample) -> None - self._string = string - self._integer = integer - self._double_value = double_value - self._optional_item = optional_item - self._items = items - self._set = set - self._map = map - self._alias = alias - - @property - def string(self): - # type: () -> str - """docs for string field""" - return self._string - - @property - def integer(self): - # type: () -> int - """docs for integer field""" - return self._integer - - @property - def double_value(self): - # type: () -> float - """docs for doubleValue field""" - return self._double_value - - @property - def optional_item(self): - # type: () -> Optional[str] - """docs for optionalItem field""" - return self._optional_item - - @property - def items(self): - # type: () -> List[str] - """docs for items field""" - return self._items - - @property - def set(self): - # type: () -> List[str] - """docs for set field""" - return self._set - - @property - def map(self): - # type: () -> Dict[str, str] - """docs for map field""" - return self._map - - @property - def alias(self): - # type: () -> StringAliasExample - """docs for alias field""" - return self._alias - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/MapAliasExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/MapAliasExample.py deleted file mode 100644 index ea0fff42f..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/MapAliasExample.py +++ /dev/null @@ -1,6 +0,0 @@ -from conjure_python_client import DictType -from typing import Any -from typing import Dict - -MapAliasExample = DictType(str, object) - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/MapExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/MapExample.py deleted file mode 100644 index cc46d0384..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/MapExample.py +++ /dev/null @@ -1,25 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition -from conjure_python_client import DictType -from typing import Dict - -class MapExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'items': ConjureFieldDefinition('items', DictType(str, str)) - } - - _items = None # type: Dict[str, str] - - def __init__(self, items): - # type: (Dict[str, str]) -> None - self._items = items - - @property - def items(self): - # type: () -> Dict[str, str] - return self._items - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/OptionalExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/OptionalExample.py deleted file mode 100644 index b9ebb5df6..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/OptionalExample.py +++ /dev/null @@ -1,25 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition -from conjure_python_client import OptionalType -from typing import Optional - -class OptionalExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'item': ConjureFieldDefinition('item', OptionalType(str)) - } - - _item = None # type: Optional[str] - - def __init__(self, item): - # type: (Optional[str]) -> None - self._item = item - - @property - def item(self): - # type: () -> Optional[str] - return self._item - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/PrimitiveOptionalsExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/PrimitiveOptionalsExample.py deleted file mode 100644 index eaa2ad0ac..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/PrimitiveOptionalsExample.py +++ /dev/null @@ -1,73 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition -from conjure_python_client import OptionalType -from typing import Optional - -class PrimitiveOptionalsExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'num': ConjureFieldDefinition('num', OptionalType(float)), - 'bool': ConjureFieldDefinition('bool', OptionalType(bool)), - 'integer': ConjureFieldDefinition('integer', OptionalType(int)), - 'safelong': ConjureFieldDefinition('safelong', OptionalType(int)), - 'rid': ConjureFieldDefinition('rid', OptionalType(str)), - 'bearertoken': ConjureFieldDefinition('bearertoken', OptionalType(str)), - 'uuid': ConjureFieldDefinition('uuid', OptionalType(str)) - } - - _num = None # type: Optional[float] - _bool = None # type: Optional[bool] - _integer = None # type: Optional[int] - _safelong = None # type: Optional[int] - _rid = None # type: Optional[str] - _bearertoken = None # type: Optional[str] - _uuid = None # type: Optional[str] - - def __init__(self, num, bool, integer, safelong, rid, bearertoken, uuid): - # type: (Optional[float], Optional[bool], Optional[int], Optional[int], Optional[str], Optional[str], Optional[str]) -> None - self._num = num - self._bool = bool - self._integer = integer - self._safelong = safelong - self._rid = rid - self._bearertoken = bearertoken - self._uuid = uuid - - @property - def num(self): - # type: () -> Optional[float] - return self._num - - @property - def bool(self): - # type: () -> Optional[bool] - return self._bool - - @property - def integer(self): - # type: () -> Optional[int] - return self._integer - - @property - def safelong(self): - # type: () -> Optional[int] - return self._safelong - - @property - def rid(self): - # type: () -> Optional[str] - return self._rid - - @property - def bearertoken(self): - # type: () -> Optional[str] - return self._bearertoken - - @property - def uuid(self): - # type: () -> Optional[str] - return self._uuid - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/ReferenceAliasExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/ReferenceAliasExample.py deleted file mode 100644 index 9e07b0c92..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/ReferenceAliasExample.py +++ /dev/null @@ -1,4 +0,0 @@ -from .AnyExample import AnyExample - -ReferenceAliasExample = AnyExample - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/ReservedKeyExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/ReservedKeyExample.py deleted file mode 100644 index 9b19e0466..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/ReservedKeyExample.py +++ /dev/null @@ -1,47 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition - -class ReservedKeyExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'package': ConjureFieldDefinition('package', str), - 'interface': ConjureFieldDefinition('interface', str), - 'field_name_with_dashes': ConjureFieldDefinition('field-name-with-dashes', str), - 'memoized_hash_code': ConjureFieldDefinition('memoizedHashCode', int) - } - - _package = None # type: str - _interface = None # type: str - _field_name_with_dashes = None # type: str - _memoized_hash_code = None # type: int - - def __init__(self, package, interface, field_name_with_dashes, memoized_hash_code): - # type: (str, str, str, int) -> None - self._package = package - self._interface = interface - self._field_name_with_dashes = field_name_with_dashes - self._memoized_hash_code = memoized_hash_code - - @property - def package(self): - # type: () -> str - return self._package - - @property - def interface(self): - # type: () -> str - return self._interface - - @property - def field_name_with_dashes(self): - # type: () -> str - return self._field_name_with_dashes - - @property - def memoized_hash_code(self): - # type: () -> int - return self._memoized_hash_code - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/RidAliasExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/RidAliasExample.py deleted file mode 100644 index dc46df370..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/RidAliasExample.py +++ /dev/null @@ -1,3 +0,0 @@ - -RidAliasExample = str - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/RidExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/RidExample.py deleted file mode 100644 index 36e83581b..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/RidExample.py +++ /dev/null @@ -1,23 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition - -class RidExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'rid_value': ConjureFieldDefinition('ridValue', str) - } - - _rid_value = None # type: str - - def __init__(self, rid_value): - # type: (str) -> None - self._rid_value = rid_value - - @property - def rid_value(self): - # type: () -> str - return self._rid_value - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/SafeLongAliasExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/SafeLongAliasExample.py deleted file mode 100644 index a4c7cde42..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/SafeLongAliasExample.py +++ /dev/null @@ -1,3 +0,0 @@ - -SafeLongAliasExample = int - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/SafeLongExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/SafeLongExample.py deleted file mode 100644 index 3afb1c04e..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/SafeLongExample.py +++ /dev/null @@ -1,23 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition - -class SafeLongExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'safe_long_value': ConjureFieldDefinition('safeLongValue', int) - } - - _safe_long_value = None # type: int - - def __init__(self, safe_long_value): - # type: (int) -> None - self._safe_long_value = safe_long_value - - @property - def safe_long_value(self): - # type: () -> int - return self._safe_long_value - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/SetExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/SetExample.py deleted file mode 100644 index fd749ef89..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/SetExample.py +++ /dev/null @@ -1,33 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition -from conjure_python_client import ListType -from typing import Set - -class SetExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'items': ConjureFieldDefinition('items', ListType(str)), - 'double_items': ConjureFieldDefinition('doubleItems', ListType(float)) - } - - _items = None # type: List[str] - _double_items = None # type: List[float] - - def __init__(self, items, double_items): - # type: (List[str], List[float]) -> None - self._items = items - self._double_items = double_items - - @property - def items(self): - # type: () -> List[str] - return self._items - - @property - def double_items(self): - # type: () -> List[float] - return self._double_items - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/StringAliasExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/StringAliasExample.py deleted file mode 100644 index 2d9946b65..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/StringAliasExample.py +++ /dev/null @@ -1,3 +0,0 @@ - -StringAliasExample = str - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/StringExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/StringExample.py deleted file mode 100644 index 555390b5f..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/StringExample.py +++ /dev/null @@ -1,23 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition - -class StringExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'string': ConjureFieldDefinition('string', str) - } - - _string = None # type: str - - def __init__(self, string): - # type: (str) -> None - self._string = string - - @property - def string(self): - # type: () -> str - return self._string - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/UnionTypeExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/UnionTypeExample.py deleted file mode 100644 index 629218a56..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/UnionTypeExample.py +++ /dev/null @@ -1,92 +0,0 @@ -from .StringExample import StringExample -from conjure_python_client import ConjureFieldDefinition -from conjure_python_client import ConjureUnionType -from conjure_python_client import ListType -from typing import Set - -class UnionTypeExample(ConjureUnionType): - """A type which can either be a StringExample, a set of strings, or an integer.""" - - _string_example = None # type: StringExample - _set = None # type: List[str] - _this_field_is_an_integer = None # type: int - _also_an_integer = None # type: int - _if = None # type: int - _new = None # type: int - _interface = None # type: int - - @classmethod - def _options(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'string_example': ConjureFieldDefinition('stringExample', StringExample), - 'set': ConjureFieldDefinition('set', ListType(str)), - 'this_field_is_an_integer': ConjureFieldDefinition('thisFieldIsAnInteger', int), - 'also_an_integer': ConjureFieldDefinition('alsoAnInteger', int), - 'if_': ConjureFieldDefinition('if', int), - 'new': ConjureFieldDefinition('new', int), - 'interface': ConjureFieldDefinition('interface', int) - } - - def __init__(self, string_example=None, set=None, this_field_is_an_integer=None, also_an_integer=None, if_=None, new=None, interface=None): - if (string_example is not None) + (set is not None) + (this_field_is_an_integer is not None) + (also_an_integer is not None) + (if_ is not None) + (new is not None) + (interface is not None) != 1: - raise ValueError('a union must contain a single member') - - if string_example is not None: - self._string_example = string_example - self._type = 'stringExample' - if set is not None: - self._set = set - self._type = 'set' - if this_field_is_an_integer is not None: - self._this_field_is_an_integer = this_field_is_an_integer - self._type = 'thisFieldIsAnInteger' - if also_an_integer is not None: - self._also_an_integer = also_an_integer - self._type = 'alsoAnInteger' - if if_ is not None: - self._if = if_ - self._type = 'if' - if new is not None: - self._new = new - self._type = 'new' - if interface is not None: - self._interface = interface - self._type = 'interface' - - @property - def string_example(self): - # type: () -> StringExample - """Docs for when UnionTypeExample is of type StringExample.""" - return self._string_example - - @property - def set(self): - # type: () -> List[str] - return self._set - - @property - def this_field_is_an_integer(self): - # type: () -> int - return self._this_field_is_an_integer - - @property - def also_an_integer(self): - # type: () -> int - return self._also_an_integer - - @property - def if_(self): - # type: () -> int - return self._if - - @property - def new(self): - # type: () -> int - return self._new - - @property - def interface(self): - # type: () -> int - return self._interface - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/UuidAliasExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/UuidAliasExample.py deleted file mode 100644 index 75248ae37..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/UuidAliasExample.py +++ /dev/null @@ -1,3 +0,0 @@ - -UuidAliasExample = str - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/UuidExample.py b/conjure-python-core/src/test/resources/types/expected/package/product/UuidExample.py deleted file mode 100644 index a4a014be7..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product/UuidExample.py +++ /dev/null @@ -1,23 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition - -class UuidExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'uuid': ConjureFieldDefinition('uuid', str) - } - - _uuid = None # type: str - - def __init__(self, uuid): - # type: (str) -> None - self._uuid = uuid - - @property - def uuid(self): - # type: () -> str - return self._uuid - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/__init__.py b/conjure-python-core/src/test/resources/types/expected/package/product/__init__.py index 4c97b2570..310846831 100644 --- a/conjure-python-core/src/test/resources/types/expected/package/product/__init__.py +++ b/conjure-python-core/src/test/resources/types/expected/package/product/__init__.py @@ -1,78 +1,799 @@ -from .AliasAsMapKeyExample import AliasAsMapKeyExample -from .AnyExample import AnyExample -from .AnyMapExample import AnyMapExample -from .BearerTokenAliasExample import BearerTokenAliasExample -from .BearerTokenExample import BearerTokenExample -from .BinaryAliasExample import BinaryAliasExample -from .BinaryExample import BinaryExample -from .BooleanAliasExample import BooleanAliasExample -from .BooleanExample import BooleanExample -from .CreateDatasetRequest import CreateDatasetRequest -from .DateTimeAliasExample import DateTimeAliasExample -from .DateTimeExample import DateTimeExample -from .DoubleAliasExample import DoubleAliasExample -from .DoubleExample import DoubleExample -from .EmptyObjectExample import EmptyObjectExample -from .EnumExample import EnumExample -from .EnumFieldExample import EnumFieldExample -from .IntegerAliasExample import IntegerAliasExample -from .IntegerExample import IntegerExample -from .ListExample import ListExample -from .ManyFieldExample import ManyFieldExample -from .MapAliasExample import MapAliasExample -from .MapExample import MapExample -from .OptionalExample import OptionalExample -from .PrimitiveOptionalsExample import PrimitiveOptionalsExample -from .ReferenceAliasExample import ReferenceAliasExample -from .ReservedKeyExample import ReservedKeyExample -from .RidAliasExample import RidAliasExample -from .RidExample import RidExample -from .SafeLongAliasExample import SafeLongAliasExample -from .SafeLongExample import SafeLongExample -from .SetExample import SetExample -from .StringAliasExample import StringAliasExample -from .StringExample import StringExample -from .UnionTypeExample import UnionTypeExample -from .UuidAliasExample import UuidAliasExample -from .UuidExample import UuidExample - -__all__ = [ - 'AliasAsMapKeyExample', - 'AnyExample', - 'AnyMapExample', - 'BearerTokenAliasExample', - 'BearerTokenExample', - 'BinaryAliasExample', - 'BinaryExample', - 'BooleanAliasExample', - 'BooleanExample', - 'CreateDatasetRequest', - 'DateTimeAliasExample', - 'DateTimeExample', - 'DoubleAliasExample', - 'DoubleExample', - 'EmptyObjectExample', - 'EnumExample', - 'EnumFieldExample', - 'IntegerAliasExample', - 'IntegerExample', - 'ListExample', - 'ManyFieldExample', - 'MapAliasExample', - 'MapExample', - 'OptionalExample', - 'PrimitiveOptionalsExample', - 'ReferenceAliasExample', - 'ReservedKeyExample', - 'RidAliasExample', - 'RidExample', - 'SafeLongAliasExample', - 'SafeLongExample', - 'SetExample', - 'StringAliasExample', - 'StringExample', - 'UnionTypeExample', - 'UuidAliasExample', - 'UuidExample', -] +# this is package package.product +from conjure_python_client import * +from conjure_python_client import ConjureBeanType +from conjure_python_client import ConjureFieldDefinition +from typing import Dict +from typing import List +from typing import Optional +from typing import Set +from typing import Tuple + +class CreateDatasetRequest(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'file_system_id': ConjureFieldDefinition('fileSystemId', str), + 'path': ConjureFieldDefinition('path', str) + } + + _file_system_id = None # type: str + _path = None # type: str + + def __init__(self, file_system_id, path): + # type: (str, str) -> None + self._file_system_id = file_system_id + self._path = path + + @property + def file_system_id(self): + # type: () -> str + return self._file_system_id + + @property + def path(self): + # type: () -> str + return self._path + +class StringExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'string': ConjureFieldDefinition('string', str) + } + + _string = None # type: str + + def __init__(self, string): + # type: (str) -> None + self._string = string + + @property + def string(self): + # type: () -> str + return self._string + +class IntegerExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'integer': ConjureFieldDefinition('integer', int) + } + + _integer = None # type: int + + def __init__(self, integer): + # type: (int) -> None + self._integer = integer + + @property + def integer(self): + # type: () -> int + return self._integer + +class SafeLongExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'safe_long_value': ConjureFieldDefinition('safeLongValue', int) + } + + _safe_long_value = None # type: int + + def __init__(self, safe_long_value): + # type: (int) -> None + self._safe_long_value = safe_long_value + + @property + def safe_long_value(self): + # type: () -> int + return self._safe_long_value + +class RidExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'rid_value': ConjureFieldDefinition('ridValue', str) + } + + _rid_value = None # type: str + + def __init__(self, rid_value): + # type: (str) -> None + self._rid_value = rid_value + + @property + def rid_value(self): + # type: () -> str + return self._rid_value + +class BearerTokenExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'bearer_token_value': ConjureFieldDefinition('bearerTokenValue', str) + } + + _bearer_token_value = None # type: str + + def __init__(self, bearer_token_value): + # type: (str) -> None + self._bearer_token_value = bearer_token_value + + @property + def bearer_token_value(self): + # type: () -> str + return self._bearer_token_value + +class DateTimeExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'datetime': ConjureFieldDefinition('datetime', str) + } + + _datetime = None # type: str + + def __init__(self, datetime): + # type: (str) -> None + self._datetime = datetime + + @property + def datetime(self): + # type: () -> str + return self._datetime + +class DoubleExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'double_value': ConjureFieldDefinition('doubleValue', float) + } + + _double_value = None # type: float + + def __init__(self, double_value): + # type: (float) -> None + self._double_value = double_value + + @property + def double_value(self): + # type: () -> float + return self._double_value + +class BinaryExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'binary': ConjureFieldDefinition('binary', BinaryType()) + } + + _binary = None # type: Any + + def __init__(self, binary): + # type: (Any) -> None + self._binary = binary + + @property + def binary(self): + # type: () -> Any + return self._binary + +class OptionalExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'item': ConjureFieldDefinition('item', OptionalType(str)) + } + + _item = None # type: Optional[str] + + def __init__(self, item): + # type: (Optional[str]) -> None + self._item = item + + @property + def item(self): + # type: () -> Optional[str] + return self._item + +class ListExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'items': ConjureFieldDefinition('items', ListType(str)), + 'primitive_items': ConjureFieldDefinition('primitiveItems', ListType(int)), + 'double_items': ConjureFieldDefinition('doubleItems', ListType(float)) + } + + _items = None # type: List[str] + _primitive_items = None # type: List[int] + _double_items = None # type: List[float] + + def __init__(self, items, primitive_items, double_items): + # type: (List[str], List[int], List[float]) -> None + self._items = items + self._primitive_items = primitive_items + self._double_items = double_items + + @property + def items(self): + # type: () -> List[str] + return self._items + + @property + def primitive_items(self): + # type: () -> List[int] + return self._primitive_items + + @property + def double_items(self): + # type: () -> List[float] + return self._double_items + +class SetExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'items': ConjureFieldDefinition('items', ListType(str)), + 'double_items': ConjureFieldDefinition('doubleItems', ListType(float)) + } + + _items = None # type: List[str] + _double_items = None # type: List[float] + + def __init__(self, items, double_items): + # type: (List[str], List[float]) -> None + self._items = items + self._double_items = double_items + + @property + def items(self): + # type: () -> List[str] + return self._items + + @property + def double_items(self): + # type: () -> List[float] + return self._double_items + +class MapExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'items': ConjureFieldDefinition('items', DictType(str, str)) + } + + _items = None # type: Dict[str, str] + + def __init__(self, items): + # type: (Dict[str, str]) -> None + self._items = items + + @property + def items(self): + # type: () -> Dict[str, str] + return self._items + +class EnumExample(ConjureEnumType): + """This enumerates the numbers 1:2.""" + + ONE = 'ONE' + '''ONE''' + TWO = 'TWO' + '''TWO''' + UNKNOWN = 'UNKNOWN' + '''UNKNOWN''' + + def __reduce_ex__(self, proto): + return self.__class__, (self.name,) + +class EnumFieldExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'enum': ConjureFieldDefinition('enum', EnumExample) + } + + _enum = None # type: EnumExample + + def __init__(self, enum): + # type: (EnumExample) -> None + self._enum = enum + + @property + def enum(self): + # type: () -> EnumExample + return self._enum + +class BooleanExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'coin': ConjureFieldDefinition('coin', bool) + } + + _coin = None # type: bool + + def __init__(self, coin): + # type: (bool) -> None + self._coin = coin + + @property + def coin(self): + # type: () -> bool + return self._coin + +class AnyExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'any': ConjureFieldDefinition('any', object) + } + + _any = None # type: Any + + def __init__(self, any): + # type: (Any) -> None + self._any = any + + @property + def any(self): + # type: () -> Any + return self._any + +class AnyMapExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'items': ConjureFieldDefinition('items', DictType(str, object)) + } + + _items = None # type: Dict[str, Any] + + def __init__(self, items): + # type: (Dict[str, Any]) -> None + self._items = items + + @property + def items(self): + # type: () -> Dict[str, Any] + return self._items + +class UuidExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'uuid': ConjureFieldDefinition('uuid', str) + } + + _uuid = None # type: str + + def __init__(self, uuid): + # type: (str) -> None + self._uuid = uuid + + @property + def uuid(self): + # type: () -> str + return self._uuid + +class PrimitiveOptionalsExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'num': ConjureFieldDefinition('num', OptionalType(float)), + 'bool': ConjureFieldDefinition('bool', OptionalType(bool)), + 'integer': ConjureFieldDefinition('integer', OptionalType(int)), + 'safelong': ConjureFieldDefinition('safelong', OptionalType(int)), + 'rid': ConjureFieldDefinition('rid', OptionalType(str)), + 'bearertoken': ConjureFieldDefinition('bearertoken', OptionalType(str)), + 'uuid': ConjureFieldDefinition('uuid', OptionalType(str)) + } + + _num = None # type: Optional[float] + _bool = None # type: Optional[bool] + _integer = None # type: Optional[int] + _safelong = None # type: Optional[int] + _rid = None # type: Optional[str] + _bearertoken = None # type: Optional[str] + _uuid = None # type: Optional[str] + + def __init__(self, num, bool, integer, safelong, rid, bearertoken, uuid): + # type: (Optional[float], Optional[bool], Optional[int], Optional[int], Optional[str], Optional[str], Optional[str]) -> None + self._num = num + self._bool = bool + self._integer = integer + self._safelong = safelong + self._rid = rid + self._bearertoken = bearertoken + self._uuid = uuid + + @property + def num(self): + # type: () -> Optional[float] + return self._num + + @property + def bool(self): + # type: () -> Optional[bool] + return self._bool + + @property + def integer(self): + # type: () -> Optional[int] + return self._integer + + @property + def safelong(self): + # type: () -> Optional[int] + return self._safelong + + @property + def rid(self): + # type: () -> Optional[str] + return self._rid + + @property + def bearertoken(self): + # type: () -> Optional[str] + return self._bearertoken + + @property + def uuid(self): + # type: () -> Optional[str] + return self._uuid + +class ManyFieldExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'string': ConjureFieldDefinition('string', str), + 'integer': ConjureFieldDefinition('integer', int), + 'double_value': ConjureFieldDefinition('doubleValue', float), + 'optional_item': ConjureFieldDefinition('optionalItem', OptionalType(str)), + 'items': ConjureFieldDefinition('items', ListType(str)), + 'set': ConjureFieldDefinition('set', ListType(str)), + 'map': ConjureFieldDefinition('map', DictType(str, str)), + 'alias': ConjureFieldDefinition('alias', StringAliasExample) + } + + _string = None # type: str + _integer = None # type: int + _double_value = None # type: float + _optional_item = None # type: Optional[str] + _items = None # type: List[str] + _set = None # type: List[str] + _map = None # type: Dict[str, str] + _alias = None # type: StringAliasExample + + def __init__(self, string, integer, double_value, optional_item, items, set, map, alias): + # type: (str, int, float, Optional[str], List[str], List[str], Dict[str, str], StringAliasExample) -> None + self._string = string + self._integer = integer + self._double_value = double_value + self._optional_item = optional_item + self._items = items + self._set = set + self._map = map + self._alias = alias + + @property + def string(self): + # type: () -> str + """docs for string field""" + return self._string + + @property + def integer(self): + # type: () -> int + """docs for integer field""" + return self._integer + + @property + def double_value(self): + # type: () -> float + """docs for doubleValue field""" + return self._double_value + + @property + def optional_item(self): + # type: () -> Optional[str] + """docs for optionalItem field""" + return self._optional_item + + @property + def items(self): + # type: () -> List[str] + """docs for items field""" + return self._items + + @property + def set(self): + # type: () -> List[str] + """docs for set field""" + return self._set + + @property + def map(self): + # type: () -> Dict[str, str] + """docs for map field""" + return self._map + + @property + def alias(self): + # type: () -> StringAliasExample + """docs for alias field""" + return self._alias + +class UnionTypeExample(ConjureUnionType): + """A type which can either be a StringExample, a set of strings, or an integer.""" + + _string_example = None # type: StringExample + _set = None # type: List[str] + _this_field_is_an_integer = None # type: int + _also_an_integer = None # type: int + _if = None # type: int + _new = None # type: int + _interface = None # type: int + + @classmethod + def _options(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'string_example': ConjureFieldDefinition('stringExample', StringExample), + 'set': ConjureFieldDefinition('set', ListType(str)), + 'this_field_is_an_integer': ConjureFieldDefinition('thisFieldIsAnInteger', int), + 'also_an_integer': ConjureFieldDefinition('alsoAnInteger', int), + 'if_': ConjureFieldDefinition('if', int), + 'new': ConjureFieldDefinition('new', int), + 'interface': ConjureFieldDefinition('interface', int) + } + + def __init__(self, string_example=None, set=None, this_field_is_an_integer=None, also_an_integer=None, if_=None, new=None, interface=None): + if (string_example is not None) + (set is not None) + (this_field_is_an_integer is not None) + (also_an_integer is not None) + (if_ is not None) + (new is not None) + (interface is not None) != 1: + raise ValueError('a union must contain a single member') + + if string_example is not None: + self._string_example = string_example + self._type = 'stringExample' + if set is not None: + self._set = set + self._type = 'set' + if this_field_is_an_integer is not None: + self._this_field_is_an_integer = this_field_is_an_integer + self._type = 'thisFieldIsAnInteger' + if also_an_integer is not None: + self._also_an_integer = also_an_integer + self._type = 'alsoAnInteger' + if if_ is not None: + self._if = if_ + self._type = 'if' + if new is not None: + self._new = new + self._type = 'new' + if interface is not None: + self._interface = interface + self._type = 'interface' + + @property + def string_example(self): + # type: () -> StringExample + """Docs for when UnionTypeExample is of type StringExample.""" + return self._string_example + + @property + def set(self): + # type: () -> List[str] + return self._set + + @property + def this_field_is_an_integer(self): + # type: () -> int + return self._this_field_is_an_integer + + @property + def also_an_integer(self): + # type: () -> int + return self._also_an_integer + + @property + def if_(self): + # type: () -> int + return self._if + + @property + def new(self): + # type: () -> int + return self._new + + @property + def interface(self): + # type: () -> int + return self._interface + +class EmptyObjectExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + } + + + +class AliasAsMapKeyExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'strings': ConjureFieldDefinition('strings', DictType(StringAliasExample, ManyFieldExample)), + 'rids': ConjureFieldDefinition('rids', DictType(RidAliasExample, ManyFieldExample)), + 'bearertokens': ConjureFieldDefinition('bearertokens', DictType(BearerTokenAliasExample, ManyFieldExample)), + 'integers': ConjureFieldDefinition('integers', DictType(IntegerAliasExample, ManyFieldExample)), + 'safelongs': ConjureFieldDefinition('safelongs', DictType(SafeLongAliasExample, ManyFieldExample)), + 'datetimes': ConjureFieldDefinition('datetimes', DictType(DateTimeAliasExample, ManyFieldExample)), + 'uuids': ConjureFieldDefinition('uuids', DictType(UuidAliasExample, ManyFieldExample)) + } + + _strings = None # type: Dict[StringAliasExample, ManyFieldExample] + _rids = None # type: Dict[RidAliasExample, ManyFieldExample] + _bearertokens = None # type: Dict[BearerTokenAliasExample, ManyFieldExample] + _integers = None # type: Dict[IntegerAliasExample, ManyFieldExample] + _safelongs = None # type: Dict[SafeLongAliasExample, ManyFieldExample] + _datetimes = None # type: Dict[DateTimeAliasExample, ManyFieldExample] + _uuids = None # type: Dict[UuidAliasExample, ManyFieldExample] + + def __init__(self, strings, rids, bearertokens, integers, safelongs, datetimes, uuids): + # type: (Dict[StringAliasExample, ManyFieldExample], Dict[RidAliasExample, ManyFieldExample], Dict[BearerTokenAliasExample, ManyFieldExample], Dict[IntegerAliasExample, ManyFieldExample], Dict[SafeLongAliasExample, ManyFieldExample], Dict[DateTimeAliasExample, ManyFieldExample], Dict[UuidAliasExample, ManyFieldExample]) -> None + self._strings = strings + self._rids = rids + self._bearertokens = bearertokens + self._integers = integers + self._safelongs = safelongs + self._datetimes = datetimes + self._uuids = uuids + + @property + def strings(self): + # type: () -> Dict[StringAliasExample, ManyFieldExample] + return self._strings + + @property + def rids(self): + # type: () -> Dict[RidAliasExample, ManyFieldExample] + return self._rids + + @property + def bearertokens(self): + # type: () -> Dict[BearerTokenAliasExample, ManyFieldExample] + return self._bearertokens + + @property + def integers(self): + # type: () -> Dict[IntegerAliasExample, ManyFieldExample] + return self._integers + + @property + def safelongs(self): + # type: () -> Dict[SafeLongAliasExample, ManyFieldExample] + return self._safelongs + + @property + def datetimes(self): + # type: () -> Dict[DateTimeAliasExample, ManyFieldExample] + return self._datetimes + + @property + def uuids(self): + # type: () -> Dict[UuidAliasExample, ManyFieldExample] + return self._uuids + +class ReservedKeyExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'package': ConjureFieldDefinition('package', str), + 'interface': ConjureFieldDefinition('interface', str), + 'field_name_with_dashes': ConjureFieldDefinition('field-name-with-dashes', str), + 'memoized_hash_code': ConjureFieldDefinition('memoizedHashCode', int) + } + + _package = None # type: str + _interface = None # type: str + _field_name_with_dashes = None # type: str + _memoized_hash_code = None # type: int + + def __init__(self, package, interface, field_name_with_dashes, memoized_hash_code): + # type: (str, str, str, int) -> None + self._package = package + self._interface = interface + self._field_name_with_dashes = field_name_with_dashes + self._memoized_hash_code = memoized_hash_code + + @property + def package(self): + # type: () -> str + return self._package + + @property + def interface(self): + # type: () -> str + return self._interface + + @property + def field_name_with_dashes(self): + # type: () -> str + return self._field_name_with_dashes + + @property + def memoized_hash_code(self): + # type: () -> int + return self._memoized_hash_code + +StringAliasExample = str + +DoubleAliasExample = float + +IntegerAliasExample = int + +BooleanAliasExample = bool + +SafeLongAliasExample = int + +RidAliasExample = str + +BearerTokenAliasExample = str + +UuidAliasExample = str + +MapAliasExample = DictType(str, object) + +ReferenceAliasExample = AnyExample + +DateTimeAliasExample = str + +BinaryAliasExample = BinaryType() diff --git a/conjure-python-core/src/test/resources/types/expected/package/product_datasets/BackingFileSystem.py b/conjure-python-core/src/test/resources/types/expected/package/product_datasets/BackingFileSystem.py deleted file mode 100644 index 5284e7f0a..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product_datasets/BackingFileSystem.py +++ /dev/null @@ -1,42 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition -from conjure_python_client import DictType -from typing import Dict - -class BackingFileSystem(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'file_system_id': ConjureFieldDefinition('fileSystemId', str), - 'base_uri': ConjureFieldDefinition('baseUri', str), - 'configuration': ConjureFieldDefinition('configuration', DictType(str, str)) - } - - _file_system_id = None # type: str - _base_uri = None # type: str - _configuration = None # type: Dict[str, str] - - def __init__(self, file_system_id, base_uri, configuration): - # type: (str, str, Dict[str, str]) -> None - self._file_system_id = file_system_id - self._base_uri = base_uri - self._configuration = configuration - - @property - def file_system_id(self): - # type: () -> str - """The name by which this file system is identified.""" - return self._file_system_id - - @property - def base_uri(self): - # type: () -> str - return self._base_uri - - @property - def configuration(self): - # type: () -> Dict[str, str] - return self._configuration - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product_datasets/Dataset.py b/conjure-python-core/src/test/resources/types/expected/package/product_datasets/Dataset.py deleted file mode 100644 index 37b5cbc04..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/product_datasets/Dataset.py +++ /dev/null @@ -1,32 +0,0 @@ -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition - -class Dataset(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'file_system_id': ConjureFieldDefinition('fileSystemId', str), - 'rid': ConjureFieldDefinition('rid', str) - } - - _file_system_id = None # type: str - _rid = None # type: str - - def __init__(self, file_system_id, rid): - # type: (str, str) -> None - self._file_system_id = file_system_id - self._rid = rid - - @property - def file_system_id(self): - # type: () -> str - return self._file_system_id - - @property - def rid(self): - # type: () -> str - """Uniquely identifies this dataset.""" - return self._rid - diff --git a/conjure-python-core/src/test/resources/types/expected/package/product_datasets/__init__.py b/conjure-python-core/src/test/resources/types/expected/package/product_datasets/__init__.py index abadae157..ee217316b 100644 --- a/conjure-python-core/src/test/resources/types/expected/package/product_datasets/__init__.py +++ b/conjure-python-core/src/test/resources/types/expected/package/product_datasets/__init__.py @@ -1,8 +1,75 @@ -from .BackingFileSystem import BackingFileSystem -from .Dataset import Dataset +# this is package package.product_datasets +from conjure_python_client import ConjureBeanType +from conjure_python_client import ConjureFieldDefinition +from typing import Dict +from typing import List +from typing import Optional +from typing import Set +from typing import Tuple -__all__ = [ - 'BackingFileSystem', - 'Dataset', -] +class BackingFileSystem(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'file_system_id': ConjureFieldDefinition('fileSystemId', str), + 'base_uri': ConjureFieldDefinition('baseUri', str), + 'configuration': ConjureFieldDefinition('configuration', DictType(str, str)) + } + + _file_system_id = None # type: str + _base_uri = None # type: str + _configuration = None # type: Dict[str, str] + + def __init__(self, file_system_id, base_uri, configuration): + # type: (str, str, Dict[str, str]) -> None + self._file_system_id = file_system_id + self._base_uri = base_uri + self._configuration = configuration + + @property + def file_system_id(self): + # type: () -> str + """The name by which this file system is identified.""" + return self._file_system_id + + @property + def base_uri(self): + # type: () -> str + return self._base_uri + + @property + def configuration(self): + # type: () -> Dict[str, str] + return self._configuration + +class Dataset(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'file_system_id': ConjureFieldDefinition('fileSystemId', str), + 'rid': ConjureFieldDefinition('rid', str) + } + + _file_system_id = None # type: str + _rid = None # type: str + + def __init__(self, file_system_id, rid): + # type: (str, str) -> None + self._file_system_id = file_system_id + self._rid = rid + + @property + def file_system_id(self): + # type: () -> str + return self._file_system_id + + @property + def rid(self): + # type: () -> str + """Uniquely identifies this dataset.""" + return self._rid diff --git a/conjure-python-core/src/test/resources/types/expected/package/with_imports/AliasImportedObject.py b/conjure-python-core/src/test/resources/types/expected/package/with_imports/AliasImportedObject.py deleted file mode 100644 index 0e315eb5f..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/with_imports/AliasImportedObject.py +++ /dev/null @@ -1,4 +0,0 @@ -from ..product.ManyFieldExample import ManyFieldExample - -AliasImportedObject = ManyFieldExample - diff --git a/conjure-python-core/src/test/resources/types/expected/package/with_imports/AliasImportedPrimitiveAlias.py b/conjure-python-core/src/test/resources/types/expected/package/with_imports/AliasImportedPrimitiveAlias.py deleted file mode 100644 index 6e5788ae0..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/with_imports/AliasImportedPrimitiveAlias.py +++ /dev/null @@ -1,4 +0,0 @@ -from ..product.StringAliasExample import StringAliasExample - -AliasImportedPrimitiveAlias = StringAliasExample - diff --git a/conjure-python-core/src/test/resources/types/expected/package/with_imports/AliasImportedReferenceAlias.py b/conjure-python-core/src/test/resources/types/expected/package/with_imports/AliasImportedReferenceAlias.py deleted file mode 100644 index 37fbc023d..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/with_imports/AliasImportedReferenceAlias.py +++ /dev/null @@ -1,4 +0,0 @@ -from ..product.ReferenceAliasExample import ReferenceAliasExample - -AliasImportedReferenceAlias = ReferenceAliasExample - diff --git a/conjure-python-core/src/test/resources/types/expected/package/with_imports/ComplexObjectWithImports.py b/conjure-python-core/src/test/resources/types/expected/package/with_imports/ComplexObjectWithImports.py deleted file mode 100644 index 7733a0b51..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/with_imports/ComplexObjectWithImports.py +++ /dev/null @@ -1,32 +0,0 @@ -from ..product.StringExample import StringExample -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition - -class ComplexObjectWithImports(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'string': ConjureFieldDefinition('string', str), - 'imported': ConjureFieldDefinition('imported', StringExample) - } - - _string = None # type: str - _imported = None # type: StringExample - - def __init__(self, string, imported): - # type: (str, StringExample) -> None - self._string = string - self._imported = imported - - @property - def string(self): - # type: () -> str - return self._string - - @property - def imported(self): - # type: () -> StringExample - return self._imported - diff --git a/conjure-python-core/src/test/resources/types/expected/package/with_imports/ImportService.py b/conjure-python-core/src/test/resources/types/expected/package/with_imports/ImportService.py deleted file mode 100644 index f967255fc..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/with_imports/ImportService.py +++ /dev/null @@ -1,37 +0,0 @@ -from ..product.StringExample import StringExample -from ..product_datasets.BackingFileSystem import BackingFileSystem -from conjure_python_client import ConjureDecoder -from conjure_python_client import ConjureEncoder -from conjure_python_client import Service - -class ImportService(Service): - - def test_endpoint(self, imported_string): - # type: (StringExample) -> BackingFileSystem - - _headers = { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - } # type: Dict[str, Any] - - _params = { - } # type: Dict[str, Any] - - _path_params = { - } # type: Dict[str, Any] - - _json = ConjureEncoder().default(imported_string) # type: Any - - _path = '/catalog/testEndpoint' - _path = _path.format(**_path_params) - - _response = self._request( # type: ignore - 'POST', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) - - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), BackingFileSystem) - diff --git a/conjure-python-core/src/test/resources/types/expected/package/with_imports/ImportedAliasInMaps.py b/conjure-python-core/src/test/resources/types/expected/package/with_imports/ImportedAliasInMaps.py deleted file mode 100644 index 75885c717..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/with_imports/ImportedAliasInMaps.py +++ /dev/null @@ -1,27 +0,0 @@ -from ..product.DateTimeAliasExample import DateTimeAliasExample -from ..product.RidAliasExample import RidAliasExample -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition -from conjure_python_client import DictType -from typing import Dict - -class ImportedAliasInMaps(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'aliases': ConjureFieldDefinition('aliases', DictType(RidAliasExample, DateTimeAliasExample)) - } - - _aliases = None # type: Dict[RidAliasExample, DateTimeAliasExample] - - def __init__(self, aliases): - # type: (Dict[RidAliasExample, DateTimeAliasExample]) -> None - self._aliases = aliases - - @property - def aliases(self): - # type: () -> Dict[RidAliasExample, DateTimeAliasExample] - return self._aliases - diff --git a/conjure-python-core/src/test/resources/types/expected/package/with_imports/UnionWithImports.py b/conjure-python-core/src/test/resources/types/expected/package/with_imports/UnionWithImports.py deleted file mode 100644 index 4e43f8999..000000000 --- a/conjure-python-core/src/test/resources/types/expected/package/with_imports/UnionWithImports.py +++ /dev/null @@ -1,38 +0,0 @@ -from ..product.AnyMapExample import AnyMapExample -from conjure_python_client import ConjureFieldDefinition -from conjure_python_client import ConjureUnionType - -class UnionWithImports(ConjureUnionType): - - _string = None # type: str - _imported = None # type: AnyMapExample - - @classmethod - def _options(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'string': ConjureFieldDefinition('string', str), - 'imported': ConjureFieldDefinition('imported', AnyMapExample) - } - - def __init__(self, string=None, imported=None): - if (string is not None) + (imported is not None) != 1: - raise ValueError('a union must contain a single member') - - if string is not None: - self._string = string - self._type = 'string' - if imported is not None: - self._imported = imported - self._type = 'imported' - - @property - def string(self): - # type: () -> str - return self._string - - @property - def imported(self): - # type: () -> AnyMapExample - return self._imported - diff --git a/conjure-python-core/src/test/resources/types/expected/package/with_imports/__init__.py b/conjure-python-core/src/test/resources/types/expected/package/with_imports/__init__.py index 5776934a3..640da7e7f 100644 --- a/conjure-python-core/src/test/resources/types/expected/package/with_imports/__init__.py +++ b/conjure-python-core/src/test/resources/types/expected/package/with_imports/__init__.py @@ -1,18 +1,139 @@ -from .AliasImportedObject import AliasImportedObject -from .AliasImportedPrimitiveAlias import AliasImportedPrimitiveAlias -from .AliasImportedReferenceAlias import AliasImportedReferenceAlias -from .ComplexObjectWithImports import ComplexObjectWithImports -from .ImportService import ImportService -from .ImportedAliasInMaps import ImportedAliasInMaps -from .UnionWithImports import UnionWithImports - -__all__ = [ - 'AliasImportedObject', - 'AliasImportedPrimitiveAlias', - 'AliasImportedReferenceAlias', - 'ComplexObjectWithImports', - 'ImportService', - 'ImportedAliasInMaps', - 'UnionWithImports', -] +# this is package package.with_imports +from ..product import AnyMapExample +from ..product import DateTimeAliasExample +from ..product import ManyFieldExample +from ..product import ReferenceAliasExample +from ..product import RidAliasExample +from ..product import StringAliasExample +from ..product import StringExample +from ..product_datasets import BackingFileSystem +from conjure_python_client import ConjureBeanType +from conjure_python_client import ConjureDecoder +from conjure_python_client import ConjureEncoder +from conjure_python_client import ConjureFieldDefinition +from conjure_python_client import Service +from typing import Dict +from typing import List +from typing import Optional +from typing import Set +from typing import Tuple + +class ComplexObjectWithImports(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'string': ConjureFieldDefinition('string', str), + 'imported': ConjureFieldDefinition('imported', StringExample) + } + + _string = None # type: str + _imported = None # type: StringExample + + def __init__(self, string, imported): + # type: (str, StringExample) -> None + self._string = string + self._imported = imported + + @property + def string(self): + # type: () -> str + return self._string + + @property + def imported(self): + # type: () -> StringExample + return self._imported + +class UnionWithImports(ConjureUnionType): + + _string = None # type: str + _imported = None # type: AnyMapExample + + @classmethod + def _options(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'string': ConjureFieldDefinition('string', str), + 'imported': ConjureFieldDefinition('imported', AnyMapExample) + } + + def __init__(self, string=None, imported=None): + if (string is not None) + (imported is not None) != 1: + raise ValueError('a union must contain a single member') + + if string is not None: + self._string = string + self._type = 'string' + if imported is not None: + self._imported = imported + self._type = 'imported' + + @property + def string(self): + # type: () -> str + return self._string + + @property + def imported(self): + # type: () -> AnyMapExample + return self._imported + +class ImportedAliasInMaps(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'aliases': ConjureFieldDefinition('aliases', DictType(RidAliasExample, DateTimeAliasExample)) + } + + _aliases = None # type: Dict[RidAliasExample, DateTimeAliasExample] + + def __init__(self, aliases): + # type: (Dict[RidAliasExample, DateTimeAliasExample]) -> None + self._aliases = aliases + + @property + def aliases(self): + # type: () -> Dict[RidAliasExample, DateTimeAliasExample] + return self._aliases + +class ImportService(Service): + + def test_endpoint(self, imported_string): + # type: (StringExample) -> BackingFileSystem + + _headers = { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + } # type: Dict[str, Any] + + _params = { + } # type: Dict[str, Any] + + _path_params = { + } # type: Dict[str, Any] + + _json = ConjureEncoder().default(imported_string) # type: Any + + _path = '/catalog/testEndpoint' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'POST', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), BackingFileSystem) + +AliasImportedObject = ManyFieldExample + +AliasImportedPrimitiveAlias = StringAliasExample + +AliasImportedReferenceAlias = ReferenceAliasExample diff --git a/conjure-python/src/main/java/com/palantir/conjure/python/cli/ConjurePythonCli.java b/conjure-python/src/main/java/com/palantir/conjure/python/cli/ConjurePythonCli.java index e05e976ca..c4e66652b 100644 --- a/conjure-python/src/main/java/com/palantir/conjure/python/cli/ConjurePythonCli.java +++ b/conjure-python/src/main/java/com/palantir/conjure/python/cli/ConjurePythonCli.java @@ -21,11 +21,12 @@ import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.google.common.base.Preconditions; import com.google.common.base.Throwables; +import com.google.common.collect.ImmutableSet; import com.palantir.conjure.python.ConjurePythonGenerator; import com.palantir.conjure.python.DefaultPythonFileWriter; import com.palantir.conjure.python.GeneratorConfiguration; -import com.palantir.conjure.python.service.ServiceGeneratorPython; -import com.palantir.conjure.python.types.DefaultBeanGeneratorPython; +import com.palantir.conjure.python.client.ClientGenerator; +import com.palantir.conjure.python.types.DefaultBeanGenerator; import com.palantir.conjure.spec.ConjureDefinition; import java.io.File; import java.io.IOException; @@ -121,8 +122,8 @@ static void generate(File target, File outputDirectory, GeneratorConfiguration c try { ConjureDefinition conjureDefinition = OBJECT_MAPPER.readValue(target, ConjureDefinition.class); ConjurePythonGenerator generator = new ConjurePythonGenerator( - new DefaultBeanGeneratorPython(), - new ServiceGeneratorPython(), + new DefaultBeanGenerator(ImmutableSet.of()), + new ClientGenerator(), config); generator.write(conjureDefinition, new DefaultPythonFileWriter(outputDirectory.toPath())); } catch (IOException e) { From f8d23abae2ece81b625e6af82b53645e0710b518 Mon Sep 17 00:00:00 2001 From: forozco Date: Mon, 23 Jul 2018 09:59:21 +0100 Subject: [PATCH 2/5] sort classes by name --- .../conjure/python/poet/PythonAlias.java | 3 +- .../conjure/python/poet/PythonAll.java | 5 + .../conjure/python/poet/PythonBean.java | 2 - .../conjure/python/poet/PythonClass.java | 2 + .../conjure/python/poet/PythonEnum.java | 2 - .../conjure/python/poet/PythonFile.java | 2 +- .../conjure/python/poet/PythonLine.java | 5 + .../conjure/python/poet/PythonMetaYaml.java | 5 + .../conjure/python/poet/PythonService.java | 2 - .../conjure/python/poet/PythonSetup.java | 5 + .../poet/PythonUnionTypeDefinition.java | 2 - .../python/types/DefaultBeanGenerator.java | 2 +- .../package/nested_service/__init__.py | 40 +- .../expected/package/product/__init__.py | 718 +++++++++--------- .../expected/package/with_imports/__init__.py | 102 +-- 15 files changed, 455 insertions(+), 442 deletions(-) diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonAlias.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonAlias.java index ea762f209..2cb3186a4 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonAlias.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonAlias.java @@ -20,12 +20,11 @@ @Value.Immutable public interface PythonAlias extends PythonClass { - String aliasName(); String aliasTarget(); @Override default void emit(PythonPoetWriter poetWriter) { - poetWriter.writeIndentedLine(String.format("%s = %s", aliasName(), aliasTarget())); + poetWriter.writeIndentedLine(String.format("%s = %s", className(), aliasTarget())); poetWriter.writeLine(); } diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonAll.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonAll.java index 654fe1d93..b88137476 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonAll.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonAll.java @@ -11,6 +11,11 @@ public interface PythonAll extends PythonClass { List contents(); + @Override + default String className() { + return "__all__"; + } + @Override default void emit(PythonPoetWriter poetWriter) { poetWriter.maintainingIndent(() -> { diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonBean.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonBean.java index de7878b32..2c4fb506d 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonBean.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonBean.java @@ -43,8 +43,6 @@ default Set requiredImports() { return DEFAULT_IMPORTS; } - String className(); - Optional docs(); List fields(); diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonClass.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonClass.java index e66ccac67..469efd7c5 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonClass.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonClass.java @@ -22,6 +22,8 @@ public interface PythonClass extends Emittable { Set requiredImports(); + String className(); + String packageName(); } diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonEnum.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonEnum.java index 5141df0ce..c8475898c 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonEnum.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonEnum.java @@ -35,8 +35,6 @@ default Set requiredImports() { return DEFAULT_IMPORTS; } - String className(); - Optional docs(); List values(); diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonFile.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonFile.java index 250d227bc..dee65a4be 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonFile.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonFile.java @@ -66,7 +66,7 @@ public int compare(PythonClass pc1, PythonClass pc2) { } else if (!(pc1 instanceof PythonAlias) && pc2 instanceof PythonAlias) { return -1; } else { - return 0; + return Comparator.comparing(PythonClass::className).compare(pc1, pc2); } } } diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonLine.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonLine.java index 8f7b9a8f0..ddd717660 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonLine.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonLine.java @@ -10,6 +10,11 @@ public interface PythonLine extends PythonClass { String text(); + @Override + default String className() { + return "__version__"; + } + @Override default void emit(PythonPoetWriter poetWriter) { poetWriter.writeIndentedLine(text()); diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonMetaYaml.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonMetaYaml.java index 8408204b9..1ab9091a6 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonMetaYaml.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonMetaYaml.java @@ -10,6 +10,11 @@ @Value.Immutable public interface PythonMetaYaml extends PythonClass { + @Override + default String className() { + return ""; + } + @Override default String packageName() { return "conda_recipe"; diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonService.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonService.java index fbd9610ae..ddbba0c90 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonService.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonService.java @@ -42,8 +42,6 @@ default Set requiredImports() { return DEFAULT_IMPORTS; } - String className(); - Optional docs(); List endpointDefinitions(); diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonSetup.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonSetup.java index aefb2c13d..4c52789fe 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonSetup.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonSetup.java @@ -23,6 +23,11 @@ default Set requiredImports() { return DEFAULT_IMPORTS; } + @Override + default String className() { + return ""; + } + @Override default String packageName() { return ""; diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonUnionTypeDefinition.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonUnionTypeDefinition.java index ee80ef8fe..1c4750853 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonUnionTypeDefinition.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonUnionTypeDefinition.java @@ -44,8 +44,6 @@ default Set requiredImports() { return DEFAULT_IMPORTS; } - String className(); - Optional docs(); /** diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/types/DefaultBeanGenerator.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/types/DefaultBeanGenerator.java index 0876821a2..13fefa339 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/types/DefaultBeanGenerator.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/types/DefaultBeanGenerator.java @@ -177,7 +177,7 @@ private PythonAlias generateObject( .collect(Collectors.toSet()); return PythonAlias.builder() - .aliasName(typeDef.getTypeName().getName()) + .className(typeDef.getTypeName().getName()) .aliasTarget(mapper.getTypeName(typeDef.getAlias())) .packageName(packageName) .addAllRequiredImports(imports) diff --git a/conjure-python-core/src/test/resources/types/expected/package/nested_service/__init__.py b/conjure-python-core/src/test/resources/types/expected/package/nested_service/__init__.py index 921540efa..af15166a0 100644 --- a/conjure-python-core/src/test/resources/types/expected/package/nested_service/__init__.py +++ b/conjure-python-core/src/test/resources/types/expected/package/nested_service/__init__.py @@ -10,26 +10,6 @@ from typing import Set from typing import Tuple -class SimpleObject(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'string': ConjureFieldDefinition('string', str) - } - - _string = None # type: str - - def __init__(self, string): - # type: (str) -> None - self._string = string - - @property - def string(self): - # type: () -> str - return self._string - class SimpleNestedService(Service): def test_endpoint(self, string): @@ -61,3 +41,23 @@ def test_endpoint(self, string): _decoder = ConjureDecoder() return _decoder.decode(_response.json(), str) +class SimpleObject(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'string': ConjureFieldDefinition('string', str) + } + + _string = None # type: str + + def __init__(self, string): + # type: (str) -> None + self._string = string + + @property + def string(self): + # type: () -> str + return self._string + diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/__init__.py b/conjure-python-core/src/test/resources/types/expected/package/product/__init__.py index 310846831..9e8602713 100644 --- a/conjure-python-core/src/test/resources/types/expected/package/product/__init__.py +++ b/conjure-python-core/src/test/resources/types/expected/package/product/__init__.py @@ -8,133 +8,201 @@ from typing import Set from typing import Tuple -class CreateDatasetRequest(ConjureBeanType): +class AliasAsMapKeyExample(ConjureBeanType): @classmethod def _fields(cls): # type: () -> Dict[str, ConjureFieldDefinition] return { - 'file_system_id': ConjureFieldDefinition('fileSystemId', str), - 'path': ConjureFieldDefinition('path', str) + 'strings': ConjureFieldDefinition('strings', DictType(StringAliasExample, ManyFieldExample)), + 'rids': ConjureFieldDefinition('rids', DictType(RidAliasExample, ManyFieldExample)), + 'bearertokens': ConjureFieldDefinition('bearertokens', DictType(BearerTokenAliasExample, ManyFieldExample)), + 'integers': ConjureFieldDefinition('integers', DictType(IntegerAliasExample, ManyFieldExample)), + 'safelongs': ConjureFieldDefinition('safelongs', DictType(SafeLongAliasExample, ManyFieldExample)), + 'datetimes': ConjureFieldDefinition('datetimes', DictType(DateTimeAliasExample, ManyFieldExample)), + 'uuids': ConjureFieldDefinition('uuids', DictType(UuidAliasExample, ManyFieldExample)) } - _file_system_id = None # type: str - _path = None # type: str + _strings = None # type: Dict[StringAliasExample, ManyFieldExample] + _rids = None # type: Dict[RidAliasExample, ManyFieldExample] + _bearertokens = None # type: Dict[BearerTokenAliasExample, ManyFieldExample] + _integers = None # type: Dict[IntegerAliasExample, ManyFieldExample] + _safelongs = None # type: Dict[SafeLongAliasExample, ManyFieldExample] + _datetimes = None # type: Dict[DateTimeAliasExample, ManyFieldExample] + _uuids = None # type: Dict[UuidAliasExample, ManyFieldExample] - def __init__(self, file_system_id, path): - # type: (str, str) -> None - self._file_system_id = file_system_id - self._path = path + def __init__(self, strings, rids, bearertokens, integers, safelongs, datetimes, uuids): + # type: (Dict[StringAliasExample, ManyFieldExample], Dict[RidAliasExample, ManyFieldExample], Dict[BearerTokenAliasExample, ManyFieldExample], Dict[IntegerAliasExample, ManyFieldExample], Dict[SafeLongAliasExample, ManyFieldExample], Dict[DateTimeAliasExample, ManyFieldExample], Dict[UuidAliasExample, ManyFieldExample]) -> None + self._strings = strings + self._rids = rids + self._bearertokens = bearertokens + self._integers = integers + self._safelongs = safelongs + self._datetimes = datetimes + self._uuids = uuids @property - def file_system_id(self): - # type: () -> str - return self._file_system_id + def strings(self): + # type: () -> Dict[StringAliasExample, ManyFieldExample] + return self._strings @property - def path(self): - # type: () -> str - return self._path + def rids(self): + # type: () -> Dict[RidAliasExample, ManyFieldExample] + return self._rids -class StringExample(ConjureBeanType): + @property + def bearertokens(self): + # type: () -> Dict[BearerTokenAliasExample, ManyFieldExample] + return self._bearertokens + + @property + def integers(self): + # type: () -> Dict[IntegerAliasExample, ManyFieldExample] + return self._integers + + @property + def safelongs(self): + # type: () -> Dict[SafeLongAliasExample, ManyFieldExample] + return self._safelongs + + @property + def datetimes(self): + # type: () -> Dict[DateTimeAliasExample, ManyFieldExample] + return self._datetimes + + @property + def uuids(self): + # type: () -> Dict[UuidAliasExample, ManyFieldExample] + return self._uuids + +class AnyExample(ConjureBeanType): @classmethod def _fields(cls): # type: () -> Dict[str, ConjureFieldDefinition] return { - 'string': ConjureFieldDefinition('string', str) + 'any': ConjureFieldDefinition('any', object) } - _string = None # type: str + _any = None # type: Any - def __init__(self, string): - # type: (str) -> None - self._string = string + def __init__(self, any): + # type: (Any) -> None + self._any = any @property - def string(self): - # type: () -> str - return self._string + def any(self): + # type: () -> Any + return self._any -class IntegerExample(ConjureBeanType): +class AnyMapExample(ConjureBeanType): @classmethod def _fields(cls): # type: () -> Dict[str, ConjureFieldDefinition] return { - 'integer': ConjureFieldDefinition('integer', int) + 'items': ConjureFieldDefinition('items', DictType(str, object)) } - _integer = None # type: int + _items = None # type: Dict[str, Any] - def __init__(self, integer): - # type: (int) -> None - self._integer = integer + def __init__(self, items): + # type: (Dict[str, Any]) -> None + self._items = items @property - def integer(self): - # type: () -> int - return self._integer + def items(self): + # type: () -> Dict[str, Any] + return self._items -class SafeLongExample(ConjureBeanType): +class BearerTokenExample(ConjureBeanType): @classmethod def _fields(cls): # type: () -> Dict[str, ConjureFieldDefinition] return { - 'safe_long_value': ConjureFieldDefinition('safeLongValue', int) + 'bearer_token_value': ConjureFieldDefinition('bearerTokenValue', str) } - _safe_long_value = None # type: int + _bearer_token_value = None # type: str - def __init__(self, safe_long_value): - # type: (int) -> None - self._safe_long_value = safe_long_value + def __init__(self, bearer_token_value): + # type: (str) -> None + self._bearer_token_value = bearer_token_value @property - def safe_long_value(self): - # type: () -> int - return self._safe_long_value + def bearer_token_value(self): + # type: () -> str + return self._bearer_token_value -class RidExample(ConjureBeanType): +class BinaryExample(ConjureBeanType): @classmethod def _fields(cls): # type: () -> Dict[str, ConjureFieldDefinition] return { - 'rid_value': ConjureFieldDefinition('ridValue', str) + 'binary': ConjureFieldDefinition('binary', BinaryType()) } - _rid_value = None # type: str + _binary = None # type: Any - def __init__(self, rid_value): - # type: (str) -> None - self._rid_value = rid_value + def __init__(self, binary): + # type: (Any) -> None + self._binary = binary @property - def rid_value(self): - # type: () -> str - return self._rid_value + def binary(self): + # type: () -> Any + return self._binary -class BearerTokenExample(ConjureBeanType): +class BooleanExample(ConjureBeanType): @classmethod def _fields(cls): # type: () -> Dict[str, ConjureFieldDefinition] return { - 'bearer_token_value': ConjureFieldDefinition('bearerTokenValue', str) + 'coin': ConjureFieldDefinition('coin', bool) } - _bearer_token_value = None # type: str + _coin = None # type: bool - def __init__(self, bearer_token_value): - # type: (str) -> None - self._bearer_token_value = bearer_token_value + def __init__(self, coin): + # type: (bool) -> None + self._coin = coin @property - def bearer_token_value(self): + def coin(self): + # type: () -> bool + return self._coin + +class CreateDatasetRequest(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'file_system_id': ConjureFieldDefinition('fileSystemId', str), + 'path': ConjureFieldDefinition('path', str) + } + + _file_system_id = None # type: str + _path = None # type: str + + def __init__(self, file_system_id, path): + # type: (str, str) -> None + self._file_system_id = file_system_id + self._path = path + + @property + def file_system_id(self): # type: () -> str - return self._bearer_token_value + return self._file_system_id + + @property + def path(self): + # type: () -> str + return self._path class DateTimeExample(ConjureBeanType): @@ -176,45 +244,68 @@ def double_value(self): # type: () -> float return self._double_value -class BinaryExample(ConjureBeanType): +class EmptyObjectExample(ConjureBeanType): @classmethod def _fields(cls): # type: () -> Dict[str, ConjureFieldDefinition] return { - 'binary': ConjureFieldDefinition('binary', BinaryType()) } - _binary = None # type: Any - def __init__(self, binary): - # type: (Any) -> None - self._binary = binary + +class EnumExample(ConjureEnumType): + """This enumerates the numbers 1:2.""" + + ONE = 'ONE' + '''ONE''' + TWO = 'TWO' + '''TWO''' + UNKNOWN = 'UNKNOWN' + '''UNKNOWN''' + + def __reduce_ex__(self, proto): + return self.__class__, (self.name,) + +class EnumFieldExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'enum': ConjureFieldDefinition('enum', EnumExample) + } + + _enum = None # type: EnumExample + + def __init__(self, enum): + # type: (EnumExample) -> None + self._enum = enum @property - def binary(self): - # type: () -> Any - return self._binary + def enum(self): + # type: () -> EnumExample + return self._enum -class OptionalExample(ConjureBeanType): +class IntegerExample(ConjureBeanType): @classmethod def _fields(cls): # type: () -> Dict[str, ConjureFieldDefinition] return { - 'item': ConjureFieldDefinition('item', OptionalType(str)) + 'integer': ConjureFieldDefinition('integer', int) } - _item = None # type: Optional[str] + _integer = None # type: int - def __init__(self, item): - # type: (Optional[str]) -> None - self._item = item + def __init__(self, integer): + # type: (int) -> None + self._integer = integer @property - def item(self): - # type: () -> Optional[str] - return self._item + def integer(self): + # type: () -> int + return self._integer class ListExample(ConjureBeanType): @@ -252,166 +343,129 @@ def double_items(self): # type: () -> List[float] return self._double_items -class SetExample(ConjureBeanType): +class ManyFieldExample(ConjureBeanType): @classmethod def _fields(cls): # type: () -> Dict[str, ConjureFieldDefinition] return { + 'string': ConjureFieldDefinition('string', str), + 'integer': ConjureFieldDefinition('integer', int), + 'double_value': ConjureFieldDefinition('doubleValue', float), + 'optional_item': ConjureFieldDefinition('optionalItem', OptionalType(str)), 'items': ConjureFieldDefinition('items', ListType(str)), - 'double_items': ConjureFieldDefinition('doubleItems', ListType(float)) + 'set': ConjureFieldDefinition('set', ListType(str)), + 'map': ConjureFieldDefinition('map', DictType(str, str)), + 'alias': ConjureFieldDefinition('alias', StringAliasExample) } - _items = None # type: List[str] - _double_items = None # type: List[float] + _string = None # type: str + _integer = None # type: int + _double_value = None # type: float + _optional_item = None # type: Optional[str] + _items = None # type: List[str] + _set = None # type: List[str] + _map = None # type: Dict[str, str] + _alias = None # type: StringAliasExample - def __init__(self, items, double_items): - # type: (List[str], List[float]) -> None + def __init__(self, string, integer, double_value, optional_item, items, set, map, alias): + # type: (str, int, float, Optional[str], List[str], List[str], Dict[str, str], StringAliasExample) -> None + self._string = string + self._integer = integer + self._double_value = double_value + self._optional_item = optional_item self._items = items - self._double_items = double_items + self._set = set + self._map = map + self._alias = alias @property - def items(self): - # type: () -> List[str] - return self._items + def string(self): + # type: () -> str + """docs for string field""" + return self._string @property - def double_items(self): - # type: () -> List[float] - return self._double_items - -class MapExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'items': ConjureFieldDefinition('items', DictType(str, str)) - } + def integer(self): + # type: () -> int + """docs for integer field""" + return self._integer - _items = None # type: Dict[str, str] + @property + def double_value(self): + # type: () -> float + """docs for doubleValue field""" + return self._double_value - def __init__(self, items): - # type: (Dict[str, str]) -> None - self._items = items + @property + def optional_item(self): + # type: () -> Optional[str] + """docs for optionalItem field""" + return self._optional_item @property def items(self): - # type: () -> Dict[str, str] + # type: () -> List[str] + """docs for items field""" return self._items -class EnumExample(ConjureEnumType): - """This enumerates the numbers 1:2.""" - - ONE = 'ONE' - '''ONE''' - TWO = 'TWO' - '''TWO''' - UNKNOWN = 'UNKNOWN' - '''UNKNOWN''' - - def __reduce_ex__(self, proto): - return self.__class__, (self.name,) - -class EnumFieldExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'enum': ConjureFieldDefinition('enum', EnumExample) - } - - _enum = None # type: EnumExample - - def __init__(self, enum): - # type: (EnumExample) -> None - self._enum = enum - @property - def enum(self): - # type: () -> EnumExample - return self._enum - -class BooleanExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'coin': ConjureFieldDefinition('coin', bool) - } - - _coin = None # type: bool - - def __init__(self, coin): - # type: (bool) -> None - self._coin = coin + def set(self): + # type: () -> List[str] + """docs for set field""" + return self._set @property - def coin(self): - # type: () -> bool - return self._coin - -class AnyExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'any': ConjureFieldDefinition('any', object) - } - - _any = None # type: Any - - def __init__(self, any): - # type: (Any) -> None - self._any = any + def map(self): + # type: () -> Dict[str, str] + """docs for map field""" + return self._map @property - def any(self): - # type: () -> Any - return self._any + def alias(self): + # type: () -> StringAliasExample + """docs for alias field""" + return self._alias -class AnyMapExample(ConjureBeanType): +class MapExample(ConjureBeanType): @classmethod def _fields(cls): # type: () -> Dict[str, ConjureFieldDefinition] return { - 'items': ConjureFieldDefinition('items', DictType(str, object)) + 'items': ConjureFieldDefinition('items', DictType(str, str)) } - _items = None # type: Dict[str, Any] + _items = None # type: Dict[str, str] def __init__(self, items): - # type: (Dict[str, Any]) -> None + # type: (Dict[str, str]) -> None self._items = items @property def items(self): - # type: () -> Dict[str, Any] + # type: () -> Dict[str, str] return self._items -class UuidExample(ConjureBeanType): +class OptionalExample(ConjureBeanType): @classmethod def _fields(cls): # type: () -> Dict[str, ConjureFieldDefinition] return { - 'uuid': ConjureFieldDefinition('uuid', str) + 'item': ConjureFieldDefinition('item', OptionalType(str)) } - _uuid = None # type: str + _item = None # type: Optional[str] - def __init__(self, uuid): - # type: (str) -> None - self._uuid = uuid + def __init__(self, item): + # type: (Optional[str]) -> None + self._item = item @property - def uuid(self): - # type: () -> str - return self._uuid + def item(self): + # type: () -> Optional[str] + return self._item class PrimitiveOptionalsExample(ConjureBeanType): @@ -481,89 +535,137 @@ def uuid(self): # type: () -> Optional[str] return self._uuid -class ManyFieldExample(ConjureBeanType): +class ReservedKeyExample(ConjureBeanType): @classmethod def _fields(cls): # type: () -> Dict[str, ConjureFieldDefinition] return { - 'string': ConjureFieldDefinition('string', str), - 'integer': ConjureFieldDefinition('integer', int), - 'double_value': ConjureFieldDefinition('doubleValue', float), - 'optional_item': ConjureFieldDefinition('optionalItem', OptionalType(str)), - 'items': ConjureFieldDefinition('items', ListType(str)), - 'set': ConjureFieldDefinition('set', ListType(str)), - 'map': ConjureFieldDefinition('map', DictType(str, str)), - 'alias': ConjureFieldDefinition('alias', StringAliasExample) + 'package': ConjureFieldDefinition('package', str), + 'interface': ConjureFieldDefinition('interface', str), + 'field_name_with_dashes': ConjureFieldDefinition('field-name-with-dashes', str), + 'memoized_hash_code': ConjureFieldDefinition('memoizedHashCode', int) } - _string = None # type: str - _integer = None # type: int - _double_value = None # type: float - _optional_item = None # type: Optional[str] - _items = None # type: List[str] - _set = None # type: List[str] - _map = None # type: Dict[str, str] - _alias = None # type: StringAliasExample + _package = None # type: str + _interface = None # type: str + _field_name_with_dashes = None # type: str + _memoized_hash_code = None # type: int - def __init__(self, string, integer, double_value, optional_item, items, set, map, alias): - # type: (str, int, float, Optional[str], List[str], List[str], Dict[str, str], StringAliasExample) -> None - self._string = string - self._integer = integer - self._double_value = double_value - self._optional_item = optional_item - self._items = items - self._set = set - self._map = map - self._alias = alias + def __init__(self, package, interface, field_name_with_dashes, memoized_hash_code): + # type: (str, str, str, int) -> None + self._package = package + self._interface = interface + self._field_name_with_dashes = field_name_with_dashes + self._memoized_hash_code = memoized_hash_code @property - def string(self): + def package(self): # type: () -> str - """docs for string field""" - return self._string + return self._package @property - def integer(self): + def interface(self): + # type: () -> str + return self._interface + + @property + def field_name_with_dashes(self): + # type: () -> str + return self._field_name_with_dashes + + @property + def memoized_hash_code(self): # type: () -> int - """docs for integer field""" - return self._integer + return self._memoized_hash_code + +class RidExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'rid_value': ConjureFieldDefinition('ridValue', str) + } + + _rid_value = None # type: str + + def __init__(self, rid_value): + # type: (str) -> None + self._rid_value = rid_value @property - def double_value(self): - # type: () -> float - """docs for doubleValue field""" - return self._double_value + def rid_value(self): + # type: () -> str + return self._rid_value + +class SafeLongExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'safe_long_value': ConjureFieldDefinition('safeLongValue', int) + } + + _safe_long_value = None # type: int + + def __init__(self, safe_long_value): + # type: (int) -> None + self._safe_long_value = safe_long_value @property - def optional_item(self): - # type: () -> Optional[str] - """docs for optionalItem field""" - return self._optional_item + def safe_long_value(self): + # type: () -> int + return self._safe_long_value + +class SetExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'items': ConjureFieldDefinition('items', ListType(str)), + 'double_items': ConjureFieldDefinition('doubleItems', ListType(float)) + } + + _items = None # type: List[str] + _double_items = None # type: List[float] + + def __init__(self, items, double_items): + # type: (List[str], List[float]) -> None + self._items = items + self._double_items = double_items @property def items(self): # type: () -> List[str] - """docs for items field""" return self._items @property - def set(self): - # type: () -> List[str] - """docs for set field""" - return self._set + def double_items(self): + # type: () -> List[float] + return self._double_items - @property - def map(self): - # type: () -> Dict[str, str] - """docs for map field""" - return self._map +class StringExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'string': ConjureFieldDefinition('string', str) + } + + _string = None # type: str + + def __init__(self, string): + # type: (str) -> None + self._string = string @property - def alias(self): - # type: () -> StringAliasExample - """docs for alias field""" - return self._alias + def string(self): + # type: () -> str + return self._string class UnionTypeExample(ConjureUnionType): """A type which can either be a StringExample, a set of strings, or an integer.""" @@ -651,149 +753,47 @@ def interface(self): # type: () -> int return self._interface -class EmptyObjectExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - } - - - -class AliasAsMapKeyExample(ConjureBeanType): - - @classmethod - def _fields(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'strings': ConjureFieldDefinition('strings', DictType(StringAliasExample, ManyFieldExample)), - 'rids': ConjureFieldDefinition('rids', DictType(RidAliasExample, ManyFieldExample)), - 'bearertokens': ConjureFieldDefinition('bearertokens', DictType(BearerTokenAliasExample, ManyFieldExample)), - 'integers': ConjureFieldDefinition('integers', DictType(IntegerAliasExample, ManyFieldExample)), - 'safelongs': ConjureFieldDefinition('safelongs', DictType(SafeLongAliasExample, ManyFieldExample)), - 'datetimes': ConjureFieldDefinition('datetimes', DictType(DateTimeAliasExample, ManyFieldExample)), - 'uuids': ConjureFieldDefinition('uuids', DictType(UuidAliasExample, ManyFieldExample)) - } - - _strings = None # type: Dict[StringAliasExample, ManyFieldExample] - _rids = None # type: Dict[RidAliasExample, ManyFieldExample] - _bearertokens = None # type: Dict[BearerTokenAliasExample, ManyFieldExample] - _integers = None # type: Dict[IntegerAliasExample, ManyFieldExample] - _safelongs = None # type: Dict[SafeLongAliasExample, ManyFieldExample] - _datetimes = None # type: Dict[DateTimeAliasExample, ManyFieldExample] - _uuids = None # type: Dict[UuidAliasExample, ManyFieldExample] - - def __init__(self, strings, rids, bearertokens, integers, safelongs, datetimes, uuids): - # type: (Dict[StringAliasExample, ManyFieldExample], Dict[RidAliasExample, ManyFieldExample], Dict[BearerTokenAliasExample, ManyFieldExample], Dict[IntegerAliasExample, ManyFieldExample], Dict[SafeLongAliasExample, ManyFieldExample], Dict[DateTimeAliasExample, ManyFieldExample], Dict[UuidAliasExample, ManyFieldExample]) -> None - self._strings = strings - self._rids = rids - self._bearertokens = bearertokens - self._integers = integers - self._safelongs = safelongs - self._datetimes = datetimes - self._uuids = uuids - - @property - def strings(self): - # type: () -> Dict[StringAliasExample, ManyFieldExample] - return self._strings - - @property - def rids(self): - # type: () -> Dict[RidAliasExample, ManyFieldExample] - return self._rids - - @property - def bearertokens(self): - # type: () -> Dict[BearerTokenAliasExample, ManyFieldExample] - return self._bearertokens - - @property - def integers(self): - # type: () -> Dict[IntegerAliasExample, ManyFieldExample] - return self._integers - - @property - def safelongs(self): - # type: () -> Dict[SafeLongAliasExample, ManyFieldExample] - return self._safelongs - - @property - def datetimes(self): - # type: () -> Dict[DateTimeAliasExample, ManyFieldExample] - return self._datetimes - - @property - def uuids(self): - # type: () -> Dict[UuidAliasExample, ManyFieldExample] - return self._uuids - -class ReservedKeyExample(ConjureBeanType): +class UuidExample(ConjureBeanType): @classmethod def _fields(cls): # type: () -> Dict[str, ConjureFieldDefinition] return { - 'package': ConjureFieldDefinition('package', str), - 'interface': ConjureFieldDefinition('interface', str), - 'field_name_with_dashes': ConjureFieldDefinition('field-name-with-dashes', str), - 'memoized_hash_code': ConjureFieldDefinition('memoizedHashCode', int) + 'uuid': ConjureFieldDefinition('uuid', str) } - _package = None # type: str - _interface = None # type: str - _field_name_with_dashes = None # type: str - _memoized_hash_code = None # type: int + _uuid = None # type: str - def __init__(self, package, interface, field_name_with_dashes, memoized_hash_code): - # type: (str, str, str, int) -> None - self._package = package - self._interface = interface - self._field_name_with_dashes = field_name_with_dashes - self._memoized_hash_code = memoized_hash_code + def __init__(self, uuid): + # type: (str) -> None + self._uuid = uuid @property - def package(self): + def uuid(self): # type: () -> str - return self._package + return self._uuid - @property - def interface(self): - # type: () -> str - return self._interface +BearerTokenAliasExample = str - @property - def field_name_with_dashes(self): - # type: () -> str - return self._field_name_with_dashes +BinaryAliasExample = BinaryType() - @property - def memoized_hash_code(self): - # type: () -> int - return self._memoized_hash_code +BooleanAliasExample = bool -StringAliasExample = str +DateTimeAliasExample = str DoubleAliasExample = float IntegerAliasExample = int -BooleanAliasExample = bool +MapAliasExample = DictType(str, object) -SafeLongAliasExample = int +ReferenceAliasExample = AnyExample RidAliasExample = str -BearerTokenAliasExample = str - -UuidAliasExample = str - -MapAliasExample = DictType(str, object) - -ReferenceAliasExample = AnyExample +SafeLongAliasExample = int -DateTimeAliasExample = str +StringAliasExample = str -BinaryAliasExample = BinaryType() +UuidAliasExample = str diff --git a/conjure-python-core/src/test/resources/types/expected/package/with_imports/__init__.py b/conjure-python-core/src/test/resources/types/expected/package/with_imports/__init__.py index 640da7e7f..3e15299ae 100644 --- a/conjure-python-core/src/test/resources/types/expected/package/with_imports/__init__.py +++ b/conjure-python-core/src/test/resources/types/expected/package/with_imports/__init__.py @@ -46,39 +46,36 @@ def imported(self): # type: () -> StringExample return self._imported -class UnionWithImports(ConjureUnionType): +class ImportService(Service): - _string = None # type: str - _imported = None # type: AnyMapExample + def test_endpoint(self, imported_string): + # type: (StringExample) -> BackingFileSystem - @classmethod - def _options(cls): - # type: () -> Dict[str, ConjureFieldDefinition] - return { - 'string': ConjureFieldDefinition('string', str), - 'imported': ConjureFieldDefinition('imported', AnyMapExample) - } + _headers = { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + } # type: Dict[str, Any] - def __init__(self, string=None, imported=None): - if (string is not None) + (imported is not None) != 1: - raise ValueError('a union must contain a single member') + _params = { + } # type: Dict[str, Any] - if string is not None: - self._string = string - self._type = 'string' - if imported is not None: - self._imported = imported - self._type = 'imported' + _path_params = { + } # type: Dict[str, Any] - @property - def string(self): - # type: () -> str - return self._string + _json = ConjureEncoder().default(imported_string) # type: Any - @property - def imported(self): - # type: () -> AnyMapExample - return self._imported + _path = '/catalog/testEndpoint' + _path = _path.format(**_path_params) + + _response = self._request( # type: ignore + 'POST', + self._uri + _path, + params=_params, + headers=_headers, + json=_json) + + _decoder = ConjureDecoder() + return _decoder.decode(_response.json(), BackingFileSystem) class ImportedAliasInMaps(ConjureBeanType): @@ -100,36 +97,39 @@ def aliases(self): # type: () -> Dict[RidAliasExample, DateTimeAliasExample] return self._aliases -class ImportService(Service): - - def test_endpoint(self, imported_string): - # type: (StringExample) -> BackingFileSystem - - _headers = { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - } # type: Dict[str, Any] +class UnionWithImports(ConjureUnionType): - _params = { - } # type: Dict[str, Any] + _string = None # type: str + _imported = None # type: AnyMapExample - _path_params = { - } # type: Dict[str, Any] + @classmethod + def _options(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'string': ConjureFieldDefinition('string', str), + 'imported': ConjureFieldDefinition('imported', AnyMapExample) + } - _json = ConjureEncoder().default(imported_string) # type: Any + def __init__(self, string=None, imported=None): + if (string is not None) + (imported is not None) != 1: + raise ValueError('a union must contain a single member') - _path = '/catalog/testEndpoint' - _path = _path.format(**_path_params) + if string is not None: + self._string = string + self._type = 'string' + if imported is not None: + self._imported = imported + self._type = 'imported' - _response = self._request( # type: ignore - 'POST', - self._uri + _path, - params=_params, - headers=_headers, - json=_json) + @property + def string(self): + # type: () -> str + return self._string - _decoder = ConjureDecoder() - return _decoder.decode(_response.json(), BackingFileSystem) + @property + def imported(self): + # type: () -> AnyMapExample + return self._imported AliasImportedObject = ManyFieldExample From 45b72d7b86126b5b55caafa23925d5386db3e233 Mon Sep 17 00:00:00 2001 From: forozco Date: Mon, 23 Jul 2018 10:18:46 +0100 Subject: [PATCH 3/5] add integration tests --- build.gradle | 1 + .../conjure/python/poet/PythonBean.java | 3 +-- conjure-python-verifier/build.gradle | 19 ++++++++++++++++-- .../python/test/client/conftest.py | 14 +++++++++++++ .../test/client/test_circular_imports.py | 20 +++++++++++++++++++ .../python/test/client/test_verify_spec.py | 14 +++++++++++++ .../src/main/conjure/integration.conjure.yml | 9 +++++++++ 7 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 conjure-python-verifier/python/test/client/test_circular_imports.py create mode 100644 conjure-python-verifier/src/main/conjure/integration.conjure.yml diff --git a/build.gradle b/build.gradle index 02f5696d3..9af02d4c7 100644 --- a/build.gradle +++ b/build.gradle @@ -29,6 +29,7 @@ buildscript { classpath 'com.netflix.nebula:nebula-dependency-recommender:5.2.0' classpath 'com.palantir.baseline:gradle-baseline-java:0.19.0' classpath 'com.palantir.configurationresolver:gradle-configuration-resolver-plugin:0.3.0' + classpath 'com.palantir.gradle.conjure:gradle-conjure:4.2.0' classpath 'com.palantir.gradle.gitversion:gradle-git-version:0.10.0' classpath 'gradle.plugin.com.palantir:gradle-circle-style:1.1.2' classpath 'gradle.plugin.org.inferred:gradle-processors:1.2.15' diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonBean.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonBean.java index 2c4fb506d..678553b38 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonBean.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonBean.java @@ -34,8 +34,7 @@ public interface PythonBean extends PythonClass { PythonImport.of(PythonClassName.of("typing", "Dict")), PythonImport.of(PythonClassName.of("typing", "Tuple")), PythonImport.of(PythonClassName.of("typing", "Optional")), - PythonImport.of(PythonClassName.of("conjure_python_client", "ConjureBeanType")), - PythonImport.of(PythonClassName.of("conjure_python_client", "ConjureFieldDefinition"))); + PythonImport.of(PythonClassName.of("conjure_python_client", "*"))); @Override @Value.Default diff --git a/conjure-python-verifier/build.gradle b/conjure-python-verifier/build.gradle index 382170f16..a14dace23 100644 --- a/conjure-python-verifier/build.gradle +++ b/conjure-python-verifier/build.gradle @@ -4,6 +4,8 @@ import static org.apache.tools.ant.taskdefs.condition.Os.* +apply plugin: 'com.palantir.conjure' + ext { osClassifier = isFamily(FAMILY_MAC) ? "osx" : "linux" } @@ -50,5 +52,18 @@ task generateVerifierBindings(type: JavaExec, dependsOn: [copyTestCases, ':conju doLast { delete "python/test/setup.py" } } -tasks.idea.dependsOn unpackVerificationServer, generateVerifierBindings -tasks.build.dependsOn unpackVerificationServer, generateVerifierBindings +task generateIntegrationTests(type: JavaExec, dependsOn: [compileConjure, ':conjure-python:compileJava']) { + main = "com.palantir.conjure.python.cli.ConjurePythonCli" + classpath = project(':conjure-python').sourceSets.main.runtimeClasspath + args 'generate', + 'build/conjure-ir/conjure-python-verifier.json', + 'python/test', + '--packageName', 'generated', + '--packageVersion', '0.0.0' + + inputs.files configurations.verificationApi + doLast { delete "python/test/setup.py" } +} + +tasks.idea.dependsOn unpackVerificationServer, generateVerifierBindings, generateIntegrationTests +tasks.build.dependsOn unpackVerificationServer, generateVerifierBindings, generateIntegrationTests diff --git a/conjure-python-verifier/python/test/client/conftest.py b/conjure-python-verifier/python/test/client/conftest.py index a47cd004b..0cae722e3 100644 --- a/conjure-python-verifier/python/test/client/conftest.py +++ b/conjure-python-verifier/python/test/client/conftest.py @@ -1,3 +1,17 @@ +# (c) Copyright 2018 Palantir Technologies Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import pytest import subprocess import yaml diff --git a/conjure-python-verifier/python/test/client/test_circular_imports.py b/conjure-python-verifier/python/test/client/test_circular_imports.py new file mode 100644 index 000000000..dcd60a579 --- /dev/null +++ b/conjure-python-verifier/python/test/client/test_circular_imports.py @@ -0,0 +1,20 @@ +# (c) Copyright 2018 Palantir Technologies Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +def test_circular_import(): + from ..generated.integration import ObjectExample, ObjectAlias + object_example = ObjectExample(None) + object_alias = ObjectAlias(None) + assert object_alias == object_example \ No newline at end of file diff --git a/conjure-python-verifier/python/test/client/test_verify_spec.py b/conjure-python-verifier/python/test/client/test_verify_spec.py index f60c504f7..70a1ff7bc 100644 --- a/conjure-python-verifier/python/test/client/test_verify_spec.py +++ b/conjure-python-verifier/python/test/client/test_verify_spec.py @@ -1,3 +1,17 @@ +# (c) Copyright 2018 Palantir Technologies Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import json import pytest import re diff --git a/conjure-python-verifier/src/main/conjure/integration.conjure.yml b/conjure-python-verifier/src/main/conjure/integration.conjure.yml new file mode 100644 index 000000000..3c473860e --- /dev/null +++ b/conjure-python-verifier/src/main/conjure/integration.conjure.yml @@ -0,0 +1,9 @@ +types: + definitions: + default-package: com.palantir.integration + objects: + ObjectExample: + fields: + recursiveField: optional + ObjectAlias: + alias: ObjectExample From 8d717590f7e2452607362822512c0cbe2d119f3b Mon Sep 17 00:00:00 2001 From: forozco Date: Mon, 23 Jul 2018 10:25:16 +0100 Subject: [PATCH 4/5] fix --- .../resources/services/expected/package/product/__init__.py | 3 +-- .../services/expected/package/product_datasets/__init__.py | 3 +-- .../types/expected/package/nested_service/__init__.py | 3 +-- .../test/resources/types/expected/package/product/__init__.py | 2 -- .../types/expected/package/product_datasets/__init__.py | 3 +-- .../resources/types/expected/package/with_imports/__init__.py | 3 +-- conjure-python-verifier/build.gradle | 2 +- 7 files changed, 6 insertions(+), 13 deletions(-) diff --git a/conjure-python-core/src/test/resources/services/expected/package/product/__init__.py b/conjure-python-core/src/test/resources/services/expected/package/product/__init__.py index 90d9104f7..b9cc18273 100644 --- a/conjure-python-core/src/test/resources/services/expected/package/product/__init__.py +++ b/conjure-python-core/src/test/resources/services/expected/package/product/__init__.py @@ -1,6 +1,5 @@ # this is package package.product -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition +from conjure_python_client import * from typing import Dict from typing import List from typing import Optional diff --git a/conjure-python-core/src/test/resources/services/expected/package/product_datasets/__init__.py b/conjure-python-core/src/test/resources/services/expected/package/product_datasets/__init__.py index ee217316b..664ced9df 100644 --- a/conjure-python-core/src/test/resources/services/expected/package/product_datasets/__init__.py +++ b/conjure-python-core/src/test/resources/services/expected/package/product_datasets/__init__.py @@ -1,6 +1,5 @@ # this is package package.product_datasets -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition +from conjure_python_client import * from typing import Dict from typing import List from typing import Optional diff --git a/conjure-python-core/src/test/resources/types/expected/package/nested_service/__init__.py b/conjure-python-core/src/test/resources/types/expected/package/nested_service/__init__.py index af15166a0..c987c1cc5 100644 --- a/conjure-python-core/src/test/resources/types/expected/package/nested_service/__init__.py +++ b/conjure-python-core/src/test/resources/types/expected/package/nested_service/__init__.py @@ -1,8 +1,7 @@ # this is package package.nested_service -from conjure_python_client import ConjureBeanType +from conjure_python_client import * from conjure_python_client import ConjureDecoder from conjure_python_client import ConjureEncoder -from conjure_python_client import ConjureFieldDefinition from conjure_python_client import Service from typing import Dict from typing import List diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/__init__.py b/conjure-python-core/src/test/resources/types/expected/package/product/__init__.py index 9e8602713..c935b5ba1 100644 --- a/conjure-python-core/src/test/resources/types/expected/package/product/__init__.py +++ b/conjure-python-core/src/test/resources/types/expected/package/product/__init__.py @@ -1,7 +1,5 @@ # this is package package.product from conjure_python_client import * -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition from typing import Dict from typing import List from typing import Optional diff --git a/conjure-python-core/src/test/resources/types/expected/package/product_datasets/__init__.py b/conjure-python-core/src/test/resources/types/expected/package/product_datasets/__init__.py index ee217316b..664ced9df 100644 --- a/conjure-python-core/src/test/resources/types/expected/package/product_datasets/__init__.py +++ b/conjure-python-core/src/test/resources/types/expected/package/product_datasets/__init__.py @@ -1,6 +1,5 @@ # this is package package.product_datasets -from conjure_python_client import ConjureBeanType -from conjure_python_client import ConjureFieldDefinition +from conjure_python_client import * from typing import Dict from typing import List from typing import Optional diff --git a/conjure-python-core/src/test/resources/types/expected/package/with_imports/__init__.py b/conjure-python-core/src/test/resources/types/expected/package/with_imports/__init__.py index 3e15299ae..d7c69b1be 100644 --- a/conjure-python-core/src/test/resources/types/expected/package/with_imports/__init__.py +++ b/conjure-python-core/src/test/resources/types/expected/package/with_imports/__init__.py @@ -7,10 +7,9 @@ from ..product import StringAliasExample from ..product import StringExample from ..product_datasets import BackingFileSystem -from conjure_python_client import ConjureBeanType +from conjure_python_client import * from conjure_python_client import ConjureDecoder from conjure_python_client import ConjureEncoder -from conjure_python_client import ConjureFieldDefinition from conjure_python_client import Service from typing import Dict from typing import List diff --git a/conjure-python-verifier/build.gradle b/conjure-python-verifier/build.gradle index a14dace23..83f2a69a1 100644 --- a/conjure-python-verifier/build.gradle +++ b/conjure-python-verifier/build.gradle @@ -52,7 +52,7 @@ task generateVerifierBindings(type: JavaExec, dependsOn: [copyTestCases, ':conju doLast { delete "python/test/setup.py" } } -task generateIntegrationTests(type: JavaExec, dependsOn: [compileConjure, ':conjure-python:compileJava']) { +task generateIntegrationTests(type: JavaExec, dependsOn: [compileIr, ':conjure-python:compileJava']) { main = "com.palantir.conjure.python.cli.ConjurePythonCli" classpath = project(':conjure-python').sourceSets.main.runtimeClasspath args 'generate', From 7eca94b94c5b78dc4db863f47f72b4560de27066 Mon Sep 17 00:00:00 2001 From: forozco Date: Mon, 23 Jul 2018 11:17:32 +0100 Subject: [PATCH 5/5] address comments with dan --- .../conjure/python/poet/PythonFile.java | 3 ++- .../test/resources/types/example-types.yml | 5 +++++ .../expected/package/product/__init__.py | 22 +++++++++++++++++++ ...t_circular_imports.py => test_code_gen.py} | 9 ++++---- .../main/conjure/example-types.conjure.yml | 1 + .../src/main/conjure/integration.conjure.yml | 9 -------- 6 files changed, 35 insertions(+), 14 deletions(-) rename conjure-python-verifier/python/test/client/{test_circular_imports.py => test_code_gen.py} (68%) create mode 120000 conjure-python-verifier/src/main/conjure/example-types.conjure.yml delete mode 100644 conjure-python-verifier/src/main/conjure/integration.conjure.yml diff --git a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonFile.java b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonFile.java index dee65a4be..a210575d9 100644 --- a/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonFile.java +++ b/conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonFile.java @@ -60,7 +60,8 @@ static Builder builder() { class PythonClassSerializationComparator implements Comparator { @Override public int compare(PythonClass pc1, PythonClass pc2) { - // PythonAlias type objects should always go last + // PythonAliases need to occur last, since they potentially reference + // objects defined in the current module if (pc1 instanceof PythonAlias && !(pc2 instanceof PythonAlias)) { return 1; } else if (!(pc1 instanceof PythonAlias) && pc2 instanceof PythonAlias) { diff --git a/conjure-python-core/src/test/resources/types/example-types.yml b/conjure-python-core/src/test/resources/types/example-types.yml index 7b0e3faa9..48c98fbee 100644 --- a/conjure-python-core/src/test/resources/types/example-types.yml +++ b/conjure-python-core/src/test/resources/types/example-types.yml @@ -156,3 +156,8 @@ types: type: string memoizedHashCode: type: integer + RecursiveObjectExample: + fields: + recursiveField: optional + RecursiveObjectAlias: + alias: RecursiveObjectExample diff --git a/conjure-python-core/src/test/resources/types/expected/package/product/__init__.py b/conjure-python-core/src/test/resources/types/expected/package/product/__init__.py index c935b5ba1..76fda2046 100644 --- a/conjure-python-core/src/test/resources/types/expected/package/product/__init__.py +++ b/conjure-python-core/src/test/resources/types/expected/package/product/__init__.py @@ -533,6 +533,26 @@ def uuid(self): # type: () -> Optional[str] return self._uuid +class RecursiveObjectExample(ConjureBeanType): + + @classmethod + def _fields(cls): + # type: () -> Dict[str, ConjureFieldDefinition] + return { + 'recursive_field': ConjureFieldDefinition('recursiveField', OptionalType(RecursiveObjectAlias)) + } + + _recursive_field = None # type: Optional[RecursiveObjectAlias] + + def __init__(self, recursive_field): + # type: (Optional[RecursiveObjectAlias]) -> None + self._recursive_field = recursive_field + + @property + def recursive_field(self): + # type: () -> Optional[RecursiveObjectAlias] + return self._recursive_field + class ReservedKeyExample(ConjureBeanType): @classmethod @@ -785,6 +805,8 @@ def uuid(self): MapAliasExample = DictType(str, object) +RecursiveObjectAlias = RecursiveObjectExample + ReferenceAliasExample = AnyExample RidAliasExample = str diff --git a/conjure-python-verifier/python/test/client/test_circular_imports.py b/conjure-python-verifier/python/test/client/test_code_gen.py similarity index 68% rename from conjure-python-verifier/python/test/client/test_circular_imports.py rename to conjure-python-verifier/python/test/client/test_code_gen.py index dcd60a579..6a8b06da0 100644 --- a/conjure-python-verifier/python/test/client/test_circular_imports.py +++ b/conjure-python-verifier/python/test/client/test_code_gen.py @@ -13,8 +13,9 @@ # limitations under the License. -def test_circular_import(): - from ..generated.integration import ObjectExample, ObjectAlias - object_example = ObjectExample(None) - object_alias = ObjectAlias(None) +# TODO(forozco): Once we split out code gen have more granular testing of code evaluation +def test_code_gen_compiles(): + from ..generated.product import RecursiveObjectExample, RecursiveObjectAlias + object_example = RecursiveObjectExample(None) + object_alias = RecursiveObjectAlias(None) assert object_alias == object_example \ No newline at end of file diff --git a/conjure-python-verifier/src/main/conjure/example-types.conjure.yml b/conjure-python-verifier/src/main/conjure/example-types.conjure.yml new file mode 120000 index 000000000..f6af5328c --- /dev/null +++ b/conjure-python-verifier/src/main/conjure/example-types.conjure.yml @@ -0,0 +1 @@ +../../../../conjure-python-core/src/test/resources/types/example-types.yml \ No newline at end of file diff --git a/conjure-python-verifier/src/main/conjure/integration.conjure.yml b/conjure-python-verifier/src/main/conjure/integration.conjure.yml deleted file mode 100644 index 3c473860e..000000000 --- a/conjure-python-verifier/src/main/conjure/integration.conjure.yml +++ /dev/null @@ -1,9 +0,0 @@ -types: - definitions: - default-package: com.palantir.integration - objects: - ObjectExample: - fields: - recursiveField: optional - ObjectAlias: - alias: ObjectExample