docs-util: fix clean script removing Auth tags (#8911)

* docs-util: fix clean script removing Auth tags

* fix removal of response types other than json
This commit is contained in:
Shahed Nasser
2024-08-30 17:02:02 +03:00
committed by GitHub
parent b9eac4402b
commit dea5af085a
3 changed files with 34 additions and 4 deletions

View File

@@ -76,7 +76,11 @@ class SchemaFactory {
let schema = Object.assign({}, schemasFactory[key])
if (additionalData) {
schema = Object.assign(schema, additionalData)
schema = Object.assign(schema, {
...additionalData,
// keep the description
description: schema.description || additionalData.description
})
}
return schema

View File

@@ -506,8 +506,11 @@ class OasKindGenerator extends FunctionKindGenerator {
}
updatedResponseSchema = newResponseSchema
} else if (oas.responses && !newResponseSchema) {
// remove response schema by only keeping the default responses
oas.responses = DEFAULT_OAS_RESPONSES
// check if it has a success response of a type other than JSON
if (!this.hasResponseType(node, oas)) {
// remove response schema by only keeping the default responses
oas.responses = DEFAULT_OAS_RESPONSES
}
} else {
// check if response status should be changed
const oldResponseStatus = Object.keys(oas.responses!).find(
@@ -2070,6 +2073,24 @@ class OasKindGenerator extends FunctionKindGenerator {
)
}
hasResponseType(node: FunctionNode, oas: OpenApiOperation): boolean {
const oldResponseStatus = Object.keys(oas.responses!).find(
(status) => !Object.keys(DEFAULT_OAS_RESPONSES).includes(status)
)
if (!oldResponseStatus) {
return false
}
const responseContent = (oas.responses![oldResponseStatus] as OpenAPIV3.ResponseObject).content
if (!responseContent) {
return false
}
const fnText = node.getText()
return Object.keys(responseContent).some((responseType) => fnText.includes(responseType))
}
private removeStringRegExpTypeOverlaps(types: ts.Type[]): ts.Type[] {
return types.filter((itemType) => {
// remove overlapping string / regexp types

View File

@@ -26,6 +26,11 @@ const ignoreSchemas = [
"AuthStoreSessionResponse",
]
const ignoreTags = {
admin: ["Auth"],
store: ["Auth"]
}
export default async function () {
const oasOutputBasePath = getOasOutputBasePath()
const oasOperationsPath = path.join(oasOutputBasePath, "operations")
@@ -225,7 +230,7 @@ export default async function () {
const lengthBefore = parsedBaseYaml.tags?.length || 0
parsedBaseYaml.tags = parsedBaseYaml.tags?.filter((tag) =>
areaTags.has(tag.name)
areaTags.has(tag.name) || ignoreTags[area].includes(tag.name)
)
if (lengthBefore !== (parsedBaseYaml.tags?.length || 0)) {