Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display JSON and protobuf request and response specification in DocService #4322

Merged
merged 27 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9358084
Display JSON and protobuf request and response specification in `DocS…
ikhoon Jun 28, 2022
95b0c4d
Fix javadoc error
ikhoon Jun 28, 2022
d9c31a0
Remove cruft
ikhoon Jun 28, 2022
9298e47
Fix tests
ikhoon Jul 1, 2022
9f810ae
Address comments by @jrhee17
ikhoon Jul 18, 2022
d279c17
Merge branch 'master' into struct-info-provider
ikhoon Jul 29, 2022
bfb8a03
Fill `DescriptionInfo` using `NamedTypeInfoProvider`
ikhoon Jul 29, 2022
2327fa5
Refactor `DocService` for better readability
ikhoon Jul 30, 2022
bfd6190
Add ExampleSupport
ikhoon Jul 30, 2022
0c91cfd
Fix NPE
ikhoon Aug 1, 2022
b14dff3
Fix failed tests
ikhoon Aug 1, 2022
11ee1ff
Add alias for linking proto messages
ikhoon Aug 1, 2022
fc32b33
lint
ikhoon Aug 1, 2022
00050a9
Fix tests
ikhoon Aug 3, 2022
316fdcd
Add ReflectiveNamedTypeInfoProvider in order to support non-json types
ikhoon Aug 3, 2022
df72d25
Fix a bug
ikhoon Aug 3, 2022
c3f0b63
Checkstyle
ikhoon Aug 3, 2022
97b9d8c
Rename ThriftNameTypeInfoProvider to ThriftNamedTypeInfoProvider
ikhoon Aug 3, 2022
7e6c892
Address comments
ikhoon Aug 8, 2022
b822357
Remove cruft
ikhoon Aug 8, 2022
5b3f3f1
Update Javadoc for alias
ikhoon Aug 11, 2022
f81452b
Use TEnum
ikhoon Aug 16, 2022
61dd8c0
Add tests to check unexpect types
ikhoon Aug 16, 2022
8412738
Fix compile errors
ikhoon Aug 16, 2022
05e11ac
Add comments
ikhoon Aug 17, 2022
fab9b95
Merge branch 'master' into struct-info-provider
ikhoon Sep 8, 2022
53475b1
Fix mistaks in the comments and Javadoc. No code has changed
ikhoon Sep 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -585,15 +585,14 @@ private static <T extends Annotation, R> Builder<R> getAnnotatedInstances(
/**
* Returns the description of the specified {@link AnnotatedElement}.
*/
@Nullable
static DescriptionInfo findDescription(AnnotatedElement annotatedElement) {
requireNonNull(annotatedElement, "annotatedElement");
final Description description = AnnotationUtil.findFirst(annotatedElement, Description.class);
if (description != null) {
final String value = description.value();
if (DefaultValues.isSpecified(value)) {
checkArgument(!value.isEmpty(), "value is empty.");
return DescriptionInfo.of(description.value(), description.markup());
return DescriptionInfo.from(description);
}
} else if (annotatedElement instanceof Parameter) {
// JavaDoc/KDoc descriptions only exist for method parameters
Expand All @@ -605,24 +604,24 @@ static DescriptionInfo findDescription(AnnotatedElement annotatedElement) {
final Properties cachedProperties = DOCUMENTATION_PROPERTIES_CACHE.getIfPresent(fileName);
if (cachedProperties != null) {
final String propertyValue = cachedProperties.getProperty(propertyName);
return propertyValue != null ? DescriptionInfo.of(propertyValue) : null;
return propertyValue != null ? DescriptionInfo.of(propertyValue) : DescriptionInfo.empty();
}
try (InputStream stream = AnnotatedServiceFactory.class.getClassLoader()
.getResourceAsStream(fileName)) {
if (stream == null) {
return null;
return DescriptionInfo.empty();
}
final Properties properties = new Properties();
properties.load(stream);
DOCUMENTATION_PROPERTIES_CACHE.put(fileName, properties);

final String propertyValue = properties.getProperty(propertyName);
return propertyValue != null ? DescriptionInfo.of(propertyValue) : null;
return propertyValue != null ? DescriptionInfo.of(propertyValue) : DescriptionInfo.empty();
} catch (IOException exception) {
logger.warn("Failed to load an API description file: {}", fileName, exception);
}
}
return null;
return DescriptionInfo.empty();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ private static void warnOnDuplicateResolver(Executable constructorOrMethod,
private static AnnotatedValueResolver ofPathVariable(String name,
AnnotatedElement annotatedElement,
AnnotatedElement typeElement, Class<?> type,
@Nullable DescriptionInfo description) {
DescriptionInfo description) {
return new Builder(annotatedElement, type)
.annotationType(Param.class)
.httpElementName(name)
Expand All @@ -550,7 +550,7 @@ private static AnnotatedValueResolver ofPathVariable(String name,
private static AnnotatedValueResolver ofQueryParam(String name,
AnnotatedElement annotatedElement,
AnnotatedElement typeElement, Class<?> type,
@Nullable DescriptionInfo description,
DescriptionInfo description,
@Nullable String serviceQueryDelimiter) {
String queryDelimiter = serviceQueryDelimiter;
final Delimiter delimiter = annotatedElement.getAnnotation(Delimiter.class);
Expand All @@ -576,7 +576,7 @@ private static AnnotatedValueResolver ofQueryParam(String name,
private static AnnotatedValueResolver ofFileParam(String name,
AnnotatedElement annotatedElement,
AnnotatedElement typeElement, Class<?> type,
@Nullable DescriptionInfo description) {
DescriptionInfo description) {
return new Builder(annotatedElement, type)
.annotationType(Param.class)
.httpElementName(name)
Expand All @@ -591,7 +591,7 @@ private static AnnotatedValueResolver ofFileParam(String name,
private static AnnotatedValueResolver ofHeader(String name,
AnnotatedElement annotatedElement,
AnnotatedElement typeElement, Class<?> type,
@Nullable DescriptionInfo description) {
DescriptionInfo description) {
return new Builder(annotatedElement, type)
.annotationType(Header.class)
.httpElementName(name)
Expand All @@ -609,7 +609,7 @@ private static AnnotatedValueResolver ofRequestObject(AnnotatedElement annotated
Class<?> type, Set<String> pathParams,
List<RequestObjectResolver> objectResolvers,
DependencyInjector dependencyInjector,
@Nullable DescriptionInfo description) {
DescriptionInfo description) {
// To do recursive resolution like a bean inside another bean, the original object resolvers should
// be passed into the AnnotatedBeanFactoryRegistry#register.
final BeanFactoryId beanFactoryId = AnnotatedBeanFactoryRegistry.register(
Expand Down Expand Up @@ -874,6 +874,16 @@ private static Type parameterizedTypeOf(AnnotatedElement element) {
element.getClass().getSimpleName());
}

static boolean isAnnotatedNullable(AnnotatedElement annotatedElement) {
for (Annotation a : annotatedElement.getAnnotations()) {
final String annotationTypeName = a.annotationType().getName();
if (annotationTypeName.endsWith(".Nullable")) {
return true;
}
}
return false;
}

@Nullable
private final Class<? extends Annotation> annotationType;

Expand All @@ -893,7 +903,6 @@ private static Type parameterizedTypeOf(AnnotatedElement element) {
@Nullable
private final Object defaultValue;

@Nullable
private final DescriptionInfo description;

private final BiFunction<AnnotatedValueResolver, ResolverContext, Object> resolver;
Expand All @@ -913,7 +922,7 @@ private AnnotatedValueResolver(@Nullable Class<? extends Annotation> annotationT
@Nullable Class<?> containerType, Class<?> elementType,
@Nullable ParameterizedType parameterizedElementType,
@Nullable String defaultValue,
@Nullable DescriptionInfo description,
DescriptionInfo description,
BiFunction<AnnotatedValueResolver, ResolverContext, Object> resolver,
@Nullable BeanFactoryId beanFactoryId,
AggregationStrategy aggregationStrategy) {
Expand All @@ -924,7 +933,7 @@ private AnnotatedValueResolver(@Nullable Class<? extends Annotation> annotationT
this.shouldWrapValueAsOptional = shouldWrapValueAsOptional;
this.elementType = requireNonNull(elementType, "elementType");
this.parameterizedElementType = parameterizedElementType;
this.description = description;
this.description = requireNonNull(description, "description");
this.containerType = containerType;
this.resolver = requireNonNull(resolver, "resolver");
this.beanFactoryId = beanFactoryId;
Expand Down Expand Up @@ -988,7 +997,6 @@ Object defaultValue() {
return defaultValue;
}

@Nullable
DescriptionInfo description() {
return description;
}
Expand Down Expand Up @@ -1068,8 +1076,7 @@ private static final class Builder {
private boolean pathVariable;
private boolean supportContainer;
private boolean supportDefault;
@Nullable
private DescriptionInfo description;
private DescriptionInfo description = DescriptionInfo.empty();
@Nullable
private BiFunction<AnnotatedValueResolver, ResolverContext, Object> resolver;
@Nullable
Expand Down Expand Up @@ -1137,7 +1144,7 @@ private Builder typeElement(AnnotatedElement typeElement) {
/**
* Sets the description of the {@link AnnotatedElement}.
*/
private Builder description(@Nullable DescriptionInfo description) {
private Builder description(DescriptionInfo description) {
this.description = description;
return this;
}
Expand Down Expand Up @@ -1355,16 +1362,6 @@ private Class<?> getElementType(Type parameterizedType, boolean unwrapOptional)
return toRawType(elementType);
}

private static boolean isAnnotatedNullable(AnnotatedElement annotatedElement) {
for (Annotation a : annotatedElement.getAnnotations()) {
final String annotationTypeName = a.annotationType().getName();
if (annotationTypeName.endsWith(".Nullable")) {
return true;
}
}
return false;
}

@Nullable
private static ParameterizedType getParameterizedElementType(Type parameterizedType) {
if (!(parameterizedType instanceof ParameterizedType)) {
Expand Down
Loading