Synergex / HarmonyCore

Harmony Core is a framework that consists of libraries, CodeGen templates, and conventions that enable you to expose Synergy logic and data as a RESTful web service using OData and ASP.NET Core
BSD 2-Clause "Simplified" License
23 stars 14 forks source link

TypeScriptInterfaceMethods.tpl generating non-matching camel case structure references in method interfaces. #321

Open tscaff opened 1 year ago

tscaff commented 1 year ago

When generating TypeScript templates in Harmony Core, it looks like the camel casing for the structure names in the methods template are incorrect and do not match the casing of the Structures being generated.

Is there a different token than that will provide the correct casing of the structure name?

Example: Note the casing on the weblibStructures.abaFile reference which does not match the casing of the structure in the Structures.ts generated by the codegen tool.

import * as weblibStructures from './Structures';

// ------------------------------------------------------------------------------ // Operation: ABALookup

export interface ABALookupRequest { connectionString: string; abaFileRecord: weblibStructures.abaFile; lookupType: string; abaCount: number; }

Stucture: ABA_FILE Description: ABA Bank Index File / export interface AbaFile { AbaNumber: number; / Size: 9, Description: ABA Bank Number / AbaName: string; / Size: 36, Description: ABA Bank Name / AbaShortname: string; / Size: 18, Description: ABA Bank Shortname / AbaAddress: string; / Size: 36, Description: ABA Bank Address / AbaState: string; / Size: 2, Description: ABA Bank State / AbaCity: string; / Size: 25, Description: ABA Bank City / AbaZip: number; / Size: 9, Description: ABA Bank Zip Code / AbaPhone: number; / Size: 10, Description: ABA Bank Telephone / AbaAllowach: string; / Size: 1, Description: Allow ACH Transactions to this Bank / AbaWirefunds: string; / Size: 1, Description: Allow Wires to this Bank / AbaFiller: string; / Size: 53, Description: Additional space for future growth */ }

SteveIves commented 1 year ago

Hey, Tom. Before I spend too much time on this, can you check something out for me. This is a "delicate" area, as we have had different customers wanting different behaviors, and I want to avoid fixing something specifically for you and in the process breaking it for someone else.

Generally, when processing with the method catalog, names are maintained from exactly how they appear in the method catalog, which has case-sensitive names. There are a couple of CodeGen "tweaks" which allow you to morph these interface, method and parameter names into camelCase or PascalCase, when using the UPPER case replacement tokensm like , and .

The tweaks are SMC_CAMEL_CASE and SMC_PASCAL_CASE. You would use one of them via the -tweaks command line option, for example -tweaks SMC_CAMEL_CASE.

Tweaks are documented here: https://codegen.synergex.com/topics/tweaks.htm

Can you try these out and see if one of them addresses your issue?

tscaff commented 1 year ago

Hi Steve.

I will test that out. Thank you for the references to the tweaks...I was trying to figure those out from within the HC project and couldn't find how those were handled....I failed to be look inside the CodeGen project...probably why I missed the documentation on it.

So while I was waiting, I actually modified the TyperScript templates to make it do what we wanted. I have attached those for review. I noticed the Non-Tweaked version didn't really match up the casing like I thought it would and it also applied pluralization where I didn't expect it to, causing some undefined references.

The attach file has the template modifications that get's us all the way to the finish in our Angular implementation.

I will test out the Tweak modifications and see how those work and post feedback to this question. Thanks again. TypeScript.zip

tscaff commented 1 year ago

@hippiehunter how would I implement those tweaks in the harmonycore gui? (I only found reference to those in regen.bat when I searched for it.)

hippiehunter commented 1 year ago

I think these typescript files are being generated by your csx script file. I think there is a task coming from InterfaceTaskHelper. CodeGenTask has a ObservableCollection member on it for Tweaks

https://github.com/Synergex/CodeGen/blob/ce3231ac799427458a4f925de7d7fbf50d66bba5/CodeGenEngine/CodeGenTask.dbl#L463

The Tweaks Steve is referencing above can just be added to that Collection on the CodeGenTask being created in your csx file.

tscaff commented 1 year ago

Thanks Jeff. I will see about doing a run through on those and see if that address the casing issues I was seeing.

hippiehunter commented 1 year ago

@tscaff did this solve your problem?

tscaff commented 1 year ago

@hippiehunter I did a few tests using the tweak options and it doesn't quite hit the mark in the manner I was hoping. It seems to tweak the value opposite of what they should be. I have to use my original template modifications I posted earlier to make it work.

Example: If I set SMC_PASCAL_CASE on both the structures and methods and client code, it seems to camel case the structure names and shows as undefine, such as in this case where abaFile is camel cased, but it's value in structures is pascal cased. When I set SMC_CAMEL_CASE it seems to do the opposite problem. And this is with using the existing templates so I guess I don't see how these could be working for folks.

import * as WeblibStructures from '../interfaces/Structures';

export interface AbalookupRequest { Connectionstring: string; Abafilerecord: WeblibStructures.abaFile; Lookuptype: string; Abacount: number; }

*

Stucture: ABA_FILE Description: ABA Bank Index File */ export interface AbaFile { AbaNumber: number; AbaName: string; AbaShortname: string; AbaAddress: string; AbaState: string; AbaCity: string; AbaZip: number; AbaPhone: number; AbaAllowach: string; AbaWirefunds: string; AbaFiller: string; }

Maybe I am doing these wrong? I have attached the templats and files for review. TypeScript.zip TraditionalBridgeGenerator.zip

hippiehunter commented 1 year ago

I poked around in the tpl files and checked with steve, the tweaks stuff is only supposed to apply to all caps tokens. As an example from one of the tpl files

public <methodName>(arg: <interfaceName>Methods.<methodName>Request): Observable<<interfaceName>Methods.<methodName>Response>

those tokens will give you camel case and should be ignoring tweaks settings.

public <METHOD_NAME>(arg: <INTERFACE_NAME>Methods.<METHOD_NAME>Request): Observable<<INTERFACE_NAME>Methods.<METHOD_NAME>Response>

These tokens will give you exact case (whatever was specified in the SMC) but will respond to tweaks settings. You can either change the tokens to all caps and set the tweaks or just adjust the casing in the tokens to the type you're looking for.

hippiehunter commented 1 year ago

@tscaff do you have a working solution to this problem?

tscaff commented 1 year ago

Hi @hippiehunter I just got back to looking at this. I don't have a solution to this problem yet. I may need some help working this one out.