fix(oas): support additional props, fix circular references patch, and other fixes (#9213)
* chore(oas): support additional props, fix circular references patch, and other fixes * fix description * description fixes
This commit is contained in:
@@ -69,9 +69,16 @@ class OasSchemaHelper {
|
||||
|
||||
// check if schema has child schemas
|
||||
// and convert those
|
||||
if (schema.properties) {
|
||||
Object.keys(schema.properties).forEach((property) => {
|
||||
const propertySchema = schema.properties![property]
|
||||
const properties = schema.properties
|
||||
? schema.properties
|
||||
: schema.additionalProperties &&
|
||||
typeof schema.additionalProperties !== "boolean" &&
|
||||
!this.isRefObject(schema.additionalProperties)
|
||||
? schema.additionalProperties.properties
|
||||
: undefined
|
||||
if (properties) {
|
||||
Object.keys(properties).forEach((property) => {
|
||||
const propertySchema = properties![property]
|
||||
if ("$ref" in propertySchema) {
|
||||
return
|
||||
}
|
||||
@@ -105,7 +112,7 @@ class OasSchemaHelper {
|
||||
})
|
||||
}
|
||||
|
||||
schema.properties![property] =
|
||||
properties![property] =
|
||||
this.namedSchemaToReference(
|
||||
propertySchema as OpenApiSchema,
|
||||
level + 1
|
||||
@@ -178,6 +185,28 @@ class OasSchemaHelper {
|
||||
this.namedSchemaToReference(transformedProperty) ||
|
||||
transformedProperty
|
||||
})
|
||||
} else if (
|
||||
clonedSchema.additionalProperties &&
|
||||
typeof clonedSchema.additionalProperties !== "boolean" &&
|
||||
!this.isRefObject(clonedSchema.additionalProperties) &&
|
||||
clonedSchema.additionalProperties.properties
|
||||
) {
|
||||
const additionalProps = schema.additionalProperties as OpenApiSchema
|
||||
Object.entries(clonedSchema.additionalProperties.properties).forEach(
|
||||
([key, property]) => {
|
||||
if (this.isRefObject(property)) {
|
||||
return
|
||||
}
|
||||
|
||||
const transformedProperty = this.schemaChildrenToRefs(
|
||||
property,
|
||||
level + 1
|
||||
)
|
||||
additionalProps.properties![key] =
|
||||
this.namedSchemaToReference(transformedProperty) ||
|
||||
transformedProperty
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
return clonedSchema
|
||||
@@ -186,10 +215,17 @@ class OasSchemaHelper {
|
||||
isSchemaEmpty(schema: OpenApiSchema): boolean {
|
||||
switch (schema.type) {
|
||||
case "object":
|
||||
return (
|
||||
const isPropertiesEmpty =
|
||||
schema.properties === undefined ||
|
||||
Object.keys(schema.properties).length === 0
|
||||
)
|
||||
const isAdditionalPropertiesEmpty =
|
||||
schema.additionalProperties === undefined ||
|
||||
typeof schema.additionalProperties === "boolean" ||
|
||||
(!this.isRefObject(schema.additionalProperties) &&
|
||||
(schema.additionalProperties.properties === undefined ||
|
||||
Object.keys(schema.additionalProperties.properties).length == 0))
|
||||
|
||||
return isPropertiesEmpty && isAdditionalPropertiesEmpty
|
||||
case "array":
|
||||
return (
|
||||
!this.isRefObject(schema.items) && this.isSchemaEmpty(schema.items)
|
||||
@@ -350,6 +386,7 @@ class OasSchemaHelper {
|
||||
| OpenApiSchema
|
||||
| OpenAPIV3.RequestBodyObject
|
||||
| OpenAPIV3.ResponseObject
|
||||
| OpenAPIV3.ParameterObject
|
||||
| undefined
|
||||
): schema is OpenAPIV3.ReferenceObject {
|
||||
return schema !== undefined && "$ref" in schema
|
||||
|
||||
Reference in New Issue
Block a user