Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions compiler/model/metamodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ export abstract class BaseType {
kind: string
/** Variant name for externally tagged variants */
variantName?: string
/**
* Additional identifiers for use by code generators. Usage depends on the actual type:
* - on unions (modeled as alias(union_of)), these are identifiers for the union members
* - for additional properties, this is the name of the dict that holds these properties
* - for additional property, this is the name of the key and value fields that hold the
* additional property
*/
codegenNames?: string[]
}

export type Variants = ExternalTag | InternalTag | Container
Expand Down
8 changes: 7 additions & 1 deletion compiler/model/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ export function hoistTypeAnnotations (type: model.TypeDefinition, jsDocs: JSDoc[
// We want to enforce a single jsDoc block.
assert(jsDocs, jsDocs.length < 2, 'Use a single multiline jsDoc block instead of multiple single line blocks')

const validTags = ['class_serializer', 'doc_url', 'behavior', 'variants', 'variant', 'shortcut_property']
const validTags = ['class_serializer', 'doc_url', 'behavior', 'variants', 'variant', 'shortcut_property', 'codegen_names']
const tags = parseJsDocTags(jsDocs)
if (jsDocs.length === 1) {
const description = jsDocs[0].getDescription()
Expand All @@ -648,6 +648,12 @@ export function hoistTypeAnnotations (type: model.TypeDefinition, jsDocs: JSDoc[
} else if (tag === 'doc_url') {
assert(jsDocs, isValidUrl(value), '@doc_url is not a valid url')
type.docUrl = value
} else if (tag === 'codegen_names') {
type.codegenNames = value.split(',').map(v => v.trim())
assert(jsDocs,
type.kind === 'type_alias' && type.type.kind === 'union_of' && type.type.items.length === type.codegenNames.length,
'@codegen_names must have the number of items as the union definition'
)
} else {
assert(jsDocs, false, `Unhandled tag: '${tag}' with value: '${value}' on type ${type.name.name}`)
}
Expand Down
Loading