Skip to content

Commit

Permalink
fix: Merge pull request #155 from IBM/fix/issue_149b
Browse files Browse the repository at this point in the history
Fix/issue 149b - convert Union[A, A] to Union[A, conlist(A, min_items=2)]

closes #149
  • Loading branch information
butler54 authored Oct 15, 2020
2 parents 0fd3c4e + 4f6f6a9 commit 7ded03e
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 29 deletions.
6 changes: 6 additions & 0 deletions scripts/fix_any.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ def fix_file(fname):
class_text = ClassText(r)
else:
if not done_header: # still in header
# block import of Any - should not be needed
r = re.sub(' Any, ', ' ', r)
# add import of conlist for Union[A, A] case
r = re.sub(r'^(from\s+pydantic\s+import.*)$', r'\1, conlist', r)
header.append(r.rstrip())
else: # in body of class looking for Any's
n1 = r.find(pattern1)
Expand All @@ -235,6 +239,8 @@ def fix_file(fname):
else:
# for a line that has no Any's, use regex to find referenced class names
class_text.add_all_refs(r)
# fix any line containing Union[A, A] to Union[A, conlist(A, min_items=2)]
r = re.sub(r'Union\[([^,]*),\s*\1\]', r'Union[\1, conlist(\1, min_items=2)]', r)
class_text.add_line(r.rstrip())

all_classes.append(class_text) # don't forget final class
Expand Down
8 changes: 4 additions & 4 deletions trestle/oscal/assessment_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
# limitations under the License.
# generated by datamodel-codegen:
# filename: oscal_assessment-plan_schema.json
# timestamp: 2020-10-14T00:53:58+00:00
# timestamp: 2020-10-15T02:07:23+00:00

from __future__ import annotations

from datetime import datetime
from enum import Enum
from typing import Any, Dict, List, Optional, Union
from typing import Dict, List, Optional, Union

from pydantic import AnyUrl, EmailStr, Field, conint, constr
from pydantic import AnyUrl, EmailStr, Field, conint, constr, conlist

from trestle.core.base_model import OscalBaseModel

Expand Down Expand Up @@ -799,7 +799,7 @@ class Objectives(OscalBaseModel):
control_objective_group: Optional[List[ControlObjectives]] = Field(
None, alias='control-objective-group'
)
objectives: Optional[Union[Objective, Objective]] = None
objectives: Optional[Union[Objective, conlist(Objective, min_items=2)]] = None
method_definitions: Optional[List[Method]] = Field(None, alias='method-definitions')
remarks: Optional[Remarks] = None

Expand Down
8 changes: 4 additions & 4 deletions trestle/oscal/assessment_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
# limitations under the License.
# generated by datamodel-codegen:
# filename: oscal_assessment-results_schema.json
# timestamp: 2020-10-14T00:54:01+00:00
# timestamp: 2020-10-15T02:07:27+00:00

from __future__ import annotations

from datetime import datetime
from enum import Enum
from typing import Any, Dict, List, Optional, Union
from typing import Dict, List, Optional, Union

from pydantic import AnyUrl, EmailStr, Field, conint, constr
from pydantic import AnyUrl, EmailStr, Field, conint, constr, conlist

from trestle.core.base_model import OscalBaseModel

Expand Down Expand Up @@ -1047,7 +1047,7 @@ class Objectives(OscalBaseModel):
control_objective_group: Optional[List[ControlObjectives]] = Field(
None, alias='control-objective-group'
)
objectives: Optional[Union[Objective, Objective]] = None
objectives: Optional[Union[Objective, conlist(Objective, min_items=2)]] = None
method_definitions: Optional[List[Method]] = Field(None, alias='method-definitions')
remarks: Optional[Remarks] = None

Expand Down
6 changes: 3 additions & 3 deletions trestle/oscal/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
# limitations under the License.
# generated by datamodel-codegen:
# filename: oscal_catalog_schema.json
# timestamp: 2020-10-14T00:54:04+00:00
# timestamp: 2020-10-15T02:07:31+00:00

from __future__ import annotations

from datetime import datetime
from enum import Enum
from typing import Any, Dict, List, Optional
from typing import Dict, List, Optional

from pydantic import AnyUrl, EmailStr, Field, constr
from pydantic import AnyUrl, EmailStr, Field, constr, conlist

from trestle.core.base_model import OscalBaseModel

Expand Down
8 changes: 4 additions & 4 deletions trestle/oscal/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
# limitations under the License.
# generated by datamodel-codegen:
# filename: oscal_component_schema.json
# timestamp: 2020-10-14T00:54:05+00:00
# timestamp: 2020-10-15T02:07:33+00:00

from __future__ import annotations

from datetime import datetime
from enum import Enum
from typing import Any, Dict, List, Optional, Union
from typing import Dict, List, Optional, Union

from pydantic import AnyUrl, EmailStr, Field, constr
from pydantic import AnyUrl, EmailStr, Field, constr, conlist

from trestle.core.base_model import OscalBaseModel

Expand Down Expand Up @@ -341,7 +341,7 @@ class Statement(OscalBaseModel):
)
description: Optional[Description] = None
properties: Optional[List[Prop]] = None
annotations: Optional[Union[Annotation, Annotation]] = None
annotations: Optional[Union[Annotation, conlist(Annotation, min_items=2)]] = None
links: Optional[List[Link]] = None
responsible_roles: Optional[Dict[str, ResponsibleRole]] = Field(None, alias='responsible-roles')
remarks: Optional[Remarks] = None
Expand Down
6 changes: 3 additions & 3 deletions trestle/oscal/poam.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
# limitations under the License.
# generated by datamodel-codegen:
# filename: oscal_poam_schema.json
# timestamp: 2020-10-14T00:54:08+00:00
# timestamp: 2020-10-15T02:07:36+00:00

from __future__ import annotations

from datetime import datetime
from enum import Enum
from typing import Any, Dict, List, Optional
from typing import Dict, List, Optional

from pydantic import AnyUrl, EmailStr, Field, conint, constr
from pydantic import AnyUrl, EmailStr, Field, conint, constr, conlist

from trestle.core.base_model import OscalBaseModel

Expand Down
6 changes: 3 additions & 3 deletions trestle/oscal/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
# limitations under the License.
# generated by datamodel-codegen:
# filename: oscal_profile_schema.json
# timestamp: 2020-10-14T00:54:10+00:00
# timestamp: 2020-10-15T02:07:40+00:00

from __future__ import annotations

from datetime import datetime
from enum import Enum
from typing import Any, Dict, List, Optional
from typing import Dict, List, Optional

from pydantic import AnyUrl, EmailStr, Field, constr
from pydantic import AnyUrl, EmailStr, Field, constr, conlist

from trestle.core.base_model import OscalBaseModel

Expand Down
8 changes: 4 additions & 4 deletions trestle/oscal/ssp.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
# limitations under the License.
# generated by datamodel-codegen:
# filename: oscal_ssp_schema.json
# timestamp: 2020-10-14T00:54:12+00:00
# timestamp: 2020-10-15T02:07:42+00:00

from __future__ import annotations

from datetime import datetime
from enum import Enum
from typing import Any, Dict, List, Optional, Union
from typing import Dict, List, Optional, Union

from pydantic import AnyUrl, EmailStr, Field, conint, constr
from pydantic import AnyUrl, EmailStr, Field, conint, constr, conlist

from trestle.core.base_model import OscalBaseModel

Expand Down Expand Up @@ -578,7 +578,7 @@ class Statement(OscalBaseModel):
)
description: Optional[Description] = None
properties: Optional[List[Prop]] = None
annotations: Optional[Union[Annotation, Annotation]] = None
annotations: Optional[Union[Annotation, conlist(Annotation, min_items=2)]] = None
links: Optional[List[Link]] = None
responsible_roles: Optional[Dict[str, ResponsibleRole]] = Field(None, alias='responsible-roles')
by_components: Optional[Dict[str, ByComponent]] = Field(None, alias='by-components')
Expand Down
8 changes: 4 additions & 4 deletions trestle/oscal/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
# limitations under the License.
# generated by datamodel-codegen:
# filename: IBM_target_schema.json
# timestamp: 2020-10-14T00:54:14+00:00
# timestamp: 2020-10-15T02:07:45+00:00

from __future__ import annotations

from datetime import datetime
from enum import Enum
from typing import Any, Dict, List, Optional, Union
from typing import Dict, List, Optional, Union

from pydantic import AnyUrl, EmailStr, Field, constr
from pydantic import AnyUrl, EmailStr, Field, constr, conlist

from trestle.core.base_model import OscalBaseModel

Expand Down Expand Up @@ -385,7 +385,7 @@ class Statement(OscalBaseModel):
)
description: Optional[Description] = None
properties: Optional[List[Prop]] = None
annotations: Optional[Union[Annotation, Annotation]] = None
annotations: Optional[Union[Annotation, conlist(Annotation, min_items=2)]] = None
links: Optional[List[Link]] = None
responsible_roles: Optional[Dict[str, ResponsibleRole]] = Field(None, alias='responsible-roles')
remarks: Optional[Remarks] = None
Expand Down

0 comments on commit 7ded03e

Please sign in to comment.