forked from phoenix-oss/llama-stack-mirror
Update discriminator to have the correct mapping
(#881)
See https://swagger.io/docs/specification/v3_0/data-models/inheritance-and-polymorphism/#discriminator When specifying discriminators, mapping must be specified unless the value of the discriminator is the subtype itself (which in our case is not.) The changes in the YAML are self-explanatory.
This commit is contained in:
parent
a6d20e0f53
commit
e5936a8df8
10 changed files with 642 additions and 420 deletions
|
@ -122,10 +122,16 @@ class JsonSchemaAnyOf(JsonSchemaNode):
|
|||
anyOf: List["JsonSchemaAny"]
|
||||
|
||||
|
||||
@dataclass
|
||||
class Discriminator:
|
||||
propertyName: str
|
||||
mapping: Dict[str, str]
|
||||
|
||||
|
||||
@dataclass
|
||||
class JsonSchemaOneOf(JsonSchemaNode):
|
||||
oneOf: List["JsonSchemaAny"]
|
||||
discriminator: Optional[str]
|
||||
discriminator: Optional[Discriminator]
|
||||
|
||||
|
||||
JsonSchemaAny = Union[
|
||||
|
|
|
@ -456,8 +456,19 @@ class JsonSchemaGenerator:
|
|||
]
|
||||
}
|
||||
if discriminator:
|
||||
# for each union type, we need to read the value of the discriminator
|
||||
mapping = {}
|
||||
for union_type in typing.get_args(typ):
|
||||
props = self.type_to_schema(union_type, force_expand=True)[
|
||||
"properties"
|
||||
]
|
||||
mapping[props[discriminator]["default"]] = self.type_to_schema(
|
||||
union_type
|
||||
)["$ref"]
|
||||
|
||||
ret["discriminator"] = {
|
||||
"propertyName": discriminator,
|
||||
"mapping": mapping,
|
||||
}
|
||||
return ret
|
||||
elif origin_type is Literal:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue