use of cz.habarta.typescript.generator.parser.RestApplicationModel in project typescript-generator by vojtechhabarta.
the class ModelCompiler method javaToTypeScript.
public TsModel javaToTypeScript(Model model) {
final SymbolTable symbolTable = new SymbolTable(settings);
final List<Extension.TransformerDefinition> extensionTransformers = getExtensionTransformers();
model = applyExtensionModelTransformers(symbolTable, model, extensionTransformers);
TsModel tsModel = processModel(symbolTable, model);
tsModel = addCustomTypeAliases(symbolTable, tsModel);
tsModel = removeInheritedProperties(symbolTable, tsModel);
tsModel = addImplementedProperties(symbolTable, tsModel);
tsModel = sortPropertiesDeclarations(symbolTable, tsModel);
if (settings.generateConstructors) {
tsModel = addConstructors(symbolTable, tsModel);
}
// REST
if (settings.isGenerateRest()) {
final Symbol responseSymbol = createRestResponseType(symbolTable, tsModel);
final TsType optionsType = settings.restOptionsType != null ? new TsType.VerbatimType(settings.restOptionsType) : null;
final TsType.GenericVariableType optionsGenericVariable = settings.restOptionsTypeIsGeneric ? new TsType.GenericVariableType(settings.restOptionsType) : null;
final List<RestApplicationModel> restApplicationsWithInterface = model.getRestApplications().stream().filter(restApplication -> restApplication.getType().generateInterface.apply(settings)).collect(Collectors.toList());
final List<RestApplicationModel> restApplicationsWithClient = model.getRestApplications().stream().filter(restApplication -> restApplication.getType().generateClient.apply(settings)).collect(Collectors.toList());
if (!restApplicationsWithInterface.isEmpty()) {
createRestInterfaces(tsModel, symbolTable, restApplicationsWithInterface, responseSymbol, optionsGenericVariable, optionsType);
}
if (!restApplicationsWithClient.isEmpty()) {
createRestClients(tsModel, symbolTable, restApplicationsWithClient, responseSymbol, optionsGenericVariable, optionsType);
}
}
// dates
tsModel = transformMaps(symbolTable, tsModel);
// dates
tsModel = transformDates(symbolTable, tsModel);
// enums
tsModel = applyExtensionTransformers(symbolTable, model, tsModel, TransformationPhase.BeforeEnums, extensionTransformers);
tsModel = addEnumValuesToJavadoc(tsModel);
if (settings.enumMemberCasing != null && settings.enumMemberCasing != IdentifierCasing.keepOriginal) {
tsModel = transformEnumMembersCase(tsModel);
}
if (!settings.areDefaultStringEnumsOverriddenByExtension()) {
if (settings.mapEnum == null || settings.mapEnum == EnumMapping.asUnion || settings.mapEnum == EnumMapping.asInlineUnion) {
tsModel = transformEnumsToUnions(tsModel);
}
if (settings.mapEnum == EnumMapping.asInlineUnion) {
tsModel = inlineEnums(tsModel, symbolTable);
}
if (settings.mapEnum == EnumMapping.asNumberBasedEnum) {
tsModel = transformEnumsToNumberBasedEnum(tsModel);
}
}
// after enum transformations transform Maps with rest of the enums (not unions) used in keys
tsModel = transformNonStringEnumKeyMaps(symbolTable, tsModel);
// tagged unions
tsModel = createAndUseTaggedUnions(symbolTable, tsModel);
// nullable types and optional properties
tsModel = makeUndefinablePropertiesAndParametersOptional(symbolTable, tsModel);
tsModel = transformNullableTypes(symbolTable, tsModel);
tsModel = eliminateUndefinedFromOptionalPropertiesAndParameters(symbolTable, tsModel);
tsModel = transformOptionalProperties(symbolTable, tsModel);
tsModel = applyExtensionTransformers(symbolTable, model, tsModel, TransformationPhase.BeforeSymbolResolution, extensionTransformers);
symbolTable.resolveSymbolNames();
tsModel = sortTypeDeclarations(symbolTable, tsModel);
tsModel = applyExtensionTransformers(symbolTable, model, tsModel, TransformationPhase.AfterDeclarationSorting, extensionTransformers);
return tsModel;
}
use of cz.habarta.typescript.generator.parser.RestApplicationModel in project typescript-generator by vojtechhabarta.
the class ModelCompiler method processRestMethodGroup.
private List<TsMethodModel> processRestMethodGroup(TsModel tsModel, SymbolTable symbolTable, List<Pair<RestApplicationModel, RestMethodModel>> methods, Symbol responseSymbol, TsType optionsType, boolean implement) {
final List<TsMethodModel> resultMethods = new ArrayList<>();
final Map<String, Long> methodNamesCount = groupingByMethodName(methods);
for (Pair<RestApplicationModel, RestMethodModel> pair : methods) {
final RestApplicationModel restApplication = pair.getValue1();
final RestMethodModel method = pair.getValue2();
final boolean createLongName = methodNamesCount.get(method.getName()) > 1;
resultMethods.add(processRestMethod(tsModel, symbolTable, restApplication.getApplicationPath(), responseSymbol, method, createLongName, optionsType, implement));
}
return resultMethods;
}
Aggregations