Skip to content

Commit

Permalink
fix: Fixed order of arguments in methods
Browse files Browse the repository at this point in the history
  • Loading branch information
micmurawski committed Jul 15, 2024
1 parent a89d5ad commit b2f9587
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 77 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ OSDUAPI.print_available_services()
```

```bash
| Name | versions |
| Name | Versions |
===================================
| dataset | latest |
| entitlements | latest |
Expand Down
23 changes: 9 additions & 14 deletions gen/client_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

from .helpers import get_path, get_server_url, load_swagger
from .swagger import SwaggerDoc
import xml.etree.ElementTree as ET


BASE_DIR = os.path.dirname(__file__)

Expand Down Expand Up @@ -87,6 +85,8 @@ def get_type_for_param(param: dict, swagger: dict | None = None) -> str:
types.append(
COMPLEX_TYPES_MAP[(_type, items_type)]
)
if len(types) == 1:
return types[0]
return "Union[%s]" % ", ".join(types)

while ref_path or all_of:
Expand Down Expand Up @@ -327,12 +327,8 @@ def get_name_from_name_map(method: str, path: str, method_names_file: str):


def create_method_name(method: str, path: str, name_parts: list[str], swagger: dict, method_names_file: str) -> str:
# try:
summary = swagger["paths"][path][method].get("summary")
description = swagger["paths"][path][method].get("description", "")
# except TypeError as e:
# print(name_parts, path)
# raise e
name = get_name_from_name_map(method, path, method_names_file)

if name:
Expand Down Expand Up @@ -562,24 +558,23 @@ def create_method_sig(swagger: dict, name: str, params: list[str], body_required
]
elements = [name, ]
sig = ""
_input_parameters_strings = []


_input_parameters_strings += [param_to_function_argument(p)
for p in sorted(path_params, key=lambda x: 0 if x.get("required") else 1)]
if body_not_required:
_input_parameters_strings += parse_request_body(swagger, body_not_required)
_input_parameters_strings = [param_to_function_argument(p)
for p in path_params]

if body_required:
_input_parameters_strings += parse_request_body(swagger, body_required)

if body_not_required:
_input_parameters_strings += parse_request_body(swagger, body_not_required)

if _input_parameters_strings:
sig += ", ".join(_input_parameters_strings)

if sig:
elements.append(sig)

doc = generate_doc_string(name, path_params, body_required, body_not_required, swagger, method, path, indent_offset=1)
doc = generate_doc_string(name, path_params, body_required, body_not_required,
swagger, method, path, indent_offset=1)
try:
if len(elements) > 1:
sig = "def %s(self, *, %s, data_partition_id: str | None = None) -> dict:" % tuple(elements)
Expand Down
2 changes: 1 addition & 1 deletion gen/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import os
import sys
import re
import sys
from subprocess import PIPE, Popen
from typing import Any

Expand Down
12 changes: 10 additions & 2 deletions osdu_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ def client(service_name, auth_backend: AuthBackendInterface, version: str | None

@classmethod
def print_available_services(cls):
print("| Name | versions |")
"""
Prints available services for client
"""
print("| Name | Versions |")
print("===================================")
for k, v in cls.list_available_services():
print("|", end="")
Expand All @@ -73,6 +76,11 @@ def print_available_services(cls):
print("|")

@staticmethod
def list_available_services() -> list[str, list[str]]:
def list_available_services() -> list[tuple[str, list[str]]]:
"""
Returns list of available services for client
Returns:
list of available services for API versions (list[tuple[str, list[str]]])
"""
module = import_module("osdu_client.services")
return [(k, v) for k, v in module.SERVICES.items()]
2 changes: 1 addition & 1 deletion osdu_client/services/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from osdu_client.services import (rafs, wellbore)
from osdu_client.services import rafs, wellbore

SERVICES = {
"dataset": [],
Expand Down
6 changes: 3 additions & 3 deletions osdu_client/services/file/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from osdu_client.utils import urljoin
from osdu_client.validation import validate_data

from .models import DeliveryGetFileSignedURLRequest, FileListRequest, FileLocationRequest, LocationRequest, Record
from .models import FileListRequest, FileLocationRequest, LocationRequest, Record, DeliveryGetFileSignedURLRequest


class FileAPIError(OSDUAPIError):
Expand Down Expand Up @@ -81,12 +81,12 @@ def get_files_upload_url(self, data_partition_id: str | None = None) -> dict:
def create_files_metadata(
self,
*,
id: str | None = None,
ancestry: dict | None = None,
kind: str,
acl: dict,
legal: dict,
data: dict,
id: str | None = None,
ancestry: dict | None = None,
data_partition_id: str | None = None,
) -> dict:
"""
Expand Down
2 changes: 1 addition & 1 deletion osdu_client/services/indexer/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def reindex_kind(
self,
*,
force_clean: str | None = None,
cursor: str | None = None,
kind: str,
cursor: str | None = None,
data_partition_id: str | None = None,
) -> dict:
"""
Expand Down
Loading

0 comments on commit b2f9587

Please sign in to comment.