Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#90] Rolling back file level schema changes #92

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/models/management/generate_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ def main(output_name: str = "api/models/schemas/schema.json"):
class_definition = schema["definitions"][definition]
# replace allOf with a single definition
json_schema = json_schema.replace(
f'"allOf": [{{"$ref": "#/definitions/{definition}"}}]',
f'"allOf": [{{"$ref": "#/definitions/{definition}"}}]',
json.dumps(class_definition)[1:-1]
)
#replace definition directly
json_schema = json_schema.replace(
f'"$ref": "#/definitions/{definition}"',
f'"$ref": "#/definitions/{definition}"',
json.dumps(class_definition)[1:-1]
)
embedded_schema = json.loads(json_schema)
Expand Down
74 changes: 0 additions & 74 deletions api/models/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ class PublisherOrganization(Organization):
)


class MediaObjectSourceOrganization(Organization):
name: str = Field(description="Name of the organization that created the media object.")


class DefinedTerm(SchemaBaseModel):
type: str = Field(alias="@type", default="DefinedTerm")
name: str = Field(description="The name of the term or item being defined.")
Expand Down Expand Up @@ -308,50 +304,6 @@ def validate_box(cls, v):
return v


class PropertyValueBase(SchemaBaseModel):
type: str = Field(
alias="@type",
default="PropertyValue",
const="PropertyValue",
description="A property-value pair.",
)
propertyID: Optional[str] = Field(
title="Property ID", description="The ID of the property."
)
name: str = Field(description="The name of the property.")
value: str = Field(description="The value of the property.")
unitCode: Optional[str] = Field(
title="Measurement unit", description="The unit of measurement for the value."
)
description: Optional[str] = Field(description="A description of the property.")
minValue: Optional[float] = Field(
title="Minimum value", description="The minimum allowed value for the property."
)
maxValue: Optional[float] = Field(
title="Maximum value", description="The maximum allowed value for the property."
)

class Config:
title = "PropertyValue"

@root_validator
def validate_min_max_values(cls, values):
min_value = values.get("minValue", None)
max_value = values.get("maxValue", None)
if min_value is not None and max_value is not None:
if min_value > max_value:
raise ValueError("Minimum value must be less than or equal to maximum value")

return values


class PropertyValue(PropertyValueBase):
# using PropertyValueBase model instead of PropertyValue model as one of the types for the value field
# in order for the schema generation (schema.json) to work. Self referencing nested models leads to
# infinite loop in our custom schema generation code when trying to replace dict with key '$ref'
value: Union[str, PropertyValueBase, List[PropertyValueBase]] = Field(description="The value of the property.")


class Place(SchemaBaseModel):
type: str = Field(alias="@type", default="Place", description="Represents the focus area of the record's content.")
name: Optional[str] = Field(description="Name of the place.")
Expand All @@ -360,12 +312,6 @@ class Place(SchemaBaseModel):
"or area coverage extent."
)

additionalProperty: Optional[List[PropertyValue]] = Field(
title="Additional properties",
default=[],
description="Additional properties of the place."
)

@root_validator
def validate_geo_or_name_required(cls, values):
name = values.get('name', None)
Expand All @@ -390,26 +336,6 @@ class MediaObject(SchemaBaseModel):
"unit of measurement."
)
name: str = Field(description="The name of the media object (file).")
additionalProperty: Optional[List[PropertyValue]] = Field(
title="Additional properties",
default=[],
description="Additional properties of the media object."
)
variableMeasured: Optional[List[Union[str, PropertyValue]]] = Field(
title="Variables measured", description="Measured variables."
)
spatialCoverage: Optional[Place] = Field(
title="Spatial coverage",
description="The spatial coverage of the media object."
)
temporalCoverage: Optional[TemporalCoverage] = Field(
title="Temporal coverage",
description="The temporal coverage of the media object."
)
sourceOrganization: Optional[MediaObjectSourceOrganization] = Field(
title="Source organization",
description="The organization that provided the media object."
)

@validator('contentSize')
def validate_content_size(cls, v):
Expand Down
Loading
Loading