Removed redundant information from models.yml and adjusted validator

This commit is contained in:
Joshua Sangmeister 2020-12-10 13:52:22 +01:00
parent 253126723f
commit 8a36731d80
3 changed files with 69 additions and 183 deletions

View File

@ -23,19 +23,18 @@
# `motion/category_id`. The type indicates that there are many # `motion/category_id`. The type indicates that there are many
# motion ids. # motion ids.
# - Generic relations: The difference to non-generic relations is that you have a # - Generic relations: The difference to non-generic relations is that you have a
# list of possible collections. Therefore we split the simple notation up to the # list of possible fields, so `to` can either hold multiple collections (if the
# properties `collections` and `field`, if each collection has the same field. # field name is the same):
# If the different collections have different fields, you can give multiple # to:
# `collection` and `field`. E.g.: # collections:
# to: # - agenda_item
# collections: # - assignment
# - collection: motion # - ...
# field: option_ids # field: tag_ids
# - collection: user # Or `to` can be a list of collection fields:
# field: # to:
# name: option_$_ids # - motion/option_ids
# type: structured-relation # - user/option_$_ids
# replacement: meeting_id
# - on_delete: This fields determines what should happen with the foreign model if # - on_delete: This fields determines what should happen with the foreign model if
# this model gets deleted. Possible values are: # this model gets deleted. Possible values are:
# - SET_NULL (default): delete the id from the foreign key # - SET_NULL (default): delete the id from the foreign key
@ -44,17 +43,12 @@
# - CASCADE: also delete all models in this foreign key # - CASCADE: also delete all models in this foreign key
# Structured fields: # Structured fields:
# - There are template fields (see autoupdate service interface) with a `$` as # - There are template fields (see autoupdate service interface) with a `$` as
# the placeholder. We have three different types: `template`, # the placeholder.
# `structured-relation` and `structured-tag`. # - The type `template` describes a structured field for the given model. If the
# - The type `template` describes a structured field for the given model. The # property `replacement` is given, it describes which field of the same model
# property `replacement` describes the meaning of the template. The property # is used as the replacement (=> structured relation). If it not given, the field
# `fields` contains the definition for all the fields that come from the template # is a structured tag. The property `fields` contains the definition for all the
# field. # fields that come from the template field.
# - The type `structured-relation` describes the content of a related field as a
# structured field (with properties `name`, `replacement` and `through`).
# - The type `structured-tag` describes the content of a related field as a
# structured field where the template is filled with arbitrary strings instead of
# instance ids.
# JSON Schema Properties: # JSON Schema Properties:
# - You can add JSON Schema properties like `enum` and `description` to the fields. # - You can add JSON Schema properties like `enum` and `description` to the fields.
@ -223,23 +217,13 @@ user:
replacement: meeting_id replacement: meeting_id
fields: fields:
type: relation type: relation
to: to: user/vote_delegations_$_from_ids
collection: user
field:
name: vote_delegations_$_from_ids
type: structured-relation
replacement: meeting_id
vote_delegations_$_from_ids: vote_delegations_$_from_ids:
type: template type: template
replacement: meeting_id replacement: meeting_id
fields: fields:
type: relation-list type: relation-list
to: to: user/vote_delegated_$_to_id
collection: user
field:
name: vote_delegated_$_to_id
type: structured-relation
replacement: meeting_id
role: role:
id: number id: number
@ -686,26 +670,15 @@ meeting:
# Logos and Fonts # Logos and Fonts
logo_$_id: logo_$_id:
type: template type: template
replacement: place
fields: fields:
type: relation type: relation
to: to: mediafile/used_as_logo_$_in_meeting_id
collection: mediafile
field:
name: used_as_logo_$_in_meeting_id
type: structured-tag
replacement: place
font_$_id: font_$_id:
type: template type: template
replacement: place replacement: place
fields: fields:
type: relation type: relation
to: to: mediafile/used_as_font_$_in_meeting_id
collection: mediafile
field:
name: used_as_font_$_in_meeting_id
type: structured-tag
replacement: place
# Examples: # Examples:
# logo_web_header: Mediafile; # logo_web_header: Mediafile;
# font_italic_pdf: Mediafile; # font_italic_pdf: Mediafile;
@ -756,12 +729,7 @@ group:
user_ids: user_ids:
type: relation-list type: relation-list
to: to: user/group_$_ids
collection: user
field:
name: group_$_ids
type: structured-relation
replacement: meeting_id
default_group_for_meeting_id: default_group_for_meeting_id:
type: relation type: relation
to: meeting/default_group_id to: meeting/default_group_id
@ -812,12 +780,7 @@ personal_note:
user_id: user_id:
type: relation type: relation
to: to: user/personal_note_$_ids
collection: user
field:
name: personal_note_$_ids
type: structured-relation
replacement: meeting_id
content_object_id: content_object_id:
type: generic-relation type: generic-relation
to: to:
@ -974,12 +937,7 @@ speaker:
equal_fields: meeting_id equal_fields: meeting_id
user_id: user_id:
type: relation type: relation
to: to: user/speaker_$_ids
collection: user
field:
name: speaker_$_ids
type: structured-relation
replacement: meeting_id
required: true required: true
meeting_id: meeting_id:
type: relation type: relation
@ -1048,7 +1006,6 @@ motion:
text: HTMLStrict text: HTMLStrict
amendment_paragraph_$: amendment_paragraph_$:
type: template type: template
replacement: paragraph_number
fields: HTMLStrict fields: HTMLStrict
modified_final_version: HTMLStrict modified_final_version: HTMLStrict
reason: HTMLStrict reason: HTMLStrict
@ -1125,12 +1082,7 @@ motion:
equal_fields: meeting_id equal_fields: meeting_id
supporter_ids: supporter_ids:
type: relation-list type: relation-list
to: to: user/supported_motion_$_ids
collection: user
field:
name: supported_motion_$_ids
type: structured-relation
replacement: meeting_id
equal_fields: meeting_id equal_fields: meeting_id
poll_ids: poll_ids:
type: relation-list type: relation-list
@ -1201,12 +1153,7 @@ motion_submitter:
user_id: user_id:
type: relation type: relation
to: to: user/submitted_motion_$_ids
collection: user
field:
name: submitted_motion_$_ids
type: structured-relation
replacement: meeting_id
motion_id: motion_id:
type: relation type: relation
to: motion/submitter_ids to: motion/submitter_ids
@ -1575,12 +1522,7 @@ poll:
equal_fields: meeting_id equal_fields: meeting_id
voted_ids: voted_ids:
type: relation-list type: relation-list
to: to: user/poll_voted_$_ids
collection: user
field:
name: poll_voted_$_ids
type: structured-relation
replacement: meeting_id
entitled_group_ids: entitled_group_ids:
type: relation-list type: relation-list
to: group/poll_ids to: group/poll_ids
@ -1623,16 +1565,9 @@ option:
content_object_id: content_object_id:
type: generic-relation type: generic-relation
to: to:
collections: # Now, we have multiple models to vote about. - motion/option_ids
- collection: motion - topic/option_ids
field: option_ids - user/option_$_ids
- collection: topic
field: option_ids
- collection: user
field:
name: option_$_ids
type: structured-relation
replacement: meeting_id
equal_fields: meeting_id equal_fields: meeting_id
meeting_id: meeting_id:
type: relation type: relation
@ -1651,20 +1586,10 @@ vote:
required: true required: true
user_id: user_id:
type: relation type: relation
to: to: user/vote_$_ids
collection: user
field:
name: vote_$_ids
type: structured-relation
replacement: meeting_id
delegated_user_id: delegated_user_id:
type: relation type: relation
to: to: user/vote_delegated_vote_$_ids
collection: user
field:
name: vote_delegated_vote_$_ids
type: structured-relation
replacement: meeting_id
meeting_id: meeting_id:
type: relation type: relation
to: meeting/vote_ids to: meeting/vote_ids
@ -1744,12 +1669,7 @@ assignment_candidate:
equal_fields: meeting_id equal_fields: meeting_id
user_id: user_id:
type: relation type: relation
to: to: user/assignment_candidate_$_ids
collection: user
field:
name: assignment_candidate_$_ids
type: structured-relation
replacement: meeting_id
meeting_id: meeting_id:
type: relation type: relation
to: meeting/assignment_candidate_ids to: meeting/assignment_candidate_ids
@ -1830,23 +1750,13 @@ mediafile:
replacement: place replacement: place
fields: fields:
type: relation type: relation
to: to: meeting/logo_$_id
collection: meeting
field:
name: logo_$_id
type: structured-tag
replacement: place
used_as_font_$_in_meeting_id: used_as_font_$_in_meeting_id:
type: template type: template
replacement: place replacement: place
fields: fields:
type: relation type: relation
to: to: meeting/font_$_id
collection: meeting
field:
name: font_$_id
type: structured-tag
replacement: place
projector: projector:
id: number id: number
@ -1877,32 +1787,17 @@ projector:
current_element_ids: current_element_ids:
type: generic-relation-list type: generic-relation-list
to: to:
collections: - motion/current_projector_ids
- collection: motion - mediafile/current_projector_ids
field: current_projector_ids - list_of_speakers/current_projector_ids
- collection: mediafile - motion_block/current_projector_ids
field: current_projector_ids - assignment/current_projector_ids
- collection: list_of_speakers - agenda_item/current_projector_ids
field: current_projector_ids - topic/current_projector_ids
- collection: motion_block - poll/current_projector_ids
field: current_projector_ids - projector_message/current_projector_ids
- collection: assignment - projector_countdown/current_projector_ids
field: current_projector_ids - user/current_projector_$_ids
- collection: agenda_item
field: current_projector_ids
- collection: topic
field: current_projector_ids
- collection: poll
field: current_projector_ids
- collection: projector_message
field: current_projector_ids
- collection: projector_countdown
field: current_projector_ids
- collection: user
field:
name: current_projector_$_ids
type: structured-relation
replacement: meeting_id
equal_fields: meeting_id equal_fields: meeting_id
preview_projection_ids: preview_projection_ids:
type: relation-list type: relation-list
@ -1948,32 +1843,17 @@ projection:
element_id: element_id:
type: generic-relation type: generic-relation
to: to:
collections: - motion/projection_ids
- collection: motion - mediafile/projection_ids
field: projection_ids - list_of_speakers/projection_ids
- collection: mediafile - motion_block/projection_ids
field: projection_ids - assignment/projection_ids
- collection: list_of_speakers - agenda_item/projection_ids
field: projection_ids - topic/projection_ids
- collection: motion_block - poll/projection_ids
field: projection_ids - projector_message/projection_ids
- collection: assignment - projector_countdown/projection_ids
field: projection_ids - user/projection_$_ids
- collection: agenda_item
field: projection_ids
- collection: topic
field: projection_ids
- collection: poll
field: projection_ids
- collection: projector_message
field: projection_ids
- collection: projector_countdown
field: projection_ids
- collection: user
field:
name: projection_$_ids
type: structured-relation
replacement: meeting_id
equal_fields: meeting_id equal_fields: meeting_id
meeting_id: meeting_id:
type: relation type: relation

View File

@ -12,7 +12,7 @@ file system path or an url starting with http:// or https://.
``` ```
cat models.yaml | modelsvalidator cat models.yml | modelsvalidator
modelsvalidator openslides/docs/models.yml modelsvalidator openslides/docs/models.yml
modelsvalidator https://raw.githubusercontent.com/OpenSlides/OpenSlides/openslides4-dev/docs/models.yml modelsvalidator https://raw.githubusercontent.com/OpenSlides/OpenSlides/openslides4-dev/docs/models.yml
``` ```

View File

@ -222,12 +222,18 @@ func (t *ToGeneric) UnmarshalYAML(value *yaml.Node) error {
return nil return nil
} }
var e struct { var e []string
CollectionFields []ToCollectionField `yaml:"collections"`
}
if err := value.Decode(&e); err != nil { if err := value.Decode(&e); err != nil {
return fmt.Errorf("decoding to generic field at line %d: %w", value.Line, err) return fmt.Errorf("decoding to generic field at line %d: %w", value.Line, err)
} }
t.CollectionFields = e.CollectionFields t.CollectionFields = make([]ToCollectionField, len(e))
for i, collectionfield := range e {
cf := strings.Split(collectionfield, "/")
if len(cf) != 2 {
return fmt.Errorf("invalid value of `to` in line %d, expected one `/`: %s", value.Line, collectionfield)
}
t.CollectionFields[i].Collection = cf[0]
t.CollectionFields[i].ToField.Name = cf[1]
}
return nil return nil
} }