Skip to content

Visitors rework, anyOf allOf oneOf support#23

Draft
Toru8P wants to merge 34 commits intodevfrom
visitor_rework
Draft

Visitors rework, anyOf allOf oneOf support#23
Toru8P wants to merge 34 commits intodevfrom
visitor_rework

Conversation

@Toru8P
Copy link

@Toru8P Toru8P commented May 23, 2022

No description provided.

@Toru8P Toru8P self-assigned this May 23, 2022
Nikita Shaposhnikov added 6 commits May 24, 2022 13:28
…an one valid - will be chosen one with unique fields contained

refactored some method of visitors, moved to abstract realization

removed objectSchema from composed choice, objects can be as Schema<*> as valid one
@Toru8P Toru8P requested a review from cordwelt May 25, 2022 16:05
@Toru8P Toru8P requested a review from isengrims May 25, 2022 16:05
@Toru8P Toru8P requested review from OptimumCode and cordwelt May 27, 2022 09:47
})
this.putProperties(METHOD_FIELD, container.method)
}
else -> error("Wrong type of Http Route Container")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You won't need it if you'll make HttpRouteContainer a sealed class

is ResponseContainer -> this.putProperties(CODE_FIELD, container.code)
is RequestContainer -> {
this.putProperties(URI_FIELD, if (container.params.isNotEmpty()) {
container.uriPattern.resolve(container.params, message.getMessage(URI_PARAMS_FIELD).orEmpty().fieldsMap.mapValues { it.value.simpleValue })

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

message.getMessage(URI_PARAMS_FIELD).orEmpty().fieldsMap.mapValues { it.value.simpleValue }

Extract into utility function?

Comment on lines +340 to +345
headerMessage[name]?.let { header ->
headers.add(message().apply {
addField("name", name)
addField("value", header.simpleValue)
})
} ?: run { if (value.required) error("Header param [$name] is required for ${message.messageType} message") }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
headerMessage[name]?.let { header ->
headers.add(message().apply {
addField("name", name)
addField("value", header.simpleValue)
})
} ?: run { if (value.required) error("Header param [$name] is required for ${message.messageType} message") }
headerMessage[name]?.let { header ->
headers += message().apply {
this["name"] = name
this["value"] = header.simpleValue
}
} ?: check(!value.required) {
"Header param [$name] is required for ${message.messageType} message"
}

Comment on lines +71 to +72
getFieldNames()
schemas.find { schema ->

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
getFieldNames()
schemas.find { schema ->
getFieldNames().schemas.find { schema ->

SchemaWriter(settings.openAPI).traverse(visitor, itemSchema, throwUndefined)
visitor.rootMessage.build().run(this::add)
}
else -> rootMessage[fieldName] = arrayNode.map {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else -> rootMessage[fieldName] = arrayNode.map {
else -> rootMessage[fieldName] = arrayNode.asSequence().map {

visitor.rootMessage
}
})
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}.iterator()

is PasswordSchema, is EmailSchema, is BinarySchema, is ByteArraySchema, is FileSchema, is MapSchema, is UUIDSchema -> throw UnsupportedOperationException("${property::class.simpleName} isn't supported for now")
else -> visitor.visit(name, property, msgStructure.requiredContains(name), checkForUndefinedFields)
}
} ?: error("Schema ${it.name}:${it.type} have no properties to process")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should validate schema during start up if it is not valid state for schema. But if it is a valid state we should not throw an exception

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants