Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦境迷离
Graphql Java Codegen
提交
45a9a046
G
Graphql Java Codegen
项目概览
梦境迷离
/
Graphql Java Codegen
11 个月 前同步成功
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Graphql Java Codegen
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
45a9a046
编写于
9月 17, 2019
作者:
B
Bogdan Kobylynskyi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support mandatory field validation annotation #3
上级
23e5ad30
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
420 addition
and
7 deletion
+420
-7
src/main/java/com/kobylynskyi/graphql/codegen/mapper/GraphqlTypeToJavaTypeMapper.java
...i/graphql/codegen/mapper/GraphqlTypeToJavaTypeMapper.java
+16
-6
src/main/java/com/kobylynskyi/graphql/codegen/model/DefaultMappingConfigValues.java
...kyi/graphql/codegen/model/DefaultMappingConfigValues.java
+7
-0
src/main/java/com/kobylynskyi/graphql/codegen/model/MappingConfig.java
.../com/kobylynskyi/graphql/codegen/model/MappingConfig.java
+2
-1
src/test/java/com/kobylynskyi/graphql/codegen/GraphqlCodegenGitHubTest.java
...kobylynskyi/graphql/codegen/GraphqlCodegenGitHubTest.java
+12
-0
src/test/resources/expected-classes/Commit.java.txt
src/test/resources/expected-classes/Commit.java.txt
+30
-0
src/test/resources/expected-classes/Commit_noValidationAnnotation.java.txt
...s/expected-classes/Commit_noValidationAnnotation.java.txt
+315
-0
src/test/resources/expected-classes/CreateEventMutation.java.txt
...t/resources/expected-classes/CreateEventMutation.java.txt
+1
-0
src/test/resources/expected-classes/EventByIdQuery.java.txt
src/test/resources/expected-classes/EventByIdQuery.java.txt
+1
-0
src/test/resources/expected-classes/EventsByCategoryAndStatusQuery.java.txt
.../expected-classes/EventsByCategoryAndStatusQuery.java.txt
+1
-0
src/test/resources/expected-classes/GithubCommitTO.java.txt
src/test/resources/expected-classes/GithubCommitTO.java.txt
+30
-0
src/test/resources/expected-classes/Mutation.java.txt
src/test/resources/expected-classes/Mutation.java.txt
+1
-0
src/test/resources/expected-classes/Query.java.txt
src/test/resources/expected-classes/Query.java.txt
+3
-0
src/test/resources/expected-classes/VersionQuery.java.txt
src/test/resources/expected-classes/VersionQuery.java.txt
+1
-0
未找到文件。
src/main/java/com/kobylynskyi/graphql/codegen/mapper/GraphqlTypeToJavaTypeMapper.java
浏览文件 @
45a9a046
...
...
@@ -19,7 +19,7 @@ class GraphqlTypeToJavaTypeMapper {
ParameterDefinition
parameter
=
new
ParameterDefinition
();
parameter
.
setName
(
MapperUtils
.
capitalizeIfRestricted
(
fieldDef
.
getName
()));
parameter
.
setType
(
getJavaType
(
mappingConfig
,
fieldDef
.
getType
(),
fieldDef
.
getName
(),
parentTypeName
));
parameter
.
setAnnotations
(
getAnnotations
(
mappingConfig
,
fieldDef
.
getType
(),
fieldDef
.
getName
(),
parentTypeName
));
parameter
.
setAnnotations
(
getAnnotations
(
mappingConfig
,
fieldDef
.
getType
(),
fieldDef
.
getName
(),
parentTypeName
,
false
));
return
parameter
;
}
...
...
@@ -69,19 +69,29 @@ class GraphqlTypeToJavaTypeMapper {
}
static
List
<
String
>
getAnnotations
(
MappingConfig
mappingConfig
,
Type
type
,
String
name
,
String
parentTypeName
)
{
return
getAnnotations
(
mappingConfig
,
type
,
name
,
parentTypeName
,
true
);
}
private
static
List
<
String
>
getAnnotations
(
MappingConfig
mappingConfig
,
Type
type
,
String
name
,
String
parentTypeName
,
boolean
mandatory
)
{
if
(
type
instanceof
TypeName
)
{
return
getAnnotations
(
mappingConfig
,
((
TypeName
)
type
).
getName
(),
name
,
parentTypeName
);
return
getAnnotations
(
mappingConfig
,
((
TypeName
)
type
).
getName
(),
name
,
parentTypeName
,
mandatory
);
}
else
if
(
type
instanceof
ListType
)
{
return
getAnnotations
(
mappingConfig
,
((
ListType
)
type
).
getType
(),
name
,
parentTypeName
);
return
getAnnotations
(
mappingConfig
,
((
ListType
)
type
).
getType
(),
name
,
parentTypeName
,
mandatory
);
}
else
if
(
type
instanceof
NonNullType
)
{
return
getAnnotations
(
mappingConfig
,
((
NonNullType
)
type
).
getType
(),
name
,
parentTypeName
);
return
getAnnotations
(
mappingConfig
,
((
NonNullType
)
type
).
getType
(),
name
,
parentTypeName
,
true
);
}
return
null
;
}
private
static
List
<
String
>
getAnnotations
(
MappingConfig
mappingConfig
,
String
graphlType
,
String
name
,
String
parentTypeName
)
{
private
static
List
<
String
>
getAnnotations
(
MappingConfig
mappingConfig
,
String
graphlType
,
String
name
,
String
parentTypeName
,
boolean
mandatory
)
{
List
<
String
>
annotations
=
new
ArrayList
<>();
// Todo: https://github.com/kobylynskyi/graphql-java-codegen/issues/3
if
(
mandatory
)
{
String
modelValidationAnnotation
=
mappingConfig
.
getModelValidationAnnotation
();
if
(
modelValidationAnnotation
!=
null
&&
!
modelValidationAnnotation
.
trim
().
isEmpty
())
{
annotations
.
add
(
modelValidationAnnotation
);
}
}
Map
<
String
,
String
>
customAnnotationsMapping
=
mappingConfig
.
getCustomAnnotationsMapping
();
if
(
name
!=
null
&&
parentTypeName
!=
null
&&
customAnnotationsMapping
.
containsKey
(
parentTypeName
+
"."
+
name
))
{
annotations
.
add
(
customAnnotationsMapping
.
get
(
parentTypeName
+
"."
+
name
));
...
...
src/main/java/com/kobylynskyi/graphql/codegen/model/DefaultMappingConfigValues.java
0 → 100644
浏览文件 @
45a9a046
package
com.kobylynskyi.graphql.codegen.model
;
public
class
DefaultMappingConfigValues
{
public
static
final
String
DEFAULT_VALIDATION_ANNOTATION
=
"javax.validation.constraints.NotNull"
;
public
static
final
boolean
DEFAULT_GENERATE_APIS
=
true
;
}
src/main/java/com/kobylynskyi/graphql/codegen/model/MappingConfig.java
浏览文件 @
45a9a046
...
...
@@ -21,12 +21,13 @@ public class MappingConfig {
*/
private
Map
<
String
,
String
>
customAnnotationsMapping
=
new
HashMap
<>();
private
boolean
generateApis
=
true
;
private
boolean
generateApis
=
DefaultMappingConfigValues
.
DEFAULT_GENERATE_APIS
;
private
String
packageName
;
private
String
apiPackageName
;
private
String
modelPackageName
;
private
String
modelNamePrefix
;
private
String
modelNameSuffix
;
private
String
modelValidationAnnotation
=
DefaultMappingConfigValues
.
DEFAULT_VALIDATION_ANNOTATION
;
public
void
putCustomTypeMappingIfAbsent
(
String
from
,
String
to
)
{
if
(
customTypesMapping
==
null
)
{
...
...
src/test/java/com/kobylynskyi/graphql/codegen/GraphqlCodegenGitHubTest.java
浏览文件 @
45a9a046
...
...
@@ -83,6 +83,18 @@ class GraphqlCodegenGitHubTest {
getGeneratedFileContent
(
files
,
"GithubCommitTO.java"
));
}
@Test
void
generate_NoValidationAnnotation
()
throws
Exception
{
mappingConfig
.
setModelValidationAnnotation
(
null
);
generator
.
generate
();
File
commitFile
=
Arrays
.
stream
(
Objects
.
requireNonNull
(
outputJavaClassesDir
.
listFiles
()))
.
filter
(
file
->
file
.
getName
().
equalsIgnoreCase
(
"Commit.java"
))
.
findFirst
().
orElseThrow
(
FileNotFoundException:
:
new
);
assertEquals
(
Utils
.
getFileContent
(
new
File
(
"src/test/resources/expected-classes/Commit_noValidationAnnotation.java.txt"
).
getPath
()),
Utils
.
getFileContent
(
commitFile
.
getPath
()));
}
private
static
String
getGeneratedFileContent
(
File
[]
files
,
String
fileName
)
throws
IOException
{
File
file
=
Arrays
.
stream
(
files
).
filter
(
f
->
f
.
getName
().
equalsIgnoreCase
(
fileName
))
.
findFirst
().
orElseThrow
(
FileNotFoundException:
:
new
);
...
...
src/test/resources/expected-classes/Commit.java.txt
浏览文件 @
45a9a046
...
...
@@ -4,43 +4,73 @@ import java.util.*;
public class Commit implements Closer, IssueTimelineItem, PullRequestTimelineItem, GitObject, Node, Subscribable, UniformResourceLocatable{
@javax.validation.constraints.NotNull
private String abbreviatedOid;
@javax.validation.constraints.NotNull
private Integer additions;
private PullRequestConnection associatedPullRequests;
private GitActor author;
@javax.validation.constraints.NotNull
private Boolean authoredByCommitter;
@javax.validation.constraints.NotNull
private String authoredDate;
@javax.validation.constraints.NotNull
private Blame blame;
@javax.validation.constraints.NotNull
private Integer changedFiles;
@javax.validation.constraints.NotNull
private CommitCommentConnection comments;
@javax.validation.constraints.NotNull
private String commitResourcePath;
@javax.validation.constraints.NotNull
private String commitUrl;
@javax.validation.constraints.NotNull
private String committedDate;
@javax.validation.constraints.NotNull
private Boolean committedViaWeb;
private GitActor committer;
@javax.validation.constraints.NotNull
private Integer deletions;
private DeploymentConnection deployments;
@javax.validation.constraints.NotNull
private CommitHistoryConnection history;
@javax.validation.constraints.NotNull
private String id;
@javax.validation.constraints.NotNull
private String message;
@javax.validation.constraints.NotNull
private String messageBody;
@javax.validation.constraints.NotNull
private String messageBodyHTML;
@javax.validation.constraints.NotNull
private String messageHeadline;
@javax.validation.constraints.NotNull
private String messageHeadlineHTML;
@javax.validation.constraints.NotNull
private String oid;
@javax.validation.constraints.NotNull
private CommitConnection parents;
private String pushedDate;
@javax.validation.constraints.NotNull
private Repository repository;
@javax.validation.constraints.NotNull
private String resourcePath;
private GitSignature signature;
private Status status;
@javax.validation.constraints.NotNull
private String tarballUrl;
@javax.validation.constraints.NotNull
private Tree tree;
@javax.validation.constraints.NotNull
private String treeResourcePath;
@javax.validation.constraints.NotNull
private String treeUrl;
@javax.validation.constraints.NotNull
private String url;
@javax.validation.constraints.NotNull
private Boolean viewerCanSubscribe;
private SubscriptionState viewerSubscription;
@javax.validation.constraints.NotNull
private String zipballUrl;
public Commit() {
...
...
src/test/resources/expected-classes/Commit_noValidationAnnotation.java.txt
0 → 100644
浏览文件 @
45a9a046
package com.github.graphql;
import java.util.*;
public class Commit implements Closer, IssueTimelineItem, PullRequestTimelineItem, GitObject, Node, Subscribable, UniformResourceLocatable{
private String abbreviatedOid;
private Integer additions;
private PullRequestConnection associatedPullRequests;
private GitActor author;
private Boolean authoredByCommitter;
private String authoredDate;
private Blame blame;
private Integer changedFiles;
private CommitCommentConnection comments;
private String commitResourcePath;
private String commitUrl;
private String committedDate;
private Boolean committedViaWeb;
private GitActor committer;
private Integer deletions;
private DeploymentConnection deployments;
private CommitHistoryConnection history;
private String id;
private String message;
private String messageBody;
private String messageBodyHTML;
private String messageHeadline;
private String messageHeadlineHTML;
private String oid;
private CommitConnection parents;
private String pushedDate;
private Repository repository;
private String resourcePath;
private GitSignature signature;
private Status status;
private String tarballUrl;
private Tree tree;
private String treeResourcePath;
private String treeUrl;
private String url;
private Boolean viewerCanSubscribe;
private SubscriptionState viewerSubscription;
private String zipballUrl;
public Commit() {
}
public String getAbbreviatedOid() {
return abbreviatedOid;
}
public void setAbbreviatedOid(String abbreviatedOid) {
this.abbreviatedOid = abbreviatedOid;
}
public Integer getAdditions() {
return additions;
}
public void setAdditions(Integer additions) {
this.additions = additions;
}
public PullRequestConnection getAssociatedPullRequests() {
return associatedPullRequests;
}
public void setAssociatedPullRequests(PullRequestConnection associatedPullRequests) {
this.associatedPullRequests = associatedPullRequests;
}
public GitActor getAuthor() {
return author;
}
public void setAuthor(GitActor author) {
this.author = author;
}
public Boolean getAuthoredByCommitter() {
return authoredByCommitter;
}
public void setAuthoredByCommitter(Boolean authoredByCommitter) {
this.authoredByCommitter = authoredByCommitter;
}
public String getAuthoredDate() {
return authoredDate;
}
public void setAuthoredDate(String authoredDate) {
this.authoredDate = authoredDate;
}
public Blame getBlame() {
return blame;
}
public void setBlame(Blame blame) {
this.blame = blame;
}
public Integer getChangedFiles() {
return changedFiles;
}
public void setChangedFiles(Integer changedFiles) {
this.changedFiles = changedFiles;
}
public CommitCommentConnection getComments() {
return comments;
}
public void setComments(CommitCommentConnection comments) {
this.comments = comments;
}
public String getCommitResourcePath() {
return commitResourcePath;
}
public void setCommitResourcePath(String commitResourcePath) {
this.commitResourcePath = commitResourcePath;
}
public String getCommitUrl() {
return commitUrl;
}
public void setCommitUrl(String commitUrl) {
this.commitUrl = commitUrl;
}
public String getCommittedDate() {
return committedDate;
}
public void setCommittedDate(String committedDate) {
this.committedDate = committedDate;
}
public Boolean getCommittedViaWeb() {
return committedViaWeb;
}
public void setCommittedViaWeb(Boolean committedViaWeb) {
this.committedViaWeb = committedViaWeb;
}
public GitActor getCommitter() {
return committer;
}
public void setCommitter(GitActor committer) {
this.committer = committer;
}
public Integer getDeletions() {
return deletions;
}
public void setDeletions(Integer deletions) {
this.deletions = deletions;
}
public DeploymentConnection getDeployments() {
return deployments;
}
public void setDeployments(DeploymentConnection deployments) {
this.deployments = deployments;
}
public CommitHistoryConnection getHistory() {
return history;
}
public void setHistory(CommitHistoryConnection history) {
this.history = history;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getMessageBody() {
return messageBody;
}
public void setMessageBody(String messageBody) {
this.messageBody = messageBody;
}
public String getMessageBodyHTML() {
return messageBodyHTML;
}
public void setMessageBodyHTML(String messageBodyHTML) {
this.messageBodyHTML = messageBodyHTML;
}
public String getMessageHeadline() {
return messageHeadline;
}
public void setMessageHeadline(String messageHeadline) {
this.messageHeadline = messageHeadline;
}
public String getMessageHeadlineHTML() {
return messageHeadlineHTML;
}
public void setMessageHeadlineHTML(String messageHeadlineHTML) {
this.messageHeadlineHTML = messageHeadlineHTML;
}
public String getOid() {
return oid;
}
public void setOid(String oid) {
this.oid = oid;
}
public CommitConnection getParents() {
return parents;
}
public void setParents(CommitConnection parents) {
this.parents = parents;
}
public String getPushedDate() {
return pushedDate;
}
public void setPushedDate(String pushedDate) {
this.pushedDate = pushedDate;
}
public Repository getRepository() {
return repository;
}
public void setRepository(Repository repository) {
this.repository = repository;
}
public String getResourcePath() {
return resourcePath;
}
public void setResourcePath(String resourcePath) {
this.resourcePath = resourcePath;
}
public GitSignature getSignature() {
return signature;
}
public void setSignature(GitSignature signature) {
this.signature = signature;
}
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
public String getTarballUrl() {
return tarballUrl;
}
public void setTarballUrl(String tarballUrl) {
this.tarballUrl = tarballUrl;
}
public Tree getTree() {
return tree;
}
public void setTree(Tree tree) {
this.tree = tree;
}
public String getTreeResourcePath() {
return treeResourcePath;
}
public void setTreeResourcePath(String treeResourcePath) {
this.treeResourcePath = treeResourcePath;
}
public String getTreeUrl() {
return treeUrl;
}
public void setTreeUrl(String treeUrl) {
this.treeUrl = treeUrl;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Boolean getViewerCanSubscribe() {
return viewerCanSubscribe;
}
public void setViewerCanSubscribe(Boolean viewerCanSubscribe) {
this.viewerCanSubscribe = viewerCanSubscribe;
}
public SubscriptionState getViewerSubscription() {
return viewerSubscription;
}
public void setViewerSubscription(SubscriptionState viewerSubscription) {
this.viewerSubscription = viewerSubscription;
}
public String getZipballUrl() {
return zipballUrl;
}
public void setZipballUrl(String zipballUrl) {
this.zipballUrl = zipballUrl;
}
}
\ No newline at end of file
src/test/resources/expected-classes/CreateEventMutation.java.txt
浏览文件 @
45a9a046
...
...
@@ -4,6 +4,7 @@ import java.util.*;
public interface CreateEventMutation {
@javax.validation.constraints.NotNull
Event createEvent(String categoryId, String createdBy) throws Exception;
}
\ No newline at end of file
src/test/resources/expected-classes/EventByIdQuery.java.txt
浏览文件 @
45a9a046
...
...
@@ -4,6 +4,7 @@ import java.util.*;
public interface EventByIdQuery {
@javax.validation.constraints.NotNull
Event eventById(String id) throws Exception;
}
\ No newline at end of file
src/test/resources/expected-classes/EventsByCategoryAndStatusQuery.java.txt
浏览文件 @
45a9a046
...
...
@@ -4,6 +4,7 @@ import java.util.*;
public interface EventsByCategoryAndStatusQuery {
@javax.validation.constraints.NotNull
Collection<Event> eventsByCategoryAndStatus(String categoryId, EventStatus status) throws Exception;
}
\ No newline at end of file
src/test/resources/expected-classes/GithubCommitTO.java.txt
浏览文件 @
45a9a046
...
...
@@ -4,43 +4,73 @@ import java.util.*;
public class GithubCommitTO implements GithubCloserTO, GithubIssueTimelineItemTO, GithubPullRequestTimelineItemTO, GithubGitObjectTO, GithubNodeTO, GithubSubscribableTO, GithubUniformResourceLocatableTO{
@javax.validation.constraints.NotNull
private String abbreviatedOid;
@javax.validation.constraints.NotNull
private Integer additions;
private GithubPullRequestConnectionTO associatedPullRequests;
private GithubGitActorTO author;
@javax.validation.constraints.NotNull
private Boolean authoredByCommitter;
@javax.validation.constraints.NotNull
private String authoredDate;
@javax.validation.constraints.NotNull
private GithubBlameTO blame;
@javax.validation.constraints.NotNull
private Integer changedFiles;
@javax.validation.constraints.NotNull
private GithubCommitCommentConnectionTO comments;
@javax.validation.constraints.NotNull
private String commitResourcePath;
@javax.validation.constraints.NotNull
private String commitUrl;
@javax.validation.constraints.NotNull
private String committedDate;
@javax.validation.constraints.NotNull
private Boolean committedViaWeb;
private GithubGitActorTO committer;
@javax.validation.constraints.NotNull
private Integer deletions;
private GithubDeploymentConnectionTO deployments;
@javax.validation.constraints.NotNull
private GithubCommitHistoryConnectionTO history;
@javax.validation.constraints.NotNull
private String id;
@javax.validation.constraints.NotNull
private String message;
@javax.validation.constraints.NotNull
private String messageBody;
@javax.validation.constraints.NotNull
private String messageBodyHTML;
@javax.validation.constraints.NotNull
private String messageHeadline;
@javax.validation.constraints.NotNull
private String messageHeadlineHTML;
@javax.validation.constraints.NotNull
private String oid;
@javax.validation.constraints.NotNull
private GithubCommitConnectionTO parents;
private String pushedDate;
@javax.validation.constraints.NotNull
private GithubRepositoryTO repository;
@javax.validation.constraints.NotNull
private String resourcePath;
private GithubGitSignatureTO signature;
private GithubStatusTO status;
@javax.validation.constraints.NotNull
private String tarballUrl;
@javax.validation.constraints.NotNull
private GithubTreeTO tree;
@javax.validation.constraints.NotNull
private String treeResourcePath;
@javax.validation.constraints.NotNull
private String treeUrl;
@javax.validation.constraints.NotNull
private String url;
@javax.validation.constraints.NotNull
private Boolean viewerCanSubscribe;
private GithubSubscriptionStateTO viewerSubscription;
@javax.validation.constraints.NotNull
private String zipballUrl;
public GithubCommitTO() {
...
...
src/test/resources/expected-classes/Mutation.java.txt
浏览文件 @
45a9a046
...
...
@@ -4,6 +4,7 @@ import java.util.*;
public interface Mutation {
@javax.validation.constraints.NotNull
Event createEvent(String categoryId, String createdBy) throws Exception;
}
\ No newline at end of file
src/test/resources/expected-classes/Query.java.txt
浏览文件 @
45a9a046
...
...
@@ -4,10 +4,13 @@ import java.util.*;
public interface Query {
@javax.validation.constraints.NotNull
String version() throws Exception;
@javax.validation.constraints.NotNull
Collection<Event> eventsByCategoryAndStatus(String categoryId, EventStatus status) throws Exception;
@javax.validation.constraints.NotNull
Event eventById(String id) throws Exception;
}
\ No newline at end of file
src/test/resources/expected-classes/VersionQuery.java.txt
浏览文件 @
45a9a046
...
...
@@ -4,6 +4,7 @@ import java.util.*;
public interface VersionQuery {
@javax.validation.constraints.NotNull
String version() throws Exception;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录