use of cz.habarta.typescript.generator.Settings in project typescript-generator by vojtechhabarta.
the class AxiosClientExtensionTest method test.
@Test
public void test() {
final Settings settings = TestUtils.settings();
settings.outputFileType = TypeScriptFileType.implementationFile;
settings.outputKind = TypeScriptOutputKind.module;
settings.generateJaxrsApplicationClient = true;
settings.jaxrsNamespacing = JaxrsNamespacing.perResource;
settings.extensions.add(new AxiosClientExtension());
final String output = new TypeScriptGenerator(settings).generateTypeScript(Input.from(JaxrsApplicationTest.OrganizationApplication.class));
final String errorMessage = "Unexpected output: " + output;
Assert.assertTrue(errorMessage, output.contains("interface Organization"));
Assert.assertTrue(errorMessage, output.contains("interface Address"));
Assert.assertTrue(errorMessage, output.contains("interface Person"));
Assert.assertTrue(errorMessage, output.contains("interface HttpClient"));
Assert.assertTrue(errorMessage, output.contains("class OrganizationsResourceClient<O>"));
Assert.assertTrue(errorMessage, output.contains("class PersonResourceClient<O>"));
Assert.assertTrue(errorMessage, output.contains("type RestResponse<R> = Promise<Axios.GenericAxiosResponse<R>>"));
Assert.assertTrue(errorMessage, output.contains("class AxiosHttpClient implements HttpClient<Axios.AxiosRequestConfig>"));
Assert.assertTrue(errorMessage, output.contains("request<R>(requestConfig: { method: string; url: string; queryParams?: any; data?: any; copyFn?: (data: R) => R; options?: Axios.AxiosRequestConfig; }): RestResponse<R>"));
Assert.assertTrue(errorMessage, output.contains("class AxiosOrganizationsResourceClient extends OrganizationsResourceClient<Axios.AxiosRequestConfig>"));
Assert.assertTrue(errorMessage, output.contains("class AxiosPersonResourceClient extends PersonResourceClient<Axios.AxiosRequestConfig>"));
Assert.assertTrue(errorMessage, output.contains("constructor(baseURL: string, axiosInstance: Axios.AxiosInstance = axios.create())"));
}
use of cz.habarta.typescript.generator.Settings in project openremote by openremote.
the class AssetModelInfoExtension method emitElements.
@SuppressWarnings("rawtypes")
@Override
public void emitElements(Writer writer, Settings settings, boolean exportKeyword, TsModel model) {
Map<String, String> assetMap = new HashMap<>();
Map<String, String> otherMap = new HashMap<>();
Arrays.stream(ValueUtil.getAssetInfos(null)).forEach(assetModelInfo -> {
String assetDescriptorName = assetModelInfo.getAssetDescriptor().getName();
assetMap.put(assetDescriptorName.toUpperCase(Locale.ROOT), assetDescriptorName);
// Store attributes
Arrays.stream(assetModelInfo.getAttributeDescriptors()).forEach(attributeDescriptor -> {
String attributeName = attributeDescriptor.getName();
otherMap.put(attributeName.toUpperCase(Locale.ROOT), attributeName);
});
});
emitEnum(writer, "WellknownAssets", assetMap);
writer.writeIndentedLine("");
emitEnum(writer, "WellknownAttributes", otherMap);
otherMap.clear();
Arrays.stream(ValueUtil.getMetaItemDescriptors()).forEach(metaItemDescriptor -> {
String metaName = metaItemDescriptor.getName();
otherMap.put(metaName.toUpperCase(Locale.ROOT), metaName);
});
writer.writeIndentedLine("");
emitEnum(writer, "WellknownMetaItems", otherMap);
otherMap.clear();
Arrays.stream(ValueUtil.getValueDescriptors()).forEach(valueDescriptor -> {
String valueTypeName = valueDescriptor.getName();
otherMap.put(valueTypeName.toUpperCase(Locale.ROOT).replaceAll("[^A-Z0-9]", ""), valueTypeName);
});
writer.writeIndentedLine("");
emitEnum(writer, "WellknownValueTypes", otherMap);
otherMap.clear();
Arrays.stream(Constants.class.getFields()).filter(f -> f.getName().startsWith("UNITS_")).forEach(unitField -> {
String unitName = unitField.getName().substring(6);
try {
otherMap.put(unitName.toUpperCase(Locale.ROOT), (String) unitField.get(null));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
});
writer.writeIndentedLine("");
emitEnum(writer, "WellknownUnitTypes", otherMap);
otherMap.clear();
Arrays.stream(Ruleset.class.getFields()).filter(f -> f.getType() == MetaItemDescriptor.class).forEach(rulesetMeta -> {
try {
MetaItemDescriptor metaItemDescriptor = (MetaItemDescriptor) rulesetMeta.get(null);
otherMap.put(metaItemDescriptor.getName().toUpperCase(Locale.ROOT).replaceAll("[^A-Z0-9]", ""), metaItemDescriptor.getName());
} catch (IllegalAccessException e) {
e.printStackTrace();
}
});
writer.writeIndentedLine("");
emitEnum(writer, "WellknownRulesetMetaItems", otherMap);
}
use of cz.habarta.typescript.generator.Settings in project typescript-generator by vojtechhabarta.
the class BeanPropertyPathExtensionTest method basicTest.
@Test
public void basicTest() throws Exception {
final StringBuilder data = new StringBuilder();
final EmitterExtension.Writer writer = new EmitterExtension.Writer() {
@Override
public void writeIndentedLine(String line) {
data.append(line + "\n");
}
};
final Settings settings = new Settings();
settings.sortDeclarations = true;
final TypeProcessor typeProcessor = new DefaultTypeProcessor();
final Model model = new Jackson2Parser(settings, typeProcessor).parseModel(ClassA.class);
final TsModel tsModel = new ModelCompiler(settings, typeProcessor).javaToTypeScript(model);
new BeanPropertyPathExtension().emitElements(writer, settings, false, tsModel);
String dataStr = data.toString();
final String expected = Utils.readString(getClass().getResourceAsStream("/ext/expected.ts"), "\n");
Assert.assertEquals(expected.trim(), dataStr.trim());
}
Aggregations