Skip to content

Commit

Permalink
used prebuild.py for translation
Browse files Browse the repository at this point in the history
  • Loading branch information
jowgn committed Feb 9, 2024
1 parent 8ca6a7a commit ddb3d8d
Show file tree
Hide file tree
Showing 1,205 changed files with 66,837 additions and 66,728 deletions.
124 changes: 67 additions & 57 deletions prebuild.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import yaml


def load_api_spec(file_path):
"""Lädt die OpenAPI-Spezifikation aus einer YAML-Datei."""
with open(file_path, 'r') as file:
with open(file_path, "r") as file:
return yaml.safe_load(file)


def sort_api_spec(api_spec, depth=0, max_depth=None):
"""Sortiert die OpenAPI-Spezifikation alphabetisch bis zur n-ten Ebene."""
if max_depth is not None and depth >= max_depth:
Expand All @@ -13,11 +15,12 @@ def sort_api_spec(api_spec, depth=0, max_depth=None):
sorted_spec = {}
for key in sorted(api_spec.keys(), key=lambda x: x.lower()):
if isinstance(api_spec[key], dict):
sorted_spec[key] = sort_api_spec(api_spec[key], depth=depth+1, max_depth=max_depth)
sorted_spec[key] = sort_api_spec(api_spec[key], depth=depth + 1, max_depth=max_depth)
else:
sorted_spec[key] = api_spec[key]
return sorted_spec


def replace_in_api_spec(api_spec, old_word, new_word, depth=0, max_depth=None, key=None):
"""Ersetzt Wortparen in OpenAPI-Spezifikation bis zur n-ten Ebene."""
if max_depth is not None and depth >= max_depth:
Expand All @@ -26,83 +29,90 @@ def replace_in_api_spec(api_spec, old_word, new_word, depth=0, max_depth=None, k
replaced_spec = {}
for thisKey in api_spec.keys():
if isinstance(api_spec[thisKey], dict):
replaced_spec[thisKey] = replace_in_api_spec(api_spec[thisKey], old_word=old_word, new_word=new_word, depth=depth+1, max_depth=max_depth, key=key)
replaced_spec[thisKey] = replace_in_api_spec(
api_spec[thisKey],
old_word=old_word,
new_word=new_word,
depth=depth + 1,
max_depth=max_depth,
key=key,
)
else:
if key is None or key == thisKey:
replaced_spec[thisKey] = api_spec[thisKey].replace(old_word, new_word)
else:
replaced_spec[thisKey] = api_spec[thisKey]
return replaced_spec


def save_api_spec(api_spec, file_path):
"""Speichert die geänderte OpenAPI-Spezifikation in einer YAML-Datei."""
with open(file_path, 'w') as file:
with open(file_path, "w") as file:
yaml.safe_dump(api_spec, file, sort_keys=False)


# Spezifikation laden
api_spec = load_api_spec("oas.yml")
api_spec_man = load_api_spec("oas_manuell.yml")
# Titel ändern
api_spec['info']['title'] = "Rentman API"
api_spec["info"]["title"] = "Rentman API"
# Security hinzufügen
api_spec['components'].update(
{
'securitySchemes': {
'bearerAuth': {
'type': 'http',
'scheme': 'bearer',
'bearerFormat': 'JWT'
}
}
}
api_spec["components"].update(
{"securitySchemes": {"bearerAuth": {"type": "http", "scheme": "bearer", "bearerFormat": "JWT"}}}
)
api_spec['security'] = [{'bearerAuth': []}]
api_spec["security"] = [{"bearerAuth": []}]
# Replace words in identifiers
word_pairs = [('Accessoire', 'Accessory'),
('Afspraakmedewerker', 'AppointmentCrew'),
('Afspraak', 'Appointment'),
('Person', 'Contactperson'),
('Medewerker', 'Crew'),
('Beschikbaarheid', 'CrewAvailability'),
('Medewerkertarief', 'CrewRates'),
('Materiaal', 'Equipment'),
('Setinhoud','EquipmentSetsContent'),
('Files','File'),
('Btwbedrag', 'InvoiceLines'),
('Factuur', 'Invoice'),
('Grootboek', 'LedgerCode'),
('Planningpersoneel', 'ProjectCrew'),
('Planningmateriaal', 'ProjectEquipment'),
('MateriaalCat', 'ProjectEquipmentGroup'),
('Functiegroep', 'ProjectFunctionGroup'),
('Functie', 'ProjectFunction'),
('Type', 'ProjectType'),
('Planningtransport', 'ProjectVehicles'),
('Offerte', 'Quote'),
('Reparatie', 'Repair'),
('Exemplaar', 'SerialNumber'),
('AssetLocation', 'StockLocation'),
('Voorraadmutatie', 'StockMovement'),
('Inhuurmateriaal', 'SubrentalEquipment'),
('Inhuurgroep', 'SubrentalEquipmentGroup'),
('Inhuur', 'Subrental'),
('Uren', 'TimeRegistration'),
('Functieuur', 'TimeRegistrationActivity'),
('Voertuig', 'Vehicle'),
('Afspraakmedewerker', 'AppointmentCrew')
]
word_pairs = [
("Accessoire", "Accessory"),
("Afspraakmedewerker", "AppointmentCrew"),
("Afspraak", "Appointment"),
("Person", "Contactperson"),
("Medewerker", "Crew"),
("Beschikbaarheid", "CrewAvailability"),
("Medewerkertarief", "CrewRates"),
("Materiaal", "Equipment"),
("Setinhoud", "EquipmentSetsContent"),
("Files", "File"),
("Btwbedrag", "InvoiceLines"),
("Factuur", "Invoice"),
("Grootboek", "LedgerCode"),
("Planningpersoneel", "ProjectCrew"),
("Planningmateriaal", "ProjectEquipment"),
("MateriaalCat", "ProjectEquipmentGroup"),
("Functiegroep", "ProjectFunctionGroup"),
("Functie", "ProjectFunction"),
("Type", "ProjectType"),
("Planningtransport", "ProjectVehicles"),
("Offerte", "Quote"),
("Reparatie", "Repair"),
("Exemplaar", "SerialNumber"),
("AssetLocation", "StockLocation"),
("Voorraadmutatie", "StockMovement"),
("Inhuurmateriaal", "SubrentalEquipment"),
("Inhuurgroep", "SubrentalEquipmentGroup"),
("Inhuur", "Subrental"),
("Uren", "TimeRegistration"),
("Functieuur", "TimeRegistrationActivity"),
("Voertuig", "Vehicle"),
("Afspraakmedewerker", "AppointmentCrew"),
]
word_pairs.sort(key=lambda pair: len(pair[0]), reverse=True)
for old_word, new_word in word_pairs:
component_schemas_to_modify = list(api_spec['components']['schemas'].keys())
component_schemas_to_modify = list(api_spec["components"]["schemas"].keys())
for key in component_schemas_to_modify:
value = api_spec['components']['schemas'][key]
value = api_spec["components"]["schemas"][key]
new_key = key.replace(old_word, new_word)
del api_spec['components']['schemas'][key]
api_spec['components']['schemas'][new_key] = value
api_spec['paths']=replace_in_api_spec(api_spec=api_spec['paths'],old_word=old_word,new_word=new_word,key='operationId')
api_spec['paths']=replace_in_api_spec(api_spec=api_spec['paths'],old_word=old_word,new_word=new_word,key='$ref')
del api_spec["components"]["schemas"][key]
api_spec["components"]["schemas"][new_key] = value
api_spec["paths"] = replace_in_api_spec(
api_spec=api_spec["paths"],
old_word=old_word,
new_word=new_word,
key="operationId",
)
api_spec["paths"] = replace_in_api_spec(
api_spec=api_spec["paths"], old_word=old_word, new_word=new_word, key="$ref"
)

# Spezifikation sortiren und speichern
api_spec = sort_api_spec(api_spec)
api_spec_man = sort_api_spec(api_spec_man)
save_api_spec(api_spec, "oas_changed.yml")
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
from typing import Any, Dict, Optional

import httpx

from ...client import Client
from ...models.appointment_crew_collectionget_response_schema import AppointmentCrewCollectiongetResponseSchema
from ...types import Response


def _get_kwargs(
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/appointmentcrew".format(client.base_url)

headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

return {
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
}


def _parse_response(*, response: httpx.Response) -> Optional[AppointmentCrewCollectiongetResponseSchema]:
if response.status_code == 200:
response_200 = AppointmentCrewCollectiongetResponseSchema.from_dict(response.json())

return response_200
return None


def _build_response(*, response: httpx.Response) -> Response[AppointmentCrewCollectiongetResponseSchema]:
return Response(
status_code=response.status_code,
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
)


def sync_detailed(
*,
client: Client,
) -> Response[AppointmentCrewCollectiongetResponseSchema]:
kwargs = _get_kwargs(
client=client,
)

response = httpx.get(
**kwargs,
)

return _build_response(response=response)


def sync(
*,
client: Client,
) -> Optional[AppointmentCrewCollectiongetResponseSchema]:
""" """

return sync_detailed(
client=client,
).parsed


async def asyncio_detailed(
*,
client: Client,
) -> Response[AppointmentCrewCollectiongetResponseSchema]:
kwargs = _get_kwargs(
client=client,
)

async with httpx.AsyncClient() as _client:
response = await _client.get(**kwargs)

return _build_response(response=response)


async def asyncio(
*,
client: Client,
) -> Optional[AppointmentCrewCollectiongetResponseSchema]:
""" """

return (
await asyncio_detailed(
client=client,
)
).parsed
103 changes: 103 additions & 0 deletions rentman_api_client/api/appointmentcrew/appointment_crew_item_get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
from typing import Any, Dict, Optional

import httpx

from ...client import Client
from ...models.appointment_crew_itemget_response_schema import AppointmentCrewItemgetResponseSchema
from ...types import Response


def _get_kwargs(
*,
client: Client,
id: int,
) -> Dict[str, Any]:
url = "{}/appointmentcrew/{id}".format(client.base_url, id=id)

headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

return {
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
}


def _parse_response(*, response: httpx.Response) -> Optional[AppointmentCrewItemgetResponseSchema]:
if response.status_code == 200:
response_200 = AppointmentCrewItemgetResponseSchema.from_dict(response.json())

return response_200
return None


def _build_response(*, response: httpx.Response) -> Response[AppointmentCrewItemgetResponseSchema]:
return Response(
status_code=response.status_code,
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
)


def sync_detailed(
*,
client: Client,
id: int,
) -> Response[AppointmentCrewItemgetResponseSchema]:
kwargs = _get_kwargs(
client=client,
id=id,
)

response = httpx.get(
**kwargs,
)

return _build_response(response=response)


def sync(
*,
client: Client,
id: int,
) -> Optional[AppointmentCrewItemgetResponseSchema]:
""" """

return sync_detailed(
client=client,
id=id,
).parsed


async def asyncio_detailed(
*,
client: Client,
id: int,
) -> Response[AppointmentCrewItemgetResponseSchema]:
kwargs = _get_kwargs(
client=client,
id=id,
)

async with httpx.AsyncClient() as _client:
response = await _client.get(**kwargs)

return _build_response(response=response)


async def asyncio(
*,
client: Client,
id: int,
) -> Optional[AppointmentCrewItemgetResponseSchema]:
""" """

return (
await asyncio_detailed(
client=client,
id=id,
)
).parsed
Loading

0 comments on commit ddb3d8d

Please sign in to comment.