Skip to content

Commit

Permalink
Merge branch 'master' into revert-16
Browse files Browse the repository at this point in the history
  • Loading branch information
vam-google committed Apr 29, 2021
2 parents eb7e5f4 + 4518386 commit 1e787df
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 108 deletions.
7 changes: 7 additions & 0 deletions SECURITY.md
@@ -0,0 +1,7 @@
# Security Policy

To report a security issue, please use [g.co/vulnz](https://g.co/vulnz).

The Google Security Team will respond within 5 working days of your report on g.co/vulnz.

We use g.co/vulnz for our intake, and do coordination and disclosure here using GitHub Security Advisory to privately discuss and fix the issue.
18 changes: 9 additions & 9 deletions pom.xml
Expand Up @@ -17,37 +17,37 @@
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>1.6</version>
<version>1.8.1</version>
</dependency>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value-annotations</artifactId>
<version>1.6</version>
<version>1.8.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.11.0</version>
<version>2.12.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.11.0</version>
<version>2.12.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.0</version>
<version>2.12.3</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.2-android</version>
<version>30.1.1-jre</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.7</version>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
Expand All @@ -62,7 +62,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -73,7 +73,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<version>3.3.0</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
Expand Down
5 changes: 5 additions & 0 deletions renovate.json
@@ -0,0 +1,5 @@
{
"extends": [
"config:base"
]
}
Expand Up @@ -87,7 +87,7 @@ private ProtoFile readDocumentMetadata(Document document, String documentFileNam

private void readSchema(Document document) {
for (Map.Entry<String, Schema> entry : document.schemas().entrySet()) {
schemaToField(entry.getValue());
schemaToField(entry.getValue(), true);
}
for (Message message : allMessages.values()) {
resolveReferences(message);
Expand Down Expand Up @@ -127,14 +127,16 @@ private void cleanupEnumNamingConflicts() {
Field f = fields.next();
if (enumNames.contains(f.getValueType().getName())) {
String desc = sanitizeDescr(f.getDescription());
fields.set(new Field(f.getName(), stringType, f.isRepeated(), f.getKeyType(), desc));
fields.set(
new Field(
f.getName(), stringType, f.isRepeated(), f.isOptional(), f.getKeyType(), desc));
}
}
}
}
}

private Field schemaToField(Schema sch) {
private Field schemaToField(Schema sch, boolean optional) {
String name = Name.anyCamel(sch.key()).toLowerUnderscore();
String description = sch.description();
Message valueType = null;
Expand Down Expand Up @@ -198,18 +200,20 @@ private Field schemaToField(Schema sch) {
}

if (repeated) {
Field subField = schemaToField(keyType == null ? sch.items() : sch.additionalProperties());
Field subField =
schemaToField(keyType == null ? sch.items() : sch.additionalProperties(), true);
valueType = subField.getValueType();
}

Field field = new Field(name, valueType, repeated, keyType, sanitizeDescr(description));
Field field =
new Field(name, valueType, repeated, optional, keyType, sanitizeDescr(description));
if (sch.type() == Schema.Type.EMPTY) {
} else if (Message.PRIMITIVES.containsKey(valueType.getName())) {
return field;
}

for (Map.Entry<String, Schema> entry : sch.properties().entrySet()) {
Field valueTypeField = schemaToField(entry.getValue());
Field valueTypeField = schemaToField(entry.getValue(), true);
valueType.getFields().add(valueTypeField);
if (valueTypeField.getValueType().isEnum()) {
valueType.getEnums().add(valueTypeField.getValueType());
Expand Down Expand Up @@ -263,17 +267,16 @@ private Message constructEnumMessage(

String dummyDesc = "A value indicating that the enum field is not set.";
String dummyFieldName = Name.anyCamel("Undefined", name).toUpperUnderscore();

Message emptyType = Message.PRIMITIVES.get("");
Field dummyField =
new Field(
dummyFieldName, Message.PRIMITIVES.get(""), false, null, sanitizeDescr(dummyDesc));
new Field(dummyFieldName, emptyType, false, false, null, sanitizeDescr(dummyDesc));
enumMessage.getFields().add(dummyField);

Iterator<String> valIter = enumVals.iterator();
Iterator<String> descIter = enumDescs.iterator();
while (valIter.hasNext() && descIter.hasNext()) {
String desc = sanitizeDescr(descIter.next());
Field enumField = new Field(valIter.next(), Message.PRIMITIVES.get(""), false, null, desc);
Field enumField = new Field(valIter.next(), emptyType, false, false, null, desc);
if (dummyField.getName().equals(enumField.getName())) {
continue;
}
Expand Down Expand Up @@ -334,8 +337,9 @@ private void readResources(Document document) {
}

for (Schema pathParam : method.pathParams().values()) {
Field pathField = schemaToField(pathParam);
if (methodSignatureParamNames.containsKey(pathParam.getIdentifier())) {
boolean required = methodSignatureParamNames.containsKey(pathParam.getIdentifier());
Field pathField = schemaToField(pathParam, !required);
if (required) {
pathField.getOptions().add(getFieldBehaviorOption("REQUIRED"));
methodSignatureParamNames.put(pathParam.getIdentifier(), pathField.getName());
}
Expand All @@ -346,8 +350,9 @@ private void readResources(Document document) {
}

for (Schema queryParam : method.queryParams().values()) {
Field queryField = schemaToField(queryParam);
if (methodSignatureParamNames.containsKey(queryParam.getIdentifier())) {
boolean required = methodSignatureParamNames.containsKey(queryParam.getIdentifier());
Field queryField = schemaToField(queryParam, !required);
if (required) {
queryField.getOptions().add(getFieldBehaviorOption("REQUIRED"));
methodSignatureParamNames.put(queryParam.getIdentifier(), queryField.getName());
}
Expand All @@ -369,7 +374,7 @@ private void readResources(Document document) {
Name.anyCamel(request.getName(), "resource").toLowerUnderscore();
String description = getMessageBodyDescription();
Field bodyField =
new Field(requestFieldName, request, false, null, sanitizeDescr(description));
new Field(requestFieldName, request, false, false, null, sanitizeDescr(description));
bodyField.getOptions().add(getFieldBehaviorOption("REQUIRED"));
input.getFields().add(bodyField);
methodHttpOption.getProperties().put("body", requestFieldName);
Expand Down
Expand Up @@ -23,15 +23,22 @@ public class Field extends ProtoElement {
private final String name;
private Message valueType;
private final boolean repeated;
private final boolean optional;
private Message keyType;
private final List<Option> options = new ArrayList<>();

public Field(
String name, Message valueType, boolean repeated, Message keyType, String description) {
String name,
Message valueType,
boolean repeated,
boolean optional,
Message keyType,
String description) {
super(description);
this.name = name;
this.valueType = valueType;
this.repeated = repeated;
this.optional = optional;
this.keyType = keyType;
}

Expand All @@ -51,6 +58,10 @@ public boolean isRepeated() {
return repeated;
}

public boolean isOptional() {
return optional;
}

public void setKeyType(Message keyType) {
this.keyType = keyType;
}
Expand Down Expand Up @@ -97,6 +108,9 @@ public String toString() {
sb.append("repeated ").append(valueType);
}
} else {
if (optional) {
sb.append("optional ");
}
sb.append(valueType);
}
if (sb.length() > 0) {
Expand Down

0 comments on commit 1e787df

Please sign in to comment.