docs-util: fix update OAS schema (#8556)
* docs-util: fix update OAS schema * fix to updating * fix condition
This commit is contained in:
@@ -518,6 +518,11 @@ class KnowledgeBaseFactory {
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
private oasDescriptionKnowledgeBase: KnowledgeBase[] = [
|
private oasDescriptionKnowledgeBase: KnowledgeBase[] = [
|
||||||
|
{
|
||||||
|
exact: "additional_data",
|
||||||
|
template:
|
||||||
|
"Pass additional custom data to the API route. This data is passed to the underlying workflow under the `additional_data` parameter.",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
pattern: /.*/,
|
pattern: /.*/,
|
||||||
template(str, options) {
|
template(str, options) {
|
||||||
|
|||||||
@@ -1739,7 +1739,7 @@ class OasKindGenerator extends FunctionKindGenerator {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const oldSchemaObj = (
|
let oldSchemaObj = (
|
||||||
oldSchema && "$ref" in oldSchema
|
oldSchema && "$ref" in oldSchema
|
||||||
? this.oasSchemaHelper.getSchemaByName(oldSchema.$ref)?.schema
|
? this.oasSchemaHelper.getSchemaByName(oldSchema.$ref)?.schema
|
||||||
: oldSchema
|
: oldSchema
|
||||||
@@ -1756,23 +1756,33 @@ class OasKindGenerator extends FunctionKindGenerator {
|
|||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
// update schema
|
const oldSchemaType = this.inferOasSchemaType(oldSchemaObj)
|
||||||
if (oldSchemaObj!.type !== newSchemaObj?.type) {
|
const newSchemaType = this.inferOasSchemaType(newSchemaObj)
|
||||||
oldSchemaObj!.type = newSchemaObj?.type
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (oldSchemaType !== newSchemaType && newSchemaType && newSchemaObj) {
|
||||||
oldSchemaObj!.description !== newSchemaObj?.description &&
|
oldSchemaObj = {
|
||||||
oldSchemaObj!.description === SUMMARY_PLACEHOLDER
|
...newSchemaObj,
|
||||||
|
description: oldSchemaObj?.description,
|
||||||
|
}
|
||||||
|
} else if (
|
||||||
|
oldSchemaObj?.allOf &&
|
||||||
|
newSchemaObj.allOf &&
|
||||||
|
oldSchemaObj.allOf.length !== newSchemaObj.allOf.length
|
||||||
) {
|
) {
|
||||||
oldSchemaObj!.description =
|
oldSchemaObj.allOf = newSchemaObj.allOf
|
||||||
newSchemaObj?.description || SUMMARY_PLACEHOLDER
|
} else if (
|
||||||
}
|
oldSchemaObj?.oneOf &&
|
||||||
|
newSchemaObj.oneOf &&
|
||||||
oldSchemaObj!.required = newSchemaObj?.required
|
oldSchemaObj.oneOf.length !== newSchemaObj.oneOf.length
|
||||||
oldSchemaObj!["x-schemaName"] = newSchemaObj?.["x-schemaName"]
|
) {
|
||||||
|
oldSchemaObj.oneOf = newSchemaObj.oneOf
|
||||||
if (oldSchemaObj!.type === "object") {
|
} else if (
|
||||||
|
oldSchemaObj?.anyOf &&
|
||||||
|
newSchemaObj.anyOf &&
|
||||||
|
oldSchemaObj.anyOf.length !== newSchemaObj.anyOf.length
|
||||||
|
) {
|
||||||
|
oldSchemaObj.anyOf = newSchemaObj.anyOf
|
||||||
|
} else if (oldSchemaType === "object") {
|
||||||
if (!oldSchemaObj?.properties && newSchemaObj?.properties) {
|
if (!oldSchemaObj?.properties && newSchemaObj?.properties) {
|
||||||
oldSchemaObj!.properties = newSchemaObj.properties
|
oldSchemaObj!.properties = newSchemaObj.properties
|
||||||
} else if (!newSchemaObj?.properties) {
|
} else if (!newSchemaObj?.properties) {
|
||||||
@@ -1823,9 +1833,46 @@ class OasKindGenerator extends FunctionKindGenerator {
|
|||||||
}) || oldSchemaObj.items
|
}) || oldSchemaObj.items
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update schema
|
||||||
|
|
||||||
|
if (
|
||||||
|
oldSchemaObj!.description !== newSchemaObj?.description &&
|
||||||
|
oldSchemaObj!.description === SUMMARY_PLACEHOLDER
|
||||||
|
) {
|
||||||
|
oldSchemaObj!.description =
|
||||||
|
newSchemaObj?.description || SUMMARY_PLACEHOLDER
|
||||||
|
}
|
||||||
|
|
||||||
|
oldSchemaObj!.required = newSchemaObj?.required
|
||||||
|
oldSchemaObj!["x-schemaName"] = newSchemaObj?.["x-schemaName"]
|
||||||
|
|
||||||
return oldSchemaObj
|
return oldSchemaObj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method infers a schema's type.
|
||||||
|
*
|
||||||
|
* @param schema - The schema to infer its type
|
||||||
|
* @returns The type, if available.
|
||||||
|
*/
|
||||||
|
inferOasSchemaType(schema?: OpenApiSchema): string | undefined {
|
||||||
|
switch (true) {
|
||||||
|
case schema === undefined:
|
||||||
|
return undefined
|
||||||
|
case schema?.allOf !== undefined:
|
||||||
|
return "allOf"
|
||||||
|
case schema?.anyOf !== undefined:
|
||||||
|
return "anyOf"
|
||||||
|
case schema?.oneOf !== undefined:
|
||||||
|
return "oneOf"
|
||||||
|
case schema?.type !== undefined:
|
||||||
|
return schema.type
|
||||||
|
case schema !== undefined:
|
||||||
|
default:
|
||||||
|
return "object"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method retrieves the workflow used in an API route.
|
* This method retrieves the workflow used in an API route.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user