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

Response models print as indented JSON #82

Merged
merged 4 commits into from
Dec 18, 2024

Conversation

mmwinther
Copy link
Member

@mmwinther mmwinther commented Dec 18, 2024

Summary

This overrides the python "dunder method" __str__ to provide a much more readable representation of a Variable Definition.

Before

id='wypvb3wd' patch_id=1 name=LanguageStringType(nb='Landbakgrunn', nn='Landbakgrunn', en='Country Background') short_name='landbak' definition=LanguageStringType(nb='For personer født i utlandet, er dette (med noen få unntak) eget fødeland. For personer født i Norge er det foreldrenes fødeland. I de tilfeller der foreldrene har ulikt fødeland, er det morens fødeland som blir valgt. Hvis ikke personen selv eller noen av foreldrene er utenlandsfødt, hentes landbakgrunn fra de første utenlandsfødte en treffer på i rekkefølgen mormor, morfar, farmor eller farfar.', nn='For personar fødd i utlandet, er dette (med nokre få unntak) eige fødeland. For personar fødd i Noreg er det fødelandet til foreldra. I dei tilfella der foreldra har ulikt fødeland, er det fødelandet til mora som blir valt. Viss ikkje personen sjølv eller nokon av foreldra er utenlandsfødt, blir henta landsbakgrunn frå dei første utenlandsfødte ein treffar på i rekkjefølgja mormor, morfar, farmor eller farfar.', en="Country background is the person's own, the mother's or possibly the father's country of birth. Persons without an immigrant background always have Norway as country background. In cases where the parents have different countries of birth the mother's country of birth is chosen. If neither the person nor the parents are born abroad, country background is chosen from the first person born abroad in the order mother's mother, mother's father, father's mother, father's father.") classification_reference='91' unit_types=['01', '02'] subject_fields=['he04'] contains_special_categories_of_personal_data=True variable_status=<VariableStatus.DRAFT: 'DRAFT'> measurement_type=None valid_from=datetime.date(2003, 1, 1) valid_until=None external_reference_uri='https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb' comment=LanguageStringType(nb='Fra og med 1.1.2003 ble definisjon endret til også å trekke inn besteforeldrenes fødeland.', nn='Fra og med 1.1.2003 ble definisjon endret til også å trekke inn besteforeldrenes fødeland.', en="As of 1 January 2003, the definition was changed to also include the grandparents' country of birth.") related_variable_definition_uris=['https://example.com/'] owner=Owner(team='team-a', groups=['team-a-developers']) contact=Contact(title=LanguageStringType(nb='Seksjon for befolkningsstatistikk', nn='Seksjon for befolkningsstatistikk', en='Division for population statistics'), email='[email protected]') created_at=datetime.datetime(2024, 6, 11, 8, 15, 19, 38000, tzinfo=TzInfo(UTC)) created_by=Person(code='[email protected]', name='Ola Nordmann') last_updated_at=datetime.datetime(2024, 6, 11, 8, 15, 19, 38000, tzinfo=TzInfo(UTC)) last_updated_by=Person(code='[email protected]', name='Ola Nordmann')

After

{
  "id": "wypvb3wd",
  "patch_id": 1,
  "name": {
    "nb": "test",
    "nn": "test",
    "en": "test"
  },
  "short_name": "var_test",
  "definition": {
    "nb": "test",
    "nn": "test",
    "en": "test"
  },
  "classification_reference": "91",
  "unit_types": [
    "01"
  ],
  "subject_fields": [
    "a",
    "b"
  ],
  "contains_special_categories_of_personal_data": true,
  "variable_status": "PUBLISHED_EXTERNAL",
  "measurement_type": "test",
  "valid_from": "2024-11-01",
  "valid_until": null,
  "external_reference_uri": "http://www.example.com",
  "comment": {
    "nb": "test",
    "nn": "test",
    "en": "test"
  },
  "related_variable_definition_uris": [
    "http://www.example.com"
  ],
  "owner": {
    "team": "my_team",
    "groups": [
      "my_team_developers"
    ]
  },
  "contact": {
    "title": {
      "nb": "test",
      "nn": "test",
      "en": "test"
    },
    "email": "[email protected]"
  },
  "created_at": "2024-11-01T00:00:00",
  "created_by": {
    "code": "724",
    "name": "name"
  },
  "last_updated_at": "2024-11-01T00:00:00",
  "last_updated_by": {
    "code": "724",
    "name": "name"
  }
}

@mmwinther mmwinther requested a review from a team as a code owner December 18, 2024 09:00
Copy link
Contributor

@tilen1976 tilen1976 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! I was a little doubtful about the name, CompletePatchOutput, but I have no other suggestions and it has to fit the existing names in Vardef so I approve 👍

@mmwinther mmwinther merged commit daed73d into main Dec 18, 2024
14 of 15 checks passed
@mmwinther mmwinther deleted the feat/dpmeta-640-indented-json-print branch December 18, 2024 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants