@Test public void parsePathParams() throws Exception { assertThat(CodeGenerator .parsePathParams(TestRequest.getDescriptor(), PathParser.parse("/users/{s}/{uint3}/{nt.f1}"))) .extracting("name") .containsExactly("s", "uint3", "nt.f1"); assertThat(CodeGenerator .parsePathParams(TestRequest.getDescriptor(), PathParser.parse("/users/{s}/{uint3}/{nt.f1}"))) .extracting(x -> Iterables.getLast(x.getFieldDescriptor()).getName()) .containsExactly("s", "uint3", "f1"); }
public static ImmutableList<PathParam> parsePathParams(Descriptors.Descriptor inputDescriptor, PathParser.ParsedPath path) { ImmutableList.Builder<PathParam> pathParams = ImmutableList.builder(); path.visit(new PathParser.EmptySegmentVisitor() { @Override public void visit(PathParser.NamedVariable namedVariable) { ImmutableList<Descriptors.FieldDescriptor> fieldDescriptor = ProtobufDescriptorJavaUtil.fieldPath(inputDescriptor, namedVariable.getName()); if (fieldDescriptor.isEmpty()) { throw new IllegalArgumentException("Couldn't find path param: " + namedVariable.getName() + " in input type: " + inputDescriptor.toProto()); } Descriptors.FieldDescriptor descriptor = Iterables.getLast(fieldDescriptor); if (descriptor.isMapField() || descriptor.isRepeated()) { throw new IllegalArgumentException( "Cannot map path param '" + namedVariable.getName() + "' as URL mapping is not supported " + "for map or repeated field types." ); } pathParams.add(new PathParam(namedVariable.getName(), fieldDescriptor)); } }); return pathParams.build(); }
CodeGenerator { public static ImmutableList<PathParam> parsePathParams(Descriptors.Descriptor inputDescriptor, PathParser.ParsedPath path) { ImmutableList.Builder<PathParam> pathParams = ImmutableList.builder(); path.visit(new PathParser.EmptySegmentVisitor() { @Override public void visit(PathParser.NamedVariable namedVariable) { ImmutableList<Descriptors.FieldDescriptor> fieldDescriptor = ProtobufDescriptorJavaUtil.fieldPath(inputDescriptor, namedVariable.getName()); if (fieldDescriptor.isEmpty()) { throw new IllegalArgumentException("Couldn't find path param: " + namedVariable.getName() + " in input type: " + inputDescriptor.toProto()); } Descriptors.FieldDescriptor descriptor = Iterables.getLast(fieldDescriptor); if (descriptor.isMapField() || descriptor.isRepeated()) { throw new IllegalArgumentException( "Cannot map path param '" + namedVariable.getName() + "' as URL mapping is not supported " + "for map or repeated field types." ); } pathParams.add(new PathParam(namedVariable.getName(), fieldDescriptor)); } }); return pathParams.build(); } }
CodeGenerator { public static ImmutableList<PathParam> parsePathParams(Descriptors.Descriptor inputDescriptor, PathParser.ParsedPath path) { ImmutableList.Builder<PathParam> pathParams = ImmutableList.builder(); path.visit(new PathParser.EmptySegmentVisitor() { @Override public void visit(PathParser.NamedVariable namedVariable) { ImmutableList<Descriptors.FieldDescriptor> fieldDescriptor = ProtobufDescriptorJavaUtil.fieldPath(inputDescriptor, namedVariable.getName()); if (fieldDescriptor.isEmpty()) { throw new IllegalArgumentException("Couldn't find path param: " + namedVariable.getName() + " in input type: " + inputDescriptor.toProto()); } Descriptors.FieldDescriptor descriptor = Iterables.getLast(fieldDescriptor); if (descriptor.isMapField() || descriptor.isRepeated()) { throw new IllegalArgumentException( "Cannot map path param '" + namedVariable.getName() + "' as URL mapping is not supported " + "for map or repeated field types." ); } pathParams.add(new PathParam(namedVariable.getName(), fieldDescriptor)); } }); return pathParams.build(); }  }
CodeGenerator { public static ImmutableList<PathParam> parsePathParams(Descriptors.Descriptor inputDescriptor, PathParser.ParsedPath path) { ImmutableList.Builder<PathParam> pathParams = ImmutableList.builder(); path.visit(new PathParser.EmptySegmentVisitor() { @Override public void visit(PathParser.NamedVariable namedVariable) { ImmutableList<Descriptors.FieldDescriptor> fieldDescriptor = ProtobufDescriptorJavaUtil.fieldPath(inputDescriptor, namedVariable.getName()); if (fieldDescriptor.isEmpty()) { throw new IllegalArgumentException("Couldn't find path param: " + namedVariable.getName() + " in input type: " + inputDescriptor.toProto()); } Descriptors.FieldDescriptor descriptor = Iterables.getLast(fieldDescriptor); if (descriptor.isMapField() || descriptor.isRepeated()) { throw new IllegalArgumentException( "Cannot map path param '" + namedVariable.getName() + "' as URL mapping is not supported " + "for map or repeated field types." ); } pathParams.add(new PathParam(namedVariable.getName(), fieldDescriptor)); } }); return pathParams.build(); }  static ImmutableList<PathParam> parsePathParams(Descriptors.Descriptor inputDescriptor,
            PathParser.ParsedPath path); PluginProtos.CodeGeneratorResponse generate(PluginProtos.CodeGeneratorRequest request); }
CodeGenerator { public static ImmutableList<PathParam> parsePathParams(Descriptors.Descriptor inputDescriptor, PathParser.ParsedPath path) { ImmutableList.Builder<PathParam> pathParams = ImmutableList.builder(); path.visit(new PathParser.EmptySegmentVisitor() { @Override public void visit(PathParser.NamedVariable namedVariable) { ImmutableList<Descriptors.FieldDescriptor> fieldDescriptor = ProtobufDescriptorJavaUtil.fieldPath(inputDescriptor, namedVariable.getName()); if (fieldDescriptor.isEmpty()) { throw new IllegalArgumentException("Couldn't find path param: " + namedVariable.getName() + " in input type: " + inputDescriptor.toProto()); } Descriptors.FieldDescriptor descriptor = Iterables.getLast(fieldDescriptor); if (descriptor.isMapField() || descriptor.isRepeated()) { throw new IllegalArgumentException( "Cannot map path param '" + namedVariable.getName() + "' as URL mapping is not supported " + "for map or repeated field types." ); } pathParams.add(new PathParam(namedVariable.getName(), fieldDescriptor)); } }); return pathParams.build(); }  static ImmutableList<PathParam> parsePathParams(Descriptors.Descriptor inputDescriptor,
            PathParser.ParsedPath path); PluginProtos.CodeGeneratorResponse generate(PluginProtos.CodeGeneratorRequest request);  }