docs-util: fix how data model name is inferred (#8351)

This commit is contained in:
Shahed Nasser
2024-07-30 18:59:29 +03:00
committed by GitHub
parent 6fabb7fad2
commit d4c9c1e7cd
3 changed files with 19 additions and 3 deletions

View File

@@ -61,7 +61,7 @@ class DmlGenerator extends AbstractGenerator {
)
this.generatorEventManager.emit(GeneratorEvent.FINISHED_GENERATE_EVENT)
console.log(`[OAS] Finished generating OAS for ${file.fileName}.`)
console.log(`[DML] Finished generating OAS for ${file.fileName}.`)
})
)
}

View File

@@ -3,7 +3,13 @@ import DefaultKindGenerator, { GetDocBlockOptions } from "./default.js"
import getBasePath from "../../utils/get-base-path.js"
import { getDmlOutputBasePath } from "../../utils/get-output-base-paths.js"
import path from "path"
import { camelToWords, RELATION_NAMES, snakeToPascal } from "utils"
import {
camelToWords,
RELATION_NAMES,
snakeToPascal,
camelToPascal,
isSnakeCase,
} from "utils"
import toJsonFormatted from "../../utils/to-json-formatted.js"
import { DmlFile, DmlObject } from "types"
@@ -186,7 +192,9 @@ class DmlKindGenerator extends DefaultKindGenerator<ts.CallExpression> {
}
}
return snakeToPascal(name.replace(/^"/, "").replace(/"$/, ""))
name = name.replace(/^"/, "").replace(/"$/, "")
return isSnakeCase(name) ? snakeToPascal(name) : camelToPascal(name)
}
/**

View File

@@ -28,6 +28,10 @@ export function camelToTitle(str: string): string {
.trim()
}
export function camelToPascal(str: string): string {
return `${str.charAt(0).toUpperCase()}${str.substring(1)}`
}
export function snakeToWords(str: string): string {
return str.replaceAll("_", " ").toLowerCase()
}
@@ -39,6 +43,10 @@ export function snakeToPascal(str: string): string {
.join("")
}
export function isSnakeCase(str: string): boolean {
return /[a-z]+_[a-z]+/g.test(str)
}
export function kebabToTitle(str: string): string {
return str
.split("-")