mrmap-community / mrmap

Spatial Service Registry
https://mrmap.rtfd.io/en/master/
MIT License
11 stars 6 forks source link

Backend: Support translation in generated schema #265

Closed jokiefer closed 2 years ago

jokiefer commented 2 years ago

Status quo

Currently the schema of the json:api is build by from rest_framework_json_api.schemas.openapi import SchemaGenerator This Generator creates a schema like below:


WebMapService:
  type: object
  required:
  - type
  - id
  additionalProperties: false
  properties:
    type:
      $ref: '#/components/schemas/type'
    id:
      $ref: '#/components/schemas/id'
    links:
      type: object
      properties:
        self:
          $ref: '#/components/schemas/link'
    attributes:
      type: object
      properties:
        id:
          type: string
          format: uuid
          readOnly: true
        created_at:
          type: string
          format: date-time
          readOnly: true
          description: The timestamp of the creation date of this object.
        last_modified_at:
          type: string
          format: date-time
          readOnly: true
          description: The timestamp of the last modification of this object

The description or example is the property help_text of the django model field.

Enhancement

  1. The verbose_name of the django model field (which is the translateable title of the field) shall be also part of the schema.
  2. The verbose_name of the model it self shall be also part of the schema.
MrSnyder commented 2 years ago

I am positive that at some point in the past (maybe 1,5 weeks ago) we had the verbose_name from the Django model class exported as a property title in the OpenAPI schema, e.g. for the WebMapService entities. Also, the Swagger UI offered the get schema operation with a language parameter that already allowed to switch between German and English.

jokiefer commented 2 years ago

Test was added in #447

use cookie to set language: django_language=de

To switch the language in the frontend: reload the schema with different django_language cookie