chore(oas): clean up oas (#9354)
* clean up generated oas * fix issues in docs-util * more fixes * align max level * validation fix * add missing summaries * fix validation * fix exchanges route
This commit is contained in:
@@ -31,7 +31,7 @@ class OasSchemaHelper {
|
||||
private schemas: Map<string, OpenApiSchema>
|
||||
protected schemaRefPrefix = "#/components/schemas/"
|
||||
protected formatter: Formatter
|
||||
private MAX_LEVEL = 5
|
||||
private MAX_LEVEL = 7
|
||||
/**
|
||||
* The path to the directory holding the base YAML files.
|
||||
*/
|
||||
@@ -356,7 +356,10 @@ class OasSchemaHelper {
|
||||
return name
|
||||
.replace("DTO", "")
|
||||
.replace(this.schemaRefPrefix, "")
|
||||
.replace(/(?<!(AdminProduct|CreateProduct))Type$/, "")
|
||||
.replace(
|
||||
/(?<!(AdminProduct|CreateProduct|StoreShippingOption|AdminShippingOption))Type$/,
|
||||
""
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,34 +37,6 @@ class SchemaFactory {
|
||||
BigNumberValue: {
|
||||
type: "number",
|
||||
},
|
||||
expand: {
|
||||
type: "string",
|
||||
title: "expand",
|
||||
description:
|
||||
"Comma-separated relations that should be expanded in the returned data.",
|
||||
},
|
||||
fields: {
|
||||
type: "string",
|
||||
title: "fields",
|
||||
description:
|
||||
"Comma-separated fields that should be included in the returned data. if a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields. without prefix it will replace the entire default fields.",
|
||||
},
|
||||
offset: {
|
||||
type: "number",
|
||||
title: "offset",
|
||||
description: "The number of items to skip when retrieving a list.",
|
||||
},
|
||||
limit: {
|
||||
type: "number",
|
||||
title: "limit",
|
||||
description: "Limit the number of items returned in the list.",
|
||||
},
|
||||
order: {
|
||||
type: "string",
|
||||
title: "order",
|
||||
description:
|
||||
"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.",
|
||||
},
|
||||
File: {
|
||||
type: "object",
|
||||
description: "A File to upload.",
|
||||
@@ -86,6 +58,41 @@ class SchemaFactory {
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Schemas used only for query types
|
||||
*/
|
||||
private schemasForQuery: Record<string, OpenApiSchema> = {
|
||||
expand: {
|
||||
type: "string",
|
||||
title: "expand",
|
||||
description:
|
||||
"Comma-separated relations that should be expanded in the returned data.",
|
||||
},
|
||||
fields: {
|
||||
type: "string",
|
||||
title: "fields",
|
||||
description:
|
||||
"Comma-separated fields that should be included in the returned data. If a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields. Without prefix it will replace the entire default fields.",
|
||||
},
|
||||
offset: {
|
||||
type: "number",
|
||||
title: "offset",
|
||||
description: "The number of items to skip when retrieving a list.",
|
||||
},
|
||||
limit: {
|
||||
type: "number",
|
||||
title: "limit",
|
||||
description: "Limit the number of items returned in the list.",
|
||||
},
|
||||
order: {
|
||||
type: "string",
|
||||
title: "order",
|
||||
description:
|
||||
"The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.",
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Schemas used only for response types.
|
||||
*/
|
||||
@@ -119,7 +126,9 @@ class SchemaFactory {
|
||||
const schemasFactory =
|
||||
type === "response"
|
||||
? this.mergeSchemas(this.schemasForResponse, this.schemas)
|
||||
: this.cloneSchema(this.schemas)
|
||||
: type === "query"
|
||||
? this.mergeSchemas(this.schemasForQuery, this.schemas)
|
||||
: this.cloneSchema(this.schemas)
|
||||
const key = Object.hasOwn(schemasFactory, name)
|
||||
? name
|
||||
: additionalData?.title || ""
|
||||
|
||||
@@ -1391,31 +1391,33 @@ class OasKindGenerator extends FunctionKindGenerator {
|
||||
case itemType.isUnion():
|
||||
// if it's a union of literal types,
|
||||
// consider it an enum
|
||||
const allLiteral = (itemType as ts.UnionType).types.every((unionType) =>
|
||||
const cleanedUpTypes = this.typesHelper.cleanUpTypes(
|
||||
(itemType as ts.UnionType).types
|
||||
)
|
||||
const allLiteral = cleanedUpTypes.every((unionType) =>
|
||||
unionType.isLiteral()
|
||||
)
|
||||
|
||||
if (allLiteral) {
|
||||
return {
|
||||
type: "string",
|
||||
description,
|
||||
enum: (itemType as ts.UnionType).types.map(
|
||||
enum: cleanedUpTypes.map(
|
||||
(unionType) => (unionType as ts.LiteralType).value
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
const oneOfItems = this.typesHelper
|
||||
.cleanUpTypes((itemType as ts.UnionType).types)
|
||||
.map((unionType) =>
|
||||
this.typeToSchema({
|
||||
itemType: unionType,
|
||||
level: maybeIncrementLevel(level, "oneOf"),
|
||||
title,
|
||||
descriptionOptions,
|
||||
saveSchema,
|
||||
...rest,
|
||||
})
|
||||
)
|
||||
const oneOfItems = cleanedUpTypes.map((unionType) =>
|
||||
this.typeToSchema({
|
||||
itemType: unionType,
|
||||
level: maybeIncrementLevel(level, "oneOf"),
|
||||
title,
|
||||
descriptionOptions,
|
||||
saveSchema,
|
||||
...rest,
|
||||
})
|
||||
)
|
||||
|
||||
if (oneOfItems.length === 1) {
|
||||
return oneOfItems[0]
|
||||
@@ -1967,7 +1969,7 @@ class OasKindGenerator extends FunctionKindGenerator {
|
||||
|
||||
if (!oldSchemaObj && newSchemaObj) {
|
||||
return newSchemaObj
|
||||
} else if (!newSchemaObj || !Object.keys(newSchemaObj)) {
|
||||
} else if (!newSchemaObj || !Object.keys(newSchemaObj).length) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user