Skip to content

Commit

Permalink
0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Hallett committed Jul 25, 2023
1 parent 7bbcb31 commit 80b1be1
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

- Use [pydantic settings](https://docs.pydantic.dev/latest/usage/pydantic_settings/) for settings management in the `constants.py` file. This is a **breaking change** and you will need to delete your `constants.py` file.

## 0.3.1

- Fixes a bug when generating HTTP Authentication schema.
- Fixes a bug when generating input classes for post functions, when the input schema doesn't exist yet.
- Generates pythonic function names in clients now, always (like `lower_case_snake_case`).

## 0.3.0

- Now generates a `MANIFEST` file with information about the build versions
Expand Down
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change log

## 0.3.1

- Fixes a bug when generating HTTP Authentication schema.
- Fixes a bug when generating input classes for post functions, when the input schema doesn't exist yet.
- Generates pythonic function names in clients now, always (like `lower_case_snake_case`).

## 0.3.0

- Now generates a `MANIFEST` file with information about the build versions
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "clientele"
version = "0.3.0"
version = "0.3.1"
description = "Typed API Clients from OpenAPI schemas"
authors = ["Paul Hallett <paulandrewhallett@gmail.com>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/generators/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def generate_post_content(self, operation: Dict, path: str) -> None:
if not operation.get("requestBody"):
input_class_name = "None"
else:
input_class_name = self.generate_input_types(operation.get("requestBody"))
input_class_name = self.generate_input_types(operation.get("requestBody", {}))
function_arguments = self.generate_function_args(
operation.get("parameters", [])
)
Expand Down
3 changes: 2 additions & 1 deletion src/generators/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
console = Console()

BEARER_CLIENT = """
headers = dict(Authorization=f'Bearer {c.get_bearer_token()}')
auth_key = c.get_bearer_token()
headers = dict(Authorization=f'Bearer ' + auth_key)
client = httpx.{client_type}(headers=headers)
"""

Expand Down
7 changes: 3 additions & 4 deletions src/generators/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ def generate_class_properties(self, properties: Dict) -> str:
return content

def generate_input_class(self, schema: Dict) -> None:
for _, schema_details in schema.items():
content = schema_details["content"]
if content := schema.get("content"):
for encoding, input_schema in content.items():
class_name = ""
if ref := input_schema["schema"].get("$ref", False):
Expand All @@ -69,12 +68,12 @@ def generate_input_class(self, schema: Dict) -> None:
properties = self.generate_class_properties(
input_schema["schema"].get("properties", {})
)
content = f"""
out_content = f"""
class {class_name}(BaseModel):
{properties if properties else " pass"}
"""
write_to_schemas(
content,
out_content,
output_dir=self.output_dir,
)

Expand Down
2 changes: 1 addition & 1 deletion src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

TEMPLATE_ROOT = dirname(dirname(abspath(__file__))) + "/src/template/"
CONSTANTS_ROOT = dirname(dirname(abspath(__file__))) + "/src/"
VERSION = "0.3.0"
VERSION = "0.3.1"
17 changes: 14 additions & 3 deletions src/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import Dict


Expand Down Expand Up @@ -41,11 +42,21 @@ def clean_prop(input_str: str) -> str:
return input_str


def _split_upper(s):
return "_".join(re.findall(".[^A-Z]*", s))


def _snake_case(s):
for badchar in ["/", "-", "."]:
s = s.replace(badchar, "_")
s = _split_upper(s)
return s.lower()


def get_func_name(operation: Dict, path: str) -> str:
if operation.get("operationId"):
return class_name_titled(operation["operationId"].split("__")[0])
# Probably 3.0.1
return path.replace("/", "_").replace("-", "_")[1:]
return _snake_case(operation["operationId"].split("__")[0])
return _snake_case(path)


def get_type(t):
Expand Down

0 comments on commit 80b1be1

Please sign in to comment.