The minProperties constraint defined in JSON schemas is currently ignored during the SDK generation process.
Example
In description.json (see description.json), we have:
{
"properties": {
"plain": { "type": "string" },
"html": { "type": "string" },
"markdown": { "type": "string" }
},
"minProperties": 1
}
This is intended to ensure that at least one of plain, html, or markdown is provided.
However, the generated Pydantic model Description in ucp_sdk/models/schemas/shopping/types/description.py defines all these fields as optional and does not enforce that at least one is present:
class Description(BaseModel):
model_config = ConfigDict(extra="allow")
plain: str | None = None
html: str | None = None
markdown: str | None = None
Instantiating Description() with no fields passes validation, which violates the schema constraint.
Proposed Solution
We need to handle minProperties (and potentially maxProperties) in preprocess_schemas.py or via post-processing of the generated models.
One option is to translate minProperties into an anyOf structure that datamodel-code-generator can interpret, or post-process the generated files to inject a Pydantic model_validator (mode='after') to enforce the property count.
The
minPropertiesconstraint defined in JSON schemas is currently ignored during the SDK generation process.Example
In
description.json(see description.json), we have:{ "properties": { "plain": { "type": "string" }, "html": { "type": "string" }, "markdown": { "type": "string" } }, "minProperties": 1 }This is intended to ensure that at least one of
plain,html, ormarkdownis provided.However, the generated Pydantic model
Descriptioninucp_sdk/models/schemas/shopping/types/description.pydefines all these fields as optional and does not enforce that at least one is present:Instantiating
Description()with no fields passes validation, which violates the schema constraint.Proposed Solution
We need to handle
minProperties(and potentiallymaxProperties) inpreprocess_schemas.pyor via post-processing of the generated models.One option is to translate
minPropertiesinto ananyOfstructure thatdatamodel-code-generatorcan interpret, or post-process the generated files to inject a Pydanticmodel_validator(mode='after') to enforce the property count.