提交 841bf823 编写于 作者: B Bogdan Kobylynskyi

New config to generate only no-args constructor #1017 (#1037)

上级 4d57b67a
......@@ -37,11 +37,12 @@
| `fieldsWithoutResolvers` | Set(String) | Empty | Fields that DO NOT require Resolvers should be defined here in format: `TypeName.fieldName` or `TypeName` or `@directive`. Can be used in conjunction with `generateExtensionFieldsResolvers` option. E.g.: `Person`, `Person.friends`, `@noResolver`. |
| `resolverArgumentAnnotations` | Set(String) | Empty | Annotations that will be added to all resolver arguments. Can be used for [spring-graphql](https://github.com/spring-projects/spring-graphql) inegration by supplying: `org.springframework.graphql.data.method.annotation.Argument` |
| `parametrizedResolverAnnotations` | Set(String) | Empty | Annotations that will be added to all parametrized resolver methods. Can be used for [spring-graphql](https://github.com/spring-projects/spring-graphql) inegration by supplying: `org.springframework.graphql.data.method.annotation.SchemaMapping(typeName="{{TYPE_NAME}}")` |
| `generateParameterizedFieldsR`<br>`esolvers` | Boolean | True | If true, then generate separate `Resolver` interface for parametrized fields. If false, then add field to the type definition and ignore field parameters. |
| `generateExtensionFieldsResol`<br>`vers` | Boolean | False | Specifies whether all fields in extensions (`extend type` and `extend interface`) should be present in Resolver interface instead of the type class itself. |
| `generateParameterizedFieldsResolvers` | Boolean | True | If true, then generate separate `Resolver` interface for parametrized fields. If false, then add field to the type definition and ignore field parameters. |
| `generateExtensionFieldsResolvers` | Boolean | False | Specifies whether all fields in extensions (`extend type` and `extend interface`) should be present in Resolver interface instead of the type class itself. |
| `generateModelsForRootTypes` | Boolean | False | Specifies whether model classes should be generated for `type Query`, `type Subscription`, `type Mutation`. |
| `useOptionalForNullableReturn`<br>`Types` | Boolean | False | Specifies whether nullable return types of api methods should be wrapped into [`java.util.Optional<>`](https://docs.oracle.com/javase/8/docs/api/index.html?java/util/Optional.html). Lists will not be wrapped. |
| `generateApisWithThrowsExcept`<br>`ion` | Boolean | True | Specifies whether api interface methods should have `throws Exception` in signature. |
| `useOptionalForNullableReturnTypes` | Boolean | False | Specifies whether nullable return types of api methods should be wrapped into [`java.util.Optional<>`](https://docs.oracle.com/javase/8/docs/api/index.html?java/util/Optional.html). Lists will not be wrapped. |
| `generateApisWithThrowsException` | Boolean | True | Specifies whether api interface methods should have `throws Exception` in signature. |
| `generateNoArgsConstructorOnly` | Boolean | False | Specifies whether model classes should only have a no-args constructor. All-args constructor will not be generated in case value is <b>true</b> |
| `apiReturnType` | String | Empty | Return type for api methods (query/mutation). For example: `reactor.core.publisher.Mono`, etc. |
| `apiReturnListType` | String | Empty | Return type for api methods (query/mutation) having list type. For example: `reactor.core.publisher.Flux`, etc. By default is empty, so `apiReturnType` will be used. |
| `subscriptionReturnType` | String | Empty | Return type for subscription methods. For example: `org.reactivestreams.Publisher`, `io.reactivex.Observable`, etc. |
......
......@@ -84,6 +84,7 @@ public class GraphQLCodegenGradleTask extends DefaultTask implements GraphQLCode
private Boolean generateApisWithThrowsException = MappingConfigConstants.DEFAULT_GENERATE_APIS_WITH_THROWS_EXCEPTION;
private Boolean generateJacksonTypeIdResolver = MappingConfigConstants.DEFAULT_GENERATE_JACKSON_TYPE_ID_RESOLVER;
private Boolean addGeneratedAnnotation = MappingConfigConstants.DEFAULT_ADD_GENERATED_ANNOTATION;
private Boolean generateNoArgsConstructorOnly = MappingConfigConstants.DEFAULT_GENERATE_NOARGS_CONSTRUCTOR_ONLY;
private String generatedAnnotation;
private Set<String> fieldsWithResolvers = new HashSet<>();
private Set<String> fieldsWithoutResolvers = new HashSet<>();
......@@ -155,6 +156,7 @@ public class GraphQLCodegenGradleTask extends DefaultTask implements GraphQLCode
mappingConfig.setUseOptionalForNullableReturnTypes(useOptionalForNullableReturnTypes);
mappingConfig.setGenerateApisWithThrowsException(generateApisWithThrowsException);
mappingConfig.setGenerateJacksonTypeIdResolver(generateJacksonTypeIdResolver);
mappingConfig.setGenerateNoArgsConstructorOnly(generateNoArgsConstructorOnly);
mappingConfig.setAddGeneratedAnnotation(addGeneratedAnnotation);
mappingConfig.setGeneratedAnnotation(generatedAnnotation);
mappingConfig.setApiReturnType(apiReturnType);
......@@ -682,6 +684,17 @@ public class GraphQLCodegenGradleTask extends DefaultTask implements GraphQLCode
this.generatedAnnotation = generatedAnnotation;
}
@Input
@Optional
@Override
public Boolean isGenerateNoArgsConstructorOnly() {
return generateNoArgsConstructorOnly;
}
public void setGenerateNoArgsConstructorOnly(Boolean generateNoArgsConstructorOnly) {
this.generateNoArgsConstructorOnly = generateNoArgsConstructorOnly;
}
@Input
@Optional
@Override
......
......@@ -155,6 +155,9 @@ public class GraphQLCodegenMojo extends AbstractMojo implements GraphQLCodegenCo
@Parameter(defaultValue = MappingConfigConstants.DEFAULT_ADD_GENERATED_ANNOTATION_STRING)
private boolean addGeneratedAnnotation;
@Parameter(defaultValue = MappingConfigConstants.DEFAULT_GENERATE_NOARGS_CONSTRUCTOR_ONLY_STRING)
private boolean generateNoArgsConstructorOnly;
@Parameter
private String generatedAnnotation;
......@@ -271,6 +274,7 @@ public class GraphQLCodegenMojo extends AbstractMojo implements GraphQLCodegenCo
mappingConfig.setGenerateJacksonTypeIdResolver(generateJacksonTypeIdResolver);
mappingConfig.setAddGeneratedAnnotation(addGeneratedAnnotation);
mappingConfig.setGeneratedAnnotation(generatedAnnotation);
mappingConfig.setGenerateNoArgsConstructorOnly(generateNoArgsConstructorOnly);
mappingConfig.setFieldsWithResolvers(mapToHashSet(fieldsWithResolvers));
mappingConfig.setFieldsWithoutResolvers(mapToHashSet(fieldsWithoutResolvers));
mappingConfig.setRelayConfig(relayConfig);
......@@ -665,30 +669,27 @@ public class GraphQLCodegenMojo extends AbstractMojo implements GraphQLCodegenCo
return generateSealedInterfaces;
}
public ParentInterfacesConfig getParentInterfaces() {
return parentInterfaces;
}
public String[] getConfigurationFiles() {
return configurationFiles;
}
@Override
public Boolean isSupportUnknownFields() {
return supportUnknownFields;
}
public void setSupportUnknownFields(boolean supportUnknownFields) {
this.supportUnknownFields = supportUnknownFields;
}
@Override
public String getUnknownFieldsPropertyName() {
return unknownFieldsPropertyName;
}
public void setUnknownFieldsPropertyName(String unknownFieldsPropertyName) {
this.unknownFieldsPropertyName = unknownFieldsPropertyName;
@Override
public Boolean isGenerateNoArgsConstructorOnly() {
return generateNoArgsConstructorOnly;
}
public ParentInterfacesConfig getParentInterfaces() {
return parentInterfaces;
}
public String[] getConfigurationFiles() {
return configurationFiles;
}
private static Map<String, List<String>> convertToListsMap(Map<String, Properties> sourceMap) {
......
......@@ -129,6 +129,8 @@ trait GraphQLCodegenKeys {
val generateJacksonTypeIdResolver = settingKey[Boolean]("Specifies whether generated union interfaces should be annotated with a custom Jackson type id resolver generated in model package.")
val generateNoArgsConstructorOnly = settingKey[Boolean]("Specifies whether model classes should only have a no-args constructor. All-args constructor will not be generated in case value is .true.")
//for version
val javaxValidationApiVersion = settingKey[Option[String]]("javax-validation-api version")
val graphqlJavaCodegenVersion = settingKey[Option[String]]("graphql-java-codegen version")
......
......@@ -122,6 +122,7 @@ class GraphQLCodegenPlugin(configuration: Configuration, private[codegen] val co
supportUnknownFields := MappingConfigConstants.DEFAULT_SUPPORT_UNKNOWN_FIELDS,
unknownFieldsPropertyName := MappingConfigConstants.DEFAULT_UNKNOWN_FIELDS_PROPERTY_NAME,
generateNoArgsConstructorOnly := MappingConfigConstants.DEFAULT_GENERATE_NOARGS_CONSTRUCTOR_ONLY,
skip := false
)
......@@ -179,6 +180,7 @@ class GraphQLCodegenPlugin(configuration: Configuration, private[codegen] val co
mappingConfig.setGeneratedLanguage((generatedLanguage in GraphQLCodegenConfig).value)
mappingConfig.setGenerateModelOpenClasses((generateModelOpenClasses in GraphQLCodegenConfig).value)
mappingConfig.setGenerateJacksonTypeIdResolver((generateJacksonTypeIdResolver in GraphQLCodegenConfig).value);
mappingConfig.setGenerateNoArgsConstructorOnly((generateNoArgsConstructorOnly in GraphQLCodegenConfig).value);
mappingConfig.setSupportUnknownFields((supportUnknownFields in GraphQLCodegenConfig).value)
mappingConfig.setUnknownFieldsPropertyName((unknownFieldsPropertyName in GraphQLCodegenConfig).value)
......
......@@ -18,6 +18,7 @@ import static com.kobylynskyi.graphql.codegen.model.DataModelFields.FIELDS;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.GENERATED_ANNOTATION;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.GENERATED_INFO;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.GENERATE_MODEL_OPEN_CLASSES;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.GENERATE_NOARGS_CONSTRUCTOR_ONLY;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.IMMUTABLE_MODELS;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.INITIALIZE_NULLABLE_TYPES;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.JAVA_DOC;
......@@ -78,6 +79,7 @@ public class InputDefinitionToDataModelMapper implements UnknownFieldsSupport {
dataModel.put(INITIALIZE_NULLABLE_TYPES, mappingContext.isInitializeNullableTypes());
dataModel.put(SUPPORT_UNKNOWN_FIELDS, mappingContext.isSupportUnknownFields());
dataModel.put(UNKNOWN_FIELDS_PROPERTY_NAME, mappingContext.getUnknownFieldsPropertyName());
dataModel.put(GENERATE_NOARGS_CONSTRUCTOR_ONLY, mappingContext.isGenerateNoArgsConstructorOnly());
return dataModel;
}
......
......@@ -29,6 +29,7 @@ import static com.kobylynskyi.graphql.codegen.model.DataModelFields.FIELDS;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.GENERATED_ANNOTATION;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.GENERATED_INFO;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.GENERATE_ALL_METHOD_IN_PROJECTION;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.GENERATE_NOARGS_CONSTRUCTOR_ONLY;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.JAVA_DOC;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.METHOD_NAME;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.OPERATION_NAME;
......@@ -154,6 +155,7 @@ public class RequestResponseDefinitionToDataModelMapper {
dataModel.put(GENERATED_ANNOTATION, mappingContext.getAddGeneratedAnnotation());
dataModel.put(GENERATED_INFO, mappingContext.getGeneratedInformation());
dataModel.put(ENUM_IMPORT_IT_SELF_IN_SCALA, mappingContext.getEnumImportItSelfInScala());
dataModel.put(GENERATE_NOARGS_CONSTRUCTOR_ONLY, mappingContext.isGenerateNoArgsConstructorOnly());
// dataModel.put(TO_STRING, mappingConfig.getGenerateToString()); always generated for serialization purposes
return dataModel;
}
......
......@@ -26,6 +26,7 @@ import static com.kobylynskyi.graphql.codegen.model.DataModelFields.FIELDS;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.GENERATED_ANNOTATION;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.GENERATED_INFO;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.GENERATE_MODEL_OPEN_CLASSES;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.GENERATE_NOARGS_CONSTRUCTOR_ONLY;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.GENERATE_SEALED_INTERFACES;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.IMMUTABLE_MODELS;
import static com.kobylynskyi.graphql.codegen.model.DataModelFields.IMPLEMENTS;
......@@ -110,6 +111,7 @@ public class TypeDefinitionToDataModelMapper implements UnknownFieldsSupport {
dataModel.put(GENERATE_SEALED_INTERFACES, mappingContext.isGenerateSealedInterfaces());
dataModel.put(SUPPORT_UNKNOWN_FIELDS, mappingContext.isSupportUnknownFields());
dataModel.put(UNKNOWN_FIELDS_PROPERTY_NAME, mappingContext.getUnknownFieldsPropertyName());
dataModel.put(GENERATE_NOARGS_CONSTRUCTOR_ONLY, mappingContext.isGenerateNoArgsConstructorOnly());
return dataModel;
}
......
......@@ -40,6 +40,7 @@ public final class DataModelFields {
public static final String GENERATE_SEALED_INTERFACES = "generateSealedInterfaces";
public static final String SUPPORT_UNKNOWN_FIELDS = "supportUnknownFields";
public static final String UNKNOWN_FIELDS_PROPERTY_NAME = "unknownFieldsPropertyName";
public static final String GENERATE_NOARGS_CONSTRUCTOR_ONLY = "generateNoArgsConstructorOnly";
private DataModelFields() {
}
......
......@@ -513,5 +513,14 @@ public interface GraphQLCodegenConfiguration {
*/
String getGeneratedAnnotation();
/**
* Specifies whether model classes should only have a no-args constructor.
* All-args constructor will not be generated in case returned value is <b>true</b>
*
* @return <b>true</b> if only no-args constructor should be generated.
* <b>false</b> if both no-args and all-args constructors should be generated
*/
Boolean isGenerateNoArgsConstructorOnly();
}
......@@ -55,6 +55,7 @@ public class MappingConfig implements GraphQLCodegenConfiguration, Combinable<Ma
private Boolean addGeneratedAnnotation;
private Boolean generateJacksonTypeIdResolver;
private Boolean supportUnknownFields;
private Boolean generateNoArgsConstructorOnly;
// field resolvers configs:
private Set<String> fieldsWithResolvers = new HashSet<>();
......@@ -209,6 +210,8 @@ public class MappingConfig implements GraphQLCodegenConfiguration, Combinable<Ma
GraphQLCodegenConfiguration::getUnknownFieldsPropertyName);
generatedAnnotation = getValueOrDefaultToThis(source,
GraphQLCodegenConfiguration::getGeneratedAnnotation);
generateNoArgsConstructorOnly = getValueOrDefaultToThis(source,
GraphQLCodegenConfiguration::isGenerateNoArgsConstructorOnly);
}
private <T> T getValueOrDefaultToThis(MappingConfig source, Function<MappingConfig, T> getValueFunction) {
......@@ -680,11 +683,6 @@ public class MappingConfig implements GraphQLCodegenConfiguration, Combinable<Ma
this.typesAsInterfaces = typesAsInterfaces;
}
@Override
public GeneratedLanguage getGeneratedLanguage() {
return generatedLanguage;
}
@Override
public String getUnknownFieldsPropertyName() {
return unknownFieldsPropertyName;
......@@ -712,10 +710,16 @@ public class MappingConfig implements GraphQLCodegenConfiguration, Combinable<Ma
this.supportUnknownFields = supportUnknownFields;
}
@Override
public GeneratedLanguage getGeneratedLanguage() {
return generatedLanguage;
}
public void setGeneratedLanguage(GeneratedLanguage generatedLanguage) {
this.generatedLanguage = generatedLanguage;
}
@Override
public Boolean isGenerateModelOpenClasses() {
return generateModelOpenClasses;
}
......@@ -724,6 +728,7 @@ public class MappingConfig implements GraphQLCodegenConfiguration, Combinable<Ma
this.generateModelOpenClasses = generateModelOpenClasses;
}
@Override
public Boolean isInitializeNullableTypes() {
return initializeNullableTypes;
}
......@@ -732,6 +737,7 @@ public class MappingConfig implements GraphQLCodegenConfiguration, Combinable<Ma
this.initializeNullableTypes = initializeNullableTypes;
}
@Override
public Boolean isGenerateSealedInterfaces() {
return generateSealedInterfaces;
}
......@@ -740,4 +746,12 @@ public class MappingConfig implements GraphQLCodegenConfiguration, Combinable<Ma
this.generateSealedInterfaces = generateSealedInterfaces;
}
@Override
public Boolean isGenerateNoArgsConstructorOnly() {
return generateNoArgsConstructorOnly;
}
public void setGenerateNoArgsConstructorOnly(Boolean generateNoArgsConstructorOnly) {
this.generateNoArgsConstructorOnly = generateNoArgsConstructorOnly;
}
}
......@@ -82,13 +82,14 @@ public class MappingConfigConstants {
// There is no need to consider the possibility of switching.
public static final String DEFAULT_SERIALIZATION_LIBRARY = "JACKSON";
//It only support in kotlin and scala.
// Only supported in Kotlin and Scala
public static final boolean DEFAULT_GENERATE_MODEL_OPEN_CLASSES = false;
public static final String DEFAULT_GENERATE_MODEL_OPEN_CLASSES_STRING = "false";
//Only supported in kotlin.
// Only supported in Kotlin
public static final boolean DEFAULT_INITIALIZE_NULLABLE_TYPES = false;
public static final String DEFAULT_INITIALIZE_NULLABLE_TYPES_STRING = "false";
// Only supported in Kotlin
public static final boolean DEFAULT_GENERATE_SEALED_INTERFACES = false;
public static final String DEFAULT_GENERATE_SEALED_INTERFACES_STRING = "false";
......@@ -97,6 +98,9 @@ public class MappingConfigConstants {
public static final String DEFAULT_SUPPORT_UNKNOWN_FIELDS_STRING = "false";
public static final String DEFAULT_UNKNOWN_FIELDS_PROPERTY_NAME = "userDefinedFields";
public static final boolean DEFAULT_GENERATE_NOARGS_CONSTRUCTOR_ONLY = false;
public static final String DEFAULT_GENERATE_NOARGS_CONSTRUCTOR_ONLY_STRING = "false";
private MappingConfigConstants() {
}
}
......@@ -114,6 +114,10 @@ public class MappingConfigDefaultValuesInitializer {
if (mappingConfig.getUnknownFieldsPropertyName() == null) {
mappingConfig.setUnknownFieldsPropertyName(MappingConfigConstants.DEFAULT_UNKNOWN_FIELDS_PROPERTY_NAME);
}
if (mappingConfig.isGenerateNoArgsConstructorOnly() == null) {
mappingConfig.setGenerateNoArgsConstructorOnly(
MappingConfigConstants.DEFAULT_GENERATE_NOARGS_CONSTRUCTOR_ONLY);
}
}
}
......@@ -341,6 +341,11 @@ public class MappingContext implements GraphQLCodegenConfiguration {
return config.getGeneratedAnnotation();
}
@Override
public Boolean isGenerateNoArgsConstructorOnly() {
return config.isGenerateNoArgsConstructorOnly();
}
public ExtendedDocument getDocument() {
return document;
}
......
......@@ -43,11 +43,11 @@ public class ${className} implements GraphQLParametrizedInput {
public ${className}() {
}
<#if fields?has_content>
<#if fields?has_content && !generateNoArgsConstructorOnly>
public ${className}(<#list fields as field>${field.type} ${field.name}<#if field_has_next>, </#if></#list>) {
<#list fields as field>
<#list fields as field>
this.${field.name} = ${field.name};
</#list>
</#list>
}
</#if>
......
......@@ -53,7 +53,7 @@ public class ${className} implements java.io.Serializable<#if implements?has_con
public ${className}() {
}
<#if fields?has_content>
<#if fields?has_content && !generateNoArgsConstructorOnly>
public ${className}(<#list fields as field>${field.type} ${field.name}<#if field_has_next>, </#if></#list>) {
<#list fields as field>
this.${field.name} = ${field.name};
......@@ -194,7 +194,15 @@ public class ${className} implements java.io.Serializable<#if implements?has_con
</#if>
public ${className} build() {
<#if generateNoArgsConstructorOnly>
${className} result = new ${className};
<#list fields as field>
result.set${field.name?cap_first}(this.${field.name});
</#list>
return result;
<#else>
return new ${className}(<#list fields as field>${field.name}<#if field_has_next>, </#if></#list>);
</#if>
}
}
......
......@@ -46,9 +46,11 @@ class GraphQLCodegenFieldsResolversTest {
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
assertSameTrimmedContent(new File("src/test/resources/expected-classes/Commit_noParametrizedFields.java.txt"),
assertSameTrimmedContent(new File("src/test/resources/expected-classes/resolvers/" +
"Commit_noParametrizedFields.java.txt"),
getFileByName(files, "Commit.java"));
assertSameTrimmedContent(new File("src/test/resources/expected-classes/CommitResolver.java.txt"),
assertSameTrimmedContent(new File("src/test/resources/expected-classes/resolvers/" +
"CommitResolver.java.txt"),
getFileByName(files, "CommitResolver.java"));
}
......@@ -94,7 +96,7 @@ class GraphQLCodegenFieldsResolversTest {
assertSameTrimmedContent(new File("src/test/resources/expected-classes/" +
"GithubAcceptTopicSuggestionPayloadTO.java.txt"),
getFileByName(files, "GithubAcceptTopicSuggestionPayloadTO.java"));
assertSameTrimmedContent(new File("src/test/resources/expected-classes/" +
assertSameTrimmedContent(new File("src/test/resources/expected-classes/resolvers/" +
"AcceptTopicSuggestionPayloadResolver.java.txt"),
getFileByName(files, "AcceptTopicSuggestionPayloadResolver.java"));
}
......@@ -107,9 +109,11 @@ class GraphQLCodegenFieldsResolversTest {
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
assertSameTrimmedContent(new File("src/test/resources/expected-classes/CommentDeletedEventResolver.java.txt"),
assertSameTrimmedContent(new File("src/test/resources/expected-classes/resolvers/" +
"CommentDeletedEventResolver.java.txt"),
getFileByName(files, "CommentDeletedEventResolver.java"));
assertSameTrimmedContent(new File("src/test/resources/expected-classes/CommentDeletedEvent.java.txt"),
assertSameTrimmedContent(new File("src/test/resources/expected-classes/resolvers/" +
"CommentDeletedEvent.java.txt"),
getFileByName(files, "CommentDeletedEvent.java"));
}
......
......@@ -89,7 +89,8 @@ class GraphQLCodegenGitHubTest {
generate();
File commitFile = getFileByName(Objects.requireNonNull(outputJavaClassesDir.listFiles()), "Commit.java");
assertSameTrimmedContent(new File("src/test/resources/expected-classes/Commit_noValidationAnnotation.java.txt"),
assertSameTrimmedContent(new File("src/test/resources/expected-classes/annotation/" +
"Commit_noValidationAnnotation.java.txt"),
commitFile);
}
......@@ -120,7 +121,8 @@ class GraphQLCodegenGitHubTest {
generate();
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
assertSameTrimmedContent(new File("src/test/resources/expected-classes/Commit_withoutPrimitives.java.txt"),
assertSameTrimmedContent(new File("src/test/resources/expected-classes/primitives/" +
"Commit_withoutPrimitives.java.txt"),
getFileByName(files, "Commit.java"));
}
......
......@@ -86,7 +86,8 @@ class GraphQLCodegenTest {
generate("src/test/resources/schemas/test.graphqls");
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
assertSameTrimmedContent(new File("src/test/resources/expected-classes/Event_noBuilder.java.txt"),
assertSameTrimmedContent(new File("src/test/resources/expected-classes/builder/" +
"Event_noBuilder.java.txt"),
getFileByName(files, "Event.java"));
}
......@@ -242,8 +243,8 @@ class GraphQLCodegenTest {
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
assertNotEquals(0, files.length);
assertSameTrimmedContent(
new File("src/test/resources/expected-classes/EventPropertyTO_withoutGeneratedAnnotation.java.txt"),
assertSameTrimmedContent(new File("src/test/resources/expected-classes/annotation/" +
"EventPropertyTO_withoutGeneratedAnnotation.java.txt"),
getFileByName(files, "EventPropertyTO.java"));
}
......@@ -398,8 +399,50 @@ class GraphQLCodegenTest {
getFileByName(files, "Person.java"));
}
private List<File> generate(String s) throws IOException {
return new JavaGraphQLCodegen(singletonList(s), outputBuildDir, mappingConfig,
@Test
void generate_NoArgsConstructorOnlyWithBuilder() throws Exception {
mappingConfig.setGenerateNoArgsConstructorOnly(true);
mappingConfig.setGenerateBuilder(true);
generate("src/test/resources/schemas/test.graphqls");
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
assertSameTrimmedContent(new File("src/test/resources/expected-classes/no-args-constructor/" +
"Event_noargsconstr_builder.java.txt"),
getFileByName(files, "Event.java"));
}
@Test
void generate_NoArgsConstructorOnlyWithoutBuilder() throws Exception {
mappingConfig.setGenerateNoArgsConstructorOnly(true);
mappingConfig.setGenerateBuilder(false);
generate("src/test/resources/schemas/test.graphqls");
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
assertSameTrimmedContent(new File("src/test/resources/expected-classes/no-args-constructor/" +
"Event_noargsconstr_withoutbuilder.java.txt"),
getFileByName(files, "Event.java"));
}
@Test
void generate_NoArgsConstructor_ParametrizedInput() throws Exception {
mappingConfig.setGenerateNoArgsConstructorOnly(true);
mappingConfig.setGenerateClient(true);
generate("src/test/resources/schemas/test.graphqls");
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
assertSameTrimmedContent(new File("src/test/resources/expected-classes/no-args-constructor/" +
"EventPropertyChildParametrizedInput_noargsconstructor.java.txt"),
getFileByName(files, "EventPropertyChildParametrizedInput.java"));
}
private List<File> generate(String path) throws IOException {
return new JavaGraphQLCodegen(singletonList(path), outputBuildDir, mappingConfig,
TestUtils.getStaticGeneratedInfo(mappingConfig)).generate();
}
......
package com.kobylynskyi.graphql.test1;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLParametrizedInput;
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLRequestSerializer;
import java.util.StringJoiner;
/**
* Parametrized input for field child in type EventProperty
*/
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
public class EventPropertyChildParametrizedInput implements GraphQLParametrizedInput {
private Integer first;
private Integer last;
public EventPropertyChildParametrizedInput() {
}
public EventPropertyChildParametrizedInput first(Integer first) {
this.first = first;
return this;
}
public EventPropertyChildParametrizedInput last(Integer last) {
this.last = last;
return this;
}
@Override
public EventPropertyChildParametrizedInput deepCopy() {
EventPropertyChildParametrizedInput parametrizedInput = new EventPropertyChildParametrizedInput();
parametrizedInput.first(this.first);
parametrizedInput.last(this.last);
return parametrizedInput;
}
@Override
public String toString() {
StringJoiner joiner = new StringJoiner(", ", "(", ")");
if (first != null) {
joiner.add("first: " + GraphQLRequestSerializer.getEntry(first));
}
if (last != null) {
joiner.add("last: " + GraphQLRequestSerializer.getEntry(last));
}
return joiner.toString();
}
}
\ No newline at end of file
package com.kobylynskyi.graphql.test1;
/**
* An event that describes a thing that happens
*/
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
public class Event implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private String id;
private String categoryId;
private java.util.List<EventProperty> properties;
private EventStatus status;
private String createdBy;
private String createdDateTime;
private Boolean active;
private Integer rating;
public Event() {
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getCategoryId() {
return categoryId;
}
public void setCategoryId(String categoryId) {
this.categoryId = categoryId;
}
public java.util.List<EventProperty> getProperties() {
return properties;
}
public void setProperties(java.util.List<EventProperty> properties) {
this.properties = properties;
}
public EventStatus getStatus() {
return status;
}
public void setStatus(EventStatus status) {
this.status = status;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public String getCreatedDateTime() {
return createdDateTime;
}
public void setCreatedDateTime(String createdDateTime) {
this.createdDateTime = createdDateTime;
}
public Boolean getActive() {
return active;
}
public void setActive(Boolean active) {
this.active = active;
}
public Integer getRating() {
return rating;
}
public void setRating(Integer rating) {
this.rating = rating;
}
public static Event.Builder builder() {
return new Event.Builder();
}
public static class Builder {
private String id;
private String categoryId;
private java.util.List<EventProperty> properties;
private EventStatus status;
private String createdBy;
private String createdDateTime;
private Boolean active;
private Integer rating;
public Builder() {
}
public Builder setId(String id) {
this.id = id;
return this;
}
public Builder setCategoryId(String categoryId) {
this.categoryId = categoryId;
return this;
}
public Builder setProperties(java.util.List<EventProperty> properties) {
this.properties = properties;
return this;
}
public Builder setStatus(EventStatus status) {
this.status = status;
return this;
}
public Builder setCreatedBy(String createdBy) {
this.createdBy = createdBy;
return this;
}
public Builder setCreatedDateTime(String createdDateTime) {
this.createdDateTime = createdDateTime;
return this;
}
public Builder setActive(Boolean active) {
this.active = active;
return this;
}
public Builder setRating(Integer rating) {
this.rating = rating;
return this;
}
public Event build() {
Event result = new Event;
result.setId(this.id);
result.setCategoryId(this.categoryId);
result.setProperties(this.properties);
result.setStatus(this.status);
result.setCreatedBy(this.createdBy);
result.setCreatedDateTime(this.createdDateTime);
result.setActive(this.active);
result.setRating(this.rating);
return result;
}
}
}
\ No newline at end of file
package com.kobylynskyi.graphql.test1;
/**
* An event that describes a thing that happens
*/
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
public class Event implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private String id;
private String categoryId;
private java.util.List<EventProperty> properties;
private EventStatus status;
private String createdBy;
private String createdDateTime;
private Boolean active;
private Integer rating;
public Event() {
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getCategoryId() {
return categoryId;
}
public void setCategoryId(String categoryId) {
this.categoryId = categoryId;
}
public java.util.List<EventProperty> getProperties() {
return properties;
}
public void setProperties(java.util.List<EventProperty> properties) {
this.properties = properties;
}
public EventStatus getStatus() {
return status;
}
public void setStatus(EventStatus status) {
this.status = status;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public String getCreatedDateTime() {
return createdDateTime;
}
public void setCreatedDateTime(String createdDateTime) {
this.createdDateTime = createdDateTime;
}
public Boolean getActive() {
return active;
}
public void setActive(Boolean active) {
this.active = active;
}
public Integer getRating() {
return rating;
}
public void setRating(Integer rating) {
this.rating = rating;
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册