docs-util: throw when schema parsing fails (#12846)

This commit is contained in:
Shahed Nasser
2025-06-27 12:52:30 +03:00
committed by GitHub
parent fcfd35a157
commit a23bbc1cbb
3 changed files with 29 additions and 10 deletions

View File

@@ -35,8 +35,18 @@
* - gte * - gte
* - nin * - nin
* value: * value:
* type: string * oneOf:
* title: value * - type: string
* title: value
* description: The shipping option rule's value.
* example: "true"
* - type: array
* description: The shipping option rule's values.
* items:
* type: string
* title: value
* description: A value of the shipping option rule.
* example: "true"
* shipping_option_id: * shipping_option_id:
* type: string * type: string
* title: shipping_option_id * title: shipping_option_id
@@ -56,5 +66,6 @@
* format: date-time * format: date-time
* title: deleted_at * title: deleted_at
* description: The date the shipping option rule was deleted. * description: The date the shipping option rule was deleted.
* *
*/ */

View File

@@ -147,5 +147,6 @@
* type: number * type: number
* title: startedAt * title: startedAt
* description: The timestamp the step started executing. * description: The timestamp the step started executing.
* *
*/ */

View File

@@ -9,6 +9,7 @@ import { parse } from "yaml"
import formatOas from "../../utils/format-oas.js" import formatOas from "../../utils/format-oas.js"
import pluralize from "pluralize" import pluralize from "pluralize"
import { capitalize, wordsToPascal } from "utils" import { capitalize, wordsToPascal } from "utils"
import chalk from "chalk"
import { OasArea } from "../kinds/oas.js" import { OasArea } from "../kinds/oas.js"
import { import {
isLevelExceeded, isLevelExceeded,
@@ -307,7 +308,7 @@ class OasSchemaHelper {
return return
} }
return this.parseSchema(schemaFileContent) return this.parseSchema(schemaFileContent, true)
} }
/** /**
@@ -316,7 +317,10 @@ class OasSchemaHelper {
* @param content - The schema comment string * @param content - The schema comment string
* @returns If the schema is valid and parsed successfully, the schema and its prefix are retrieved. * @returns If the schema is valid and parsed successfully, the schema and its prefix are retrieved.
*/ */
parseSchema(content: string): ParsedSchema | undefined { parseSchema(
content: string,
failOnParseError = false
): ParsedSchema | undefined {
const schemaFileContent = content const schemaFileContent = content
.replace(`/**\n`, "") .replace(`/**\n`, "")
.replaceAll(DOCBLOCK_LINE_ASTRIX, "") .replaceAll(DOCBLOCK_LINE_ASTRIX, "")
@@ -334,8 +338,11 @@ class OasSchemaHelper {
try { try {
schema = parse(splitContent.slice(1).join("\n")) schema = parse(splitContent.slice(1).join("\n"))
} catch (e) { } catch (e) {
// couldn't parse the OAS, so consider it if (failOnParseError) {
// not existent throw e
}
console.error(chalk.red(e))
} }
return schema return schema