Skip to content

Add typeName parameter to TypeScript TypeMapper#38

Open
EllaSedova wants to merge 1 commit into
vmkteam:masterfrom
EllaSedova:master
Open

Add typeName parameter to TypeScript TypeMapper#38
EllaSedova wants to merge 1 commit into
vmkteam:masterfrom
EllaSedova:master

Conversation

@EllaSedova
Copy link
Copy Markdown

Problem

The TypeMapper hook currently receives only the JSON Schema definition and the converted TypeScript type. This is enough to map fields by name, but there is no way to know which interface the field belongs to.

In practice this is a problem when different RPC methods have parameters with the same field name but different semantics. Without the parent type name the mapper cannot distinguish between them and is forced to use the same union for all.

Changes

  • Added typeName string as the first parameter of the TypeMapper function type. It contains the name of the TypeScript interface being generated, or an empty string for top-level return types.
  • Passed typeName through convertTSType and addTSComplexInterface.
  • Replaced inline func(in smd.JSONSchema, tsType Type) Type with TypeMapper alias in addTSComplexInterface signature for consistency.

Breaking change

The signature of TypeMapper has changed. Migration requires adding one parameter:

// before                                                                                                                                                                     
func(in smd.JSONSchema, tsType typescript.Type) typescript.Type
                                                                                                                                                                                
// after
func(typeName string, in smd.JSONSchema, tsType typescript.Type) typescript.Type 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant