FixMyBerlin / fixmy.platform

Backend providing (geo)data and content for multiple applications
GNU Affero General Public License v3.0
11 stars 3 forks source link

Übertragung des Profils nach Angabe aller Daten #104

Closed cafca closed 4 years ago

cafca commented 5 years ago

Todo:

s-pic commented 5 years ago

Kann bei der Erstellung des JSON schemas gerne zuarbeiten.

s-pic commented 5 years ago

Habe mal geschaut, ob man nicht Deine Vorarbeit – die Typisierung der im State verwendeten Objekte (bspw. ProfileRequest) – nutzen kann, um auf dieser Basis das JSON Schemas zu generieren. Die Lib typescript-json-schema leistet dies grundsätzlich.

Im Projekt kam es bei der Nutzung der im Readme dokumentierten Aufrufe zwar zu Fehlern (es Files in node_module analysiert, was ich garnicht erwarte), Wenn ich src/pages/KatasterKI/types.ts jedoch extrahiere und im selben Verzeichnis

npm i -g typescript-json-schema
typescript-json-schema "./ProfileRequest.ts" *

aufrufe, wird erfolgreich ein Schema für alle zusammenhängenden Typen erstellt:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "definitions": {
        "Answer": {
            "properties": {
                "duration": {
                    "type": "number"
                },
                "rating": {
                    "$ref": "#/definitions/Rating"
                },
                "sceneID": {
                    "type": "string"
                }
            },
            "type": "object"
        },
        "AnswerRequest": {
            "properties": {
                "duration": {
                    "type": "number"
                },
                "rating": {
                    "$ref": "#/definitions/Rating"
                },
                "sceneID": {
                    "type": "string"
                }
            },
            "type": "object"
        },
        "Experiment": {
            "enum": [
                "CP",
                "MS",
                "SE"
            ],
            "type": "string"
        },
        "Perspective": {
            "enum": [
                "A",
                "C",
                "P"
            ],
            "type": "string"
        },
        "PerspectiveChangeRequest": {
            "properties": {
                "perspective": {
                    "$ref": "#/definitions/Perspective"
                }
            },
            "type": "object"
        },
        "PerspectiveChangeResponse": {
            "properties": {
                "ratings_total": {
                    "type": "number"
                },
                "scenes": {
                    "items": {
                        "type": "string"
                    },
                    "type": "array"
                }
            },
            "type": "object"
        },
        "ProfileRequest": {
            "properties": {
                "ageGroup": {
                    "enum": [
                        0,
                        1,
                        2,
                        3
                    ],
                    "type": "number"
                },
                "berlinTraffic": {
                    "type": "string"
                },
                "bicycleAccident": {
                    "enum": [
                        0,
                        1,
                        2,
                        3
                    ],
                    "type": "number"
                },
                "bicycleUse": {
                    "enum": [
                        0,
                        1,
                        2,
                        3
                    ],
                    "type": "number"
                },
                "bikeReasons": {
                    "items": {
                        "type": "string"
                    },
                    "type": "array"
                },
                "district": {
                    "type": "string"
                },
                "gender": {
                    "enum": [
                        "d",
                        "m",
                        "w"
                    ],
                    "type": "string"
                },
                "hasChildren": {
                    "type": "boolean"
                },
                "isAgbAccepted": {
                    "type": "boolean"
                },
                "postcode": {
                    "type": "string"
                },
                "transportRatings": {
                    "additionalProperties": {
                        "$ref": "#/definitions/TransportRating"
                    },
                    "type": "object"
                },
                "userGroup": {
                    "$ref": "#/definitions/UserGroup"
                },
                "vehiclesOwned": {
                    "items": {
                        "enum": [
                            "bicycle",
                            "car",
                            "motorbike",
                            "pedelec",
                            "public"
                        ],
                        "type": "string"
                    },
                    "type": "array"
                }
            },
            "type": "object"
        },
        "ProfileResponse": {
            "properties": {
                "ratings_total": {
                    "type": "number"
                },
                "scenes": {
                    "items": {
                        "type": "string"
                    },
                    "type": "array"
                }
            },
            "type": "object"
        },
        "Rating": {
            "enum": [
                0,
                1,
                2,
                3
            ],
            "type": "number"
        },
        "RequestState": {
            "enum": [
                "delayed",
                "error",
                "pending",
                "success",
                "waiting"
            ],
            "type": "string"
        },
        "TransportMode": {
            "enum": [
                "bicycle",
                "car",
                "motorbike",
                "pedestrian",
                "public"
            ],
            "type": "string"
        },
        "TransportRating": {
            "enum": [
                0,
                1,
                2,
                3,
                4,
                5
            ],
            "type": "number"
        },
        "UserGroup": {
            "enum": [
                "bicycle",
                "car",
                "pedestrian",
                "potentialBicycle"
            ],
            "type": "string"
        },
        "VehicleKind": {
            "enum": [
                "bicycle",
                "car",
                "motorbike",
                "pedelec",
                "public"
            ],
            "type": "string"
        }
    }
}
cafca commented 5 years ago

Ja genau, dafür gibt es auch schon ein npm run command in der package.json