Skip to content

Commit

Permalink
fix: fix singleton update requires id
Browse files Browse the repository at this point in the history
  • Loading branch information
pviti committed Dec 19, 2024
1 parent 2401996 commit 4eccc03
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 61 deletions.
12 changes: 8 additions & 4 deletions gen/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,9 +740,10 @@ const generateResource = (type: string, name: string, resource: Resource): strin

typesArray.forEach(t => {
const cudSuffix = getCUDSuffix(t)
resourceInterfaces.push(`Resource${cudSuffix}`)
const resIntf = ((singletonResource && (cudSuffix === 'Update'))? 'Singleton' : 'Resource') + cudSuffix
resourceInterfaces.push(resIntf)
const component: Component = resource.components[t]
const tplCmp = templatedComponent(resName, t, component)
const tplCmp = templatedComponent(resName, t, component, singletonResource)
tplCmp.models.forEach(m => {
if (m !== 'Resource') declaredImportsModels.add(m) // Fix resource_errors issue
})
Expand Down Expand Up @@ -904,7 +905,7 @@ const nullable = (type: string): string => {

type ComponentEnums = { [key: string]: string }

const templatedComponent = (res: string, name: string, cmp: Component): { component: string, models: string[], enums: ComponentEnums, nullables: boolean } => {
const templatedComponent = (res: string, name: string, cmp: Component, singleton?: boolean): { component: string, models: string[], enums: ComponentEnums, nullables: boolean } => {

const cudModel = isCUDModel(name)

Expand Down Expand Up @@ -973,7 +974,10 @@ const templatedComponent = (res: string, name: string, cmp: Component): { compon
let component = (fields.length || rels.length) ? templates.model : templates.model_empty

component = component.replace(/##__RESOURCE_MODEL__##/g, name)
component = component.replace(/##__EXTEND_TYPE__##/g, getCUDSuffix(name))

const cudSuffix = getCUDSuffix(name)
const extendType = ((singleton && cudModel && (cudSuffix === 'Update'))? 'Singleton' : 'Resource') + cudSuffix
component = component.replace(/##__EXTEND_TYPE__##/, extendType)

const fieldsStr = (fields.length ? '\n\t' : '') + fields.join('\n\t') + (fields.length && rels.length ? '\n' : '')
const relsStr = rels.join('\n\t') + (rels.length ? '\n' : '')
Expand Down
2 changes: 1 addition & 1 deletion gen/templates/model.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
interface ##__RESOURCE_MODEL__## extends Resource##__EXTEND_TYPE__## {
interface ##__RESOURCE_MODEL__## extends ##__EXTEND_TYPE__## {
##__RESOURCE_MODEL_FIELDS__##
##__RESOURCE_MODEL_RELATIONSHIPS__##
}
Loading

0 comments on commit 4eccc03

Please sign in to comment.