use of com.google.api.codegen.config.FieldModel in project toolkit by googleapis.
the class JavaDiscoGapicRequestToViewTransformer method generateRequestClass.
private StaticLangApiMessageView generateRequestClass(SchemaTransformationContext context, MethodModel method, RequestObjectParamView resourceNameView) {
StaticLangApiMessageView.Builder requestView = StaticLangApiMessageView.newBuilder();
SymbolTable symbolTable = SymbolTable.fromSeed(reservedKeywords);
String requestClassId = context.getNamer().privateFieldName(DiscoGapicParser.getRequestName(((DiscoveryMethodModel) method).getDiscoMethod()));
String requestName = nameFormatter.privateFieldName(Name.anyCamel(symbolTable.getNewSymbol(requestClassId)));
boolean hasRequiredProperties = false;
requestView.name(requestName);
requestView.description(method.getDescription());
String requestTypeName = nameFormatter.publicClassName(Name.anyCamel(requestClassId));
requestView.typeName(requestTypeName);
requestView.innerTypeName(requestTypeName);
List<StaticLangApiMessageView> properties = new LinkedList<>();
// Add the standard query parameters.
for (String param : STANDARD_QUERY_PARAMS.keySet()) {
if (method.getInputField(param) != null) {
continue;
}
StaticLangApiMessageView.Builder paramView = StaticLangApiMessageView.newBuilder();
paramView.description(STANDARD_QUERY_PARAMS.get(param));
paramView.name(symbolTable.getNewSymbol(param));
paramView.typeName("String");
paramView.innerTypeName("String");
paramView.isRequired(false);
paramView.canRepeat(false);
paramView.fieldGetFunction(context.getNamer().getFieldGetFunctionName(DiscoGapicParser.stringToName(param), SurfaceNamer.MapType.NOT_MAP, SurfaceNamer.Cardinality.NOT_REPEATED));
paramView.fieldSetFunction(context.getDiscoGapicNamer().getResourceSetterName(param, SurfaceNamer.Cardinality.NOT_REPEATED, context.getNamer()));
paramView.properties(Collections.emptyList());
paramView.isRequestMessage(false);
paramView.hasRequiredProperties(false);
properties.add(paramView.build());
}
for (FieldModel entry : method.getInputFields()) {
if (entry.mayBeInResourceName()) {
hasRequiredProperties = true;
continue;
}
String parameterName = entry.getNameAsParameter();
properties.add(schemaToParamView(context, entry, parameterName, symbolTable, EscapeName.ESCAPE_NAME));
if (entry.isRequired()) {
hasRequiredProperties = true;
}
}
StaticLangApiMessageView.Builder paramView = StaticLangApiMessageView.newBuilder();
Method discoMethod = ((DiscoveryMethodModel) method).getDiscoMethod();
String resourceName = DiscoGapicParser.getResourceIdentifier(discoMethod.path()).toLowerCamel();
StringBuilder description = new StringBuilder(discoMethod.parameters().get(resourceName).description());
description.append(String.format("\nIt must have the format `%s`. ", discoMethod.path()));
description.append(String.format("\\`{%s}\\` must start with a letter,\n", resourceName));
description.append("and contain only letters (\\`[A-Za-z]\\`), numbers (\\`[0-9]\\`), dashes (\\`-\\`),\n" + " * underscores (\\`_\\`), periods (\\`.\\`), tildes (\\`~\\`), plus (\\`+\\`) or percent\n" + " * signs (\\`%\\`). It must be between 3 and 255 characters in length, and it\n" + " * must not start with \\`\"goog\"\\`.");
paramView.description(description.toString());
paramView.name(symbolTable.getNewSymbol(resourceNameView.name()));
paramView.typeName("String");
paramView.innerTypeName("String");
paramView.isRequired(true);
paramView.canRepeat(false);
paramView.fieldGetFunction(resourceNameView.getCallName());
paramView.fieldSetFunction(resourceNameView.setCallName());
paramView.properties(new LinkedList<>());
paramView.isRequestMessage(false);
paramView.hasRequiredProperties(false);
properties.add(paramView.build());
Collections.sort(properties);
requestView.canRepeat(false);
requestView.isRequired(true);
requestView.properties(properties);
requestView.hasRequiredProperties(hasRequiredProperties);
requestView.isRequestMessage(true);
requestView.pathAsResourceName(resourceNameView);
Schema requestBodyDef = ((DiscoveryMethodModel) method).getDiscoMethod().request();
if (requestBodyDef != null && !Strings.isNullOrEmpty(requestBodyDef.reference())) {
FieldModel requestBody = DiscoveryField.create(requestBodyDef, context.getDocContext().getApiModel());
requestView.requestBodyType(schemaToParamView(context, requestBody, DiscoGapicParser.getSchemaNameAsParameter(requestBodyDef).toLowerCamel(), symbolTable, EscapeName.NO_ESCAPE_NAME));
}
return requestView.build();
}
use of com.google.api.codegen.config.FieldModel in project toolkit by googleapis.
the class InitCodeNode method getChildFieldConfig.
private static FieldConfig getChildFieldConfig(Map<String, FieldConfig> fieldConfigMap, FieldConfig parentFieldConfig, TypeModel parentType, String key) {
if (parentType.isMap()) {
return parentFieldConfig;
} else if (parentType.isRepeated()) {
return parentFieldConfig;
} else if (parentType.isMessage()) {
FieldModel childField = parentType.getField(key);
if (childField == null) {
throw new IllegalArgumentException("Message type " + parentType + " does not have field " + key);
}
FieldConfig fieldConfig = fieldConfigMap.get(childField.getFullName());
if (fieldConfig == null) {
fieldConfig = FieldConfig.createDefaultFieldConfig(childField);
}
return fieldConfig;
} else {
throw new IllegalArgumentException("Primitive type " + parentType + " cannot have children. Child key: " + key);
}
}
use of com.google.api.codegen.config.FieldModel in project toolkit by googleapis.
the class BatchingTransformer method generateDescriptorClass.
private BatchingDescriptorClassView generateDescriptorClass(MethodContext context) {
SurfaceNamer namer = context.getNamer();
MethodModel method = context.getMethodModel();
BatchingConfig batching = context.getMethodConfig().getBatching();
FieldModel batchedField = batching.getBatchedField();
FieldModel subresponseField = batching.getSubresponseField();
BatchingDescriptorClassView.Builder desc = BatchingDescriptorClassView.newBuilder();
desc.name(context.getNamer().getBatchingDescriptorConstName(context.getMethodModel()));
desc.requestTypeName(method.getAndSaveRequestTypeName(context.getTypeTable(), context.getNamer()));
desc.responseTypeName(method.getAndSaveResponseTypeName(context.getTypeTable(), context.getNamer()));
desc.batchedFieldTypeName(context.getTypeTable().getAndSaveNicknameFor(batchedField));
desc.partitionKeys(generatePartitionKeys(context));
desc.discriminatorFieldCopies(generateDiscriminatorFieldCopies(context));
desc.batchedFieldGetFunction(namer.getFieldGetFunctionName(batchedField));
desc.batchedFieldSetFunction(namer.getFieldSetFunctionName(batchedField));
desc.batchedFieldCountGetFunction(namer.getFieldCountGetFunctionName(batchedField));
if (subresponseField != null) {
desc.subresponseTypeName(context.getTypeTable().getAndSaveNicknameFor(subresponseField));
desc.subresponseByIndexGetFunction(namer.getByIndexGetFunctionName(subresponseField));
desc.subresponseSetFunction(namer.getFieldSetFunctionName(subresponseField));
}
return desc.build();
}
use of com.google.api.codegen.config.FieldModel in project toolkit by googleapis.
the class GrpcElementDocTransformer method generateMessagePropertyDocs.
private List<ParamDocView> generateMessagePropertyDocs(ModelTypeTable typeTable, SurfaceNamer namer, Iterable<FieldModel> fields) {
ImmutableList.Builder<ParamDocView> propertyDocs = ImmutableList.builder();
for (FieldModel field : fields) {
SimpleParamDocView.Builder doc = SimpleParamDocView.newBuilder();
doc.paramName(namer.getFieldKey(field));
doc.typeName(namer.getMessagePropertyTypeName(typeTable, field));
doc.lines(namer.getDocLines(field));
propertyDocs.add(doc.build());
}
return propertyDocs.build();
}
use of com.google.api.codegen.config.FieldModel in project toolkit by googleapis.
the class IamResourceTransformer method generateIamResources.
public List<IamResourceView> generateIamResources(InterfaceContext context) {
List<IamResourceView> resources = new ArrayList<>();
for (FieldModel field : context.getProductConfig().getInterfaceConfig(context.getInterfaceModel()).getIamResources()) {
String resourceTypeName = context.getImportTypeTable().getAndSaveNicknameFor(field.getParentTypeName(context.getImportTypeTable()).getFullName());
resources.add(IamResourceView.builder().resourceGetterFunctionName(context.getNamer().getIamResourceGetterFunctionName(field)).paramName(context.getNamer().getIamResourceParamName(field)).exampleName(context.getNamer().getIamResourceGetterFunctionExampleName(context.getInterfaceConfig(), field)).fieldName(context.getNamer().publicFieldName(Name.from(field.getSimpleName()))).resourceTypeName(resourceTypeName).resourceConstructorName(context.getNamer().getTypeConstructor(resourceTypeName)).build());
}
return resources;
}
Aggregations