docs-util: fix how data model name is inferred (#8351)
This commit is contained in:
@@ -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}.`)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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("-")
|
||||
|
||||
Reference in New Issue
Block a user