PnX-SI / Nomenclature-api-module

Flask module for Nomenclature API
GNU General Public License v3.0
3 stars 10 forks source link

feat: fetch nomenclature definition list with taxonomy #26

Closed sgrimault closed 5 years ago

sgrimault commented 5 years ago

Nouvelle route /nomenclatures/taxonomy qui permet de lister l'intégralité de la nomenclature avec les termes et la taxonomie.

Schéma JSON en sortie :

{
  "definitions": {},
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "http://geonature.fr/nomenclatures.json",
  "type": "array",
  "title": "array of nomenclature type schema",
  "minItems": 0,
  "items": {
    "$id": "#/type",
    "type": "object",
    "title": "Nomenclature type schema",
    "required": [
      "id_type",
      "label_default",
      "mnemonique",
      "nomenclatures"
    ],
    "properties": {
      "id_type": {
        "$id": "#/type/properties/id_type",
        "type": "integer",
        "title": "id_type",
        "default": 0,
        "examples": [
          8
        ]
      },
      "label_de": {
        "$id": "#/type/properties/label_de",
        "type": [
          "string",
          "null"
        ],
        "title": "label in german",
        "default": null
      },
      "label_default": {
        "$id": "#/type/properties/label_default",
        "type": "string",
        "title": "label_default",
        "examples": [
          "Niveau de naturalité"
        ],
        "pattern": "^(.*)$"
      },
      "label_en": {
        "$id": "#/type/properties/label_en",
        "type": [
          "string",
          "null"
        ],
        "title": "label in english",
        "default": null
      },
      "label_es": {
        "$id": "#/type/properties/label_es",
        "type": [
          "string",
          "null"
        ],
        "title": "label in spanish",
        "default": null
      },
      "label_fr": {
        "$id": "#/type/properties/label_fr",
        "type": [
          "string",
          "null"
        ],
        "title": "label in french",
        "default": null,
        "examples": [
          "Niveau de naturalité"
        ],
        "pattern": "^(.*)$"
      },
      "label_it": {
        "$id": "#/type/properties/label_it",
        "type": [
          "string",
          "null"
        ],
        "title": "label in italian",
        "default": null
      },
      "mnemonique": {
        "$id": "#/type/properties/mnemonique",
        "type": "string",
        "title": "mnemonique",
        "examples": [
          "NATURALITE"
        ],
        "pattern": "^(.*)$"
      },
      "nomenclatures": {
        "$id": "#/type/properties/nomenclatures",
        "type": "array",
        "title": "array of nomenclatures schema",
        "minItems": 0,
        "items": {
          "$id": "#/type/properties/nomenclatures/nomenclature",
          "type": "object",
          "title": "nomenclature schema",
          "required": [
            "cd_nomenclature",
            "hierarchy",
            "id_nomenclature",
            "label_default",
            "mnemonique",
            "taxref"
          ],
          "properties": {
            "cd_nomenclature": {
              "$id": "#/type/properties/nomenclatures/nomenclature/properties/cd_nomenclature",
              "type": "string",
              "title": "cd_nomenclature",
              "examples": [
                "0"
              ],
              "pattern": "^(.*)$"
            },
            "hierarchy": {
              "$id": "#/type/properties/nomenclatures/nomenclature/properties/hierarchy",
              "type": "string",
              "title": "hierarchy",
              "examples": [
                "008.001"
              ],
              "pattern": "^(.*)$"
            },
            "id_nomenclature": {
              "$id": "#/type/properties/nomenclatures/nomenclature/properties/id_nomenclature",
              "type": "integer",
              "title": "id_nomenclature",
              "default": 0,
              "examples": [
                159
              ]
            },
            "label_de": {
              "$id": "#/type/properties/nomenclatures/nomenclature/properties/label_de",
              "type": [
                "string",
                "null"
              ],
              "title": "label in german",
              "default": null,
              "examples": [
                null
              ]
            },
            "label_default": {
              "$id": "#/type/properties/nomenclatures/nomenclature/properties/label_default",
              "type": "string",
              "title": "label_default",
              "examples": [
                "Inconnu"
              ],
              "pattern": "^(.*)$"
            },
            "label_en": {
              "$id": "#/type/properties/nomenclatures/nomenclature/properties/label_en",
              "type": [
                "string",
                "null"
              ],
              "title": "label in english",
              "default": null,
              "examples": [
                null
              ]
            },
            "label_es": {
              "$id": "#/type/properties/nomenclatures/nomenclature/properties/label_es",
              "type": [
                "string",
                "null"
              ],
              "title": "label in spanish",
              "default": null,
              "examples": [
                null
              ]
            },
            "label_fr": {
              "$id": "#/type/properties/nomenclatures/nomenclature/properties/label_fr",
              "type": [
                "string",
                "null"
              ],
              "title": "label in french",
              "default": null,
              "examples": [
                "Inconnu"
              ],
              "pattern": "^(.*)$"
            },
            "label_it": {
              "$id": "#/type/properties/nomenclatures/nomenclature/properties/label_it",
              "type": [
                "string",
                "null"
              ],
              "title": "label in italian",
              "default": null,
              "examples": [
                null
              ]
            },
            "mnemonique": {
              "$id": "#/type/properties/nomenclatures/nomenclature/properties/mnemonique",
              "type": "string",
              "title": "mnemonique",
              "examples": [
                "Inconnu"
              ],
              "pattern": "^(.*)$"
            },
            "taxref": {
              "$id": "#/type/properties/nomenclatures/nomenclature/properties/taxref",
              "type": "array",
              "title": "array of taxref schema",
              "minItems": 0,
              "items": {
                "$id": "#/type/properties/nomenclatures/nomenclature/properties/taxref/taxref",
                "type": "object",
                "title": "taxref schema",
                "required": [
                  "group2_inpn",
                  "regne"
                ],
                "properties": {
                  "group2_inpn": {
                    "$id": "#/type/properties/nomenclatures/nomenclature/properties/taxref/taxref/properties/group2_inpn",
                    "type": "string",
                    "title": "group2_inpn",
                    "examples": [
                      "all"
                    ],
                    "pattern": "^(.*)$"
                  },
                  "regne": {
                    "$id": "#/type/properties/nomenclatures/nomenclature/properties/taxref/taxref/properties/regne",
                    "type": "string",
                    "title": "regne",
                    "examples": [
                      "all"
                    ],
                    "pattern": "^(.*)$"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
TheoLechemia commented 5 years ago

J'ai un problème avec l'import du fichier "repository'.

 File "/home/theo/workspace/GN2/Nomenclature-api-module/src/pypnnomenclature/routes.py", line 7, in <module>
    import repository
ModuleNotFoundError: No module named 'repository'

Tu n'as pas eu ce problème ? J'ai dû changer la ligne import repository par from . import repository.

J'ai aussi changé la stratégie de chargement de la relationship taxref en select au lieu de join pour maintenir la compatibilité avec ceux qui n'ont pas la taxonomie dans leur schéma ref_nomenclatures.

    taxref = relationship(
        'CorTaxrefNomenclature',
        lazy='select'
    )
TheoLechemia commented 5 years ago

J'ai fais une PR sur la branche de ton dépôt. J'imagine que si tu l'accepte, elle va se répercuter ici ?

sgrimault commented 5 years ago

Ok ça me va aussi de mon coté. Merci :)

sgrimault commented 5 years ago

Je n'ai pas eu de souci coté import de mon coté (Python 3.6.8)