public String typeName() { return TSSyntax.escapeKeyword(this._dataSchema.getName(), EscapeStrategy.MANGLE); }
public Set<String> modulesRequiredToUse() { Set<String> modules = new HashSet<>(); // Named types get their own files, so you have to import them in order to use them. modules.add(importString(_dataSchema.getName(), _dataSchema.getNamespace())); return modules; } }
protected void writeSchemaName(NamedDataSchema schema) throws IOException { _builder.writeString(_currentNamespace.equals(schema.getNamespace()) ? schema.getName() : schema.getFullName()); }
/** * Return the {@link DataSchema}'s language binding name. * This is the fully qualified name for the generated data model to resolve potential name conflict. * * @return the {@link DataSchema}'s language binding name. */ @Override public String getBindingName() { return (_package == null || _package.isEmpty()) ? getFullName() : _package + "." + getName(); }
/** * Return Java class name for a {@link com.linkedin.data.schema.NamedDataSchema}. * * @param schema provides the {@link com.linkedin.data.schema.NamedDataSchema}. * * @return the fully qualified Java class name for the provided {@link com.linkedin.data.schema.NamedDataSchema}. */ public static String classNameForNamedSchema(NamedDataSchema schema) { final StringBuilder sb = new StringBuilder(); final String namespace = schema.getNamespace(); if (!namespace.isEmpty()) { sb.append(namespace); sb.append('.'); } sb.append(schema.getName()); return sb.toString(); }
/** * Return the Avro-compatible union member key (discriminator) for the provided {@link DataSchema}. * * The Avro-compatible key does not include the namespace in the key, e.g. the key for * "com.linkedin.foo.Bar" is "Bar". * * @param schema to return the Avro-compatible union member key for. * @return the Avro-compatible union member key for provided {@link DataSchema}. */ public static String avroUnionMemberKey(DataSchema schema) { DataSchema dereferencedSchema = schema.getDereferencedDataSchema(); String name; // Avro union member type discriminator names if (dereferencedSchema instanceof NamedDataSchema) { name = ((NamedDataSchema) dereferencedSchema).getName(); } else { name = dereferencedSchema.getUnionMemberKey(); } return name; }
/** * Get the .pdl escaped source identifier for the given named type. * If the type is imported, it's simple name will be returned, else it's fully qualified name will be returned. * * @param schema provides the named schema to get a .pdl escaped source identifier for. * @return a escaped source identifier. */ private String toTypeIdentifier(NamedDataSchema schema) { if (schema.getNamespace().equals(_namespace) || (_importsByLocalName.containsKey(schema.getName()) && _importsByLocalName.get(schema.getName()).getNamespace().equals(schema.getNamespace()))) { return escapeIdentifier(schema.getName()); } else { return escapeIdentifier(schema.getFullName()); } }
/** * Returns the union member class name for the given {@link ClassTemplateSpec} as a Typescript * source code string. * * @return a typescript source code string identifying the union member. */ public String unionMemberTypeName() { DataSchema memberSchema = _memberSchema(); Type memberType = _memberSchema().getType(); if (memberSchema.isPrimitive() || memberType == Type.MAP || memberType == Type.ARRAY) { String unionMemberKey = _memberSchema().getUnionMemberKey(); String camelCasedName = Character.toUpperCase(unionMemberKey.charAt(0)) + unionMemberKey.substring(1); return camelCasedName + "Member"; // IntMember, DoubleMember, FixedMember etc } else if (memberSchema instanceof NamedDataSchema) { String className = ((NamedDataSchema) memberSchema).getName(); return className + "Member"; // e.g: FortuneCookieMember } else { throw new IllegalArgumentException("Don't know how to handle schema of type " + memberSchema.getType()); } }
/** * Checks that the schema name and namespace match the file name and path. These must match for * FileDataSchemaResolver to find a schema pdscs by fully qualified name. * */ private void validateSchemaWithFilepath(File schemaSourceFile, DataSchema schema) { if(schemaSourceFile != null && schemaSourceFile.isFile() && schema instanceof NamedDataSchema) { NamedDataSchema namedDataSchema = (NamedDataSchema)schema; String namespace = namedDataSchema.getNamespace(); if(!FileUtil.removeFileExtension(schemaSourceFile.getName()).equalsIgnoreCase(namedDataSchema.getName())) { throw new IllegalArgumentException(namedDataSchema.getFullName() + " has name that does not match filename '" + schemaSourceFile.getAbsolutePath() + "'"); } String directory = schemaSourceFile.getParentFile().getAbsolutePath(); if(!directory.endsWith(namespace.replace('.', File.separatorChar))) { throw new IllegalArgumentException(namedDataSchema.getFullName() + " has namespace that does not match " + "file path '" + schemaSourceFile.getAbsolutePath() + "'"); } } }
/** * Checks that the schema name and namespace match the file name and path. These must match for FileDataSchemaResolver to find a schema pdscs by fully qualified name. */ private void validateSchemaWithFilePath(File schemaSourceFile, DataSchema schema) { if (schemaSourceFile != null && schemaSourceFile.isFile() && schema instanceof NamedDataSchema) { final NamedDataSchema namedDataSchema = (NamedDataSchema) schema; final String namespace = namedDataSchema.getNamespace(); if (!FileUtil.removeFileExtension(schemaSourceFile.getName()).equalsIgnoreCase(namedDataSchema.getName())) { throw new IllegalArgumentException(namedDataSchema.getFullName() + " has name that does not match filename '" + schemaSourceFile.getAbsolutePath() + "'"); } final String directory = schemaSourceFile.getParentFile().getAbsolutePath(); if (!directory.endsWith(namespace.replace('.', File.separatorChar))) { throw new IllegalArgumentException(namedDataSchema.getFullName() + " has namespace that does not match " + "file path '" + schemaSourceFile.getAbsolutePath() + "'"); } } }
private ClassAndSchema getMapValueName(MapDataSchema mapSchema, ClassTemplateSpec enclosingClass, String memberName) { CustomInfoSpec customInfo = getImmediateCustomInfo(mapSchema.getValues()); if (customInfo != null) { return new ClassAndSchema(new ClassInfo(customInfo.getCustomSchema().getNamespace(), customInfo.getCustomSchema().getName()), customInfo.getCustomSchema()); } else { return new ClassAndSchema(classNameForUnnamedTraverse(enclosingClass, memberName, mapSchema.getValues()), mapSchema.getValues()); } }
return new ClassAndSchema(new ClassInfo(customSchema.getNamespace(), customSchema.getName()), customSchema);
if (customInfo != null) return new ClassInfo(customInfo.getCustomSchema().getNamespace(), customInfo.getCustomSchema().getName() + ARRAY_SUFFIX); case ENUM: final NamedDataSchema namedSchema = (NamedDataSchema) dereferencedDataSchema; return new ClassInfo(namedSchema.getNamespace(), CodeUtil.capitalize(namedSchema.getName()));