-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Open-API: Refactor TableRequirements (#7710)
* Open-API: Refactor TableRequirements I believe the constraints are not defined in the right way. After generating code I got: ```python class TableRequirement(BaseModel): type: Literal[ 'assert-create', 'assert-table-uuid', 'assert-ref-snapshot-id', 'assert-last-assigned-field-id', 'assert-current-schema-id', 'assert-last-assigned-partition-id', 'assert-default-spec-id', 'assert-default-sort-order-id', ] ref: Optional[str] = None uuid: Optional[str] = None snapshot_id: Optional[int] = Field(None, alias='snapshot-id') last_assigned_field_id: Optional[int] = Field(None, alias='last-assigned-field-id') current_schema_id: Optional[int] = Field(None, alias='current-schema-id') last_assigned_partition_id: Optional[int] = Field( None, alias='last-assigned-partition-id' ) default_spec_id: Optional[int] = Field(None, alias='default-spec-id') default_sort_order_id: Optional[int] = Field(None, alias='default-sort-order-id') ``` Which encapulates all the requirements. After the refactor in this PR, we'll end up with: ```python class AssertCreate(BaseModel): type: Literal['assert-create'] class AssertTableUUID(BaseModel): type: Literal['assert-table-uuid'] uuid: str class AssertRefSnapshotId(BaseModel): type: Literal['assert-ref-snapshot-id'] ref: str snapshot_id: int = Field(..., alias='snapshot-id') class AssertLastAssignedFieldId(BaseModel): type: Literal['assert-last-assigned-field-id'] last_assigned_partition_id: int = Field(..., alias='last-assigned-partition-id') class AssertCurrentSchemaId(BaseModel): type: Literal['assert-current-schema-id'] current_schema_id: int = Field(..., alias='current-schema-id') class AssertLastAssignedPartitionId(BaseModel): type: Literal['assert-last-assigned-partition-id'] last_assigned_partition_id: int = Field(..., alias='last-assigned-partition-id') class AssertDefaultSpecId(BaseModel): type: Literal['assert-default-spec-id'] default_spec_id: int = Field(..., alias='default-spec-id') class AssertDefaultSortOrderId(BaseModel): type: Literal['assert-default-sort-order-id'] default_sort_order_id: int = Field(..., alias='default-sort-order-id') class TableRequirement(BaseModel): __root__: Union[ AssertCreate, AssertTableUUID, AssertRefSnapshotId, AssertLastAssignedFieldId, AssertCurrentSchemaId, AssertLastAssignedPartitionId, AssertDefaultSpecId, AssertDefaultSortOrderId, ] = Field(..., discriminator='type') ``` Which makes sense to me. * Apply suggestions from code review Co-authored-by: Eduard Tudenhoefner <[email protected]> * WIP * Fixed the inheritance * Generate the code * Fix order --------- Co-authored-by: Eduard Tudenhoefner <[email protected]>
- Loading branch information
Showing
2 changed files
with
187 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters