Skip to content

Commit

Permalink
Using endpoint directly instead of ginving example path
Browse files Browse the repository at this point in the history
  • Loading branch information
kojilin committed Sep 7, 2020
1 parent 5b760ca commit 9a8e4f0
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 79 deletions.
9 changes: 6 additions & 3 deletions docs-client/src/containers/MethodPage/DebugPage.tsx
Expand Up @@ -477,9 +477,12 @@ const DebugPage: React.FunctionComponent<Props> = ({
if (isAnnotatedService) {
return examplePaths;
}
return examplePaths.filter((path) =>
transport.findDebugMimeTypeEndpoint(method, path.value),
);
return transport.listDebugMimeTypeEndpoint(method).map((endpoint) => {
return {
label: endpoint.pathMapping,
value: endpoint.pathMapping,
};
});
}, [examplePaths, method, isAnnotatedService, transport]);

return (
Expand Down
96 changes: 47 additions & 49 deletions docs-client/src/containers/MethodPage/EndpointPath.tsx
Expand Up @@ -33,54 +33,52 @@ interface Props {
onPathFormChange: (e: ChangeEvent<HTMLInputElement>) => void;
}

const EndpointPath: React.FunctionComponent<Props> = (props) => {
return (
<>
<Typography variant="body2" paragraph />
<Button color="secondary" onClick={props.onEditEndpointPathClick}>
Endpoint path
</Button>
<Typography variant="body2" paragraph />
{props.endpointPathOpen && (
<>
{props.isAnnotatedService ? (
<>
{props.examplePaths.length > 0 && (
<>
<Typography variant="body2" paragraph />
<Dropdown
placeholder="Select an example path..."
options={props.examplePaths}
onChange={props.onSelectedPathChange}
/>
</>
)}
<Typography variant="body2" paragraph />
<TextField
fullWidth
value={props.additionalPath}
placeholder={endpointPathPlaceHolder}
onChange={props.onPathFormChange}
inputProps={{
readOnly: !props.editable,
className: 'code',
}}
/>
</>
) : (
<>
<Typography variant="body2" paragraph />
<Dropdown
options={props.examplePaths}
onChange={props.onSelectedPathChange}
value={props.additionalPath}
/>
</>
)}
</>
)}
</>
);
};
const EndpointPath: React.FunctionComponent<Props> = (props) => (
<>
<Typography variant="body2" paragraph />
<Button color="secondary" onClick={props.onEditEndpointPathClick}>
Endpoint path
</Button>
<Typography variant="body2" paragraph />
{props.endpointPathOpen && (
<>
{props.isAnnotatedService ? (
<>
{props.examplePaths.length > 0 && (
<>
<Typography variant="body2" paragraph />
<Dropdown
placeholder="Select an example path..."
options={props.examplePaths}
onChange={props.onSelectedPathChange}
/>
</>
)}
<Typography variant="body2" paragraph />
<TextField
fullWidth
value={props.additionalPath}
placeholder={endpointPathPlaceHolder}
onChange={props.onPathFormChange}
inputProps={{
readOnly: !props.editable,
className: 'code',
}}
/>
</>
) : (
<>
<Typography variant="body2" paragraph />
<Dropdown
options={props.examplePaths}
onChange={props.onSelectedPathChange}
value={props.additionalPath}
/>
</>
)}
</>
)}
</>
);

export default React.memo(EndpointPath);
12 changes: 6 additions & 6 deletions docs-client/src/lib/transports/transport.ts
Expand Up @@ -104,6 +104,12 @@ export default abstract class Transport {
return body;
}

public listDebugMimeTypeEndpoint(method: Method): Endpoint[] {
return method.endpoints.filter((endpoint) =>
endpoint.availableMimeTypes.includes(this.getDebugMimeType()),
);
}

/**
* Checking if the endpoint's path supports target path.
* Default implementation is suitable for RPC, using endpoint.pathMapping === path.
Expand All @@ -124,10 +130,4 @@ export default abstract class Transport {
endpointPath?: string,
queries?: string,
): Promise<string>;

private listDebugMimeTypeEndpoint(method: Method): Endpoint[] {
return method.endpoints.filter((endpoint) =>
endpoint.availableMimeTypes.includes(this.getDebugMimeType()),
);
}
}
Expand Up @@ -34,7 +34,6 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Streams;
import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.EnumDescriptor;
import com.google.protobuf.Descriptors.FieldDescriptor;
Expand Down Expand Up @@ -278,9 +277,6 @@ static MethodInfo newMethodInfo(MethodDescriptor method, ServiceEntry service) {
})
.collect(toImmutableSet());

final List<String> examplePaths =
Streams.stream(methodEndpoints).map(EndpointInfo::pathMapping).collect(toImmutableList());

return new MethodInfo(
method.getName(),
namedMessageSignature(method.getOutputType()),
Expand All @@ -291,7 +287,7 @@ static MethodInfo newMethodInfo(MethodDescriptor method, ServiceEntry service) {
methodEndpoints,
/* exampleHeaders */ ImmutableList.of(),
defaultExamples(method),
examplePaths,
/* examplePaths */ ImmutableList.of(),
/* exampleQueries */ ImmutableList.of(),
HttpMethod.POST,
/* docString */ null);
Expand Down
Expand Up @@ -85,26 +85,17 @@ void servicesTest() throws Exception {
m.endpoints().forEach(e -> {
assertThat(e.pathMapping()).isEqualTo("/armeria.grpc.testing.TestService/" + m.name());
});
m.examplePaths().forEach(p -> {
assertThat(p).isEqualTo("/armeria.grpc.testing.TestService/" + m.name());
});
});
services.get(UnitTestServiceGrpc.SERVICE_NAME).methods().forEach(m -> {
m.endpoints().forEach(e -> {
assertThat(e.pathMapping()).isEqualTo("/test/armeria.grpc.testing.UnitTestService/" + m.name());
});
m.examplePaths().forEach(p -> {
assertThat(p).isEqualTo("/test/armeria.grpc.testing.UnitTestService/" + m.name());
});
});
services.get(ReconnectServiceGrpc.SERVICE_NAME).methods().forEach(m -> {
m.endpoints().forEach(e -> {
assertThat(e.pathMapping()).isEqualTo("/reconnect/armeria.grpc.testing.ReconnectService/" +
m.name());
});
m.examplePaths().forEach(p -> {
assertThat(p).isEqualTo("/reconnect/armeria.grpc.testing.ReconnectService/" + m.name());
});
});
}

Expand Down
Expand Up @@ -53,7 +53,6 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Streams;

import com.linecorp.armeria.common.HttpMethod;
import com.linecorp.armeria.common.thrift.ThriftProtocolFactories;
Expand Down Expand Up @@ -268,13 +267,10 @@ private static MethodInfo newMethodInfo(String name,
.map(TypeSignature::ofNamed)
.collect(toImmutableList());

final List<String> examplePaths =
Streams.stream(endpoints).map(EndpointInfo::pathMapping).collect(toImmutableList());

return new MethodInfo(name, returnTypeSignature, parameters, exceptionTypeSignatures, endpoints,
ImmutableList.of(),
ImmutableList.of(),
examplePaths,
ImmutableList.of(),
ImmutableList.of(),
HttpMethod.POST, null);
}
Expand Down
Expand Up @@ -97,7 +97,6 @@ void servicesTest() {
assertThat(methods).containsKey("bar4");
final MethodInfo bar4 = methods.get("bar4");
assertThat(bar4.exampleRequests()).isEmpty();
assertThat(bar4.examplePaths()).containsExactly("/foo");
assertThat(bar4.endpoints())
.containsExactly(EndpointInfo.builder("*", "/foo")
.defaultFormat(ThriftSerializationFormats.COMPACT).build());
Expand Down Expand Up @@ -128,7 +127,6 @@ public void multiplePaths() {
fooServiceInfo.methods().stream()
.collect(toImmutableMap(MethodInfo::name, Function.identity()));
final MethodInfo bar4 = methods.get("bar4");
assertThat(bar4.examplePaths()).containsExactlyInAnyOrder("/foo1", "/foo2");
assertThat(bar4.endpoints())
.containsExactlyInAnyOrder(
EndpointInfo.builder("*", "/foo1")
Expand Down

0 comments on commit 9a8e4f0

Please sign in to comment.