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

Local Reference Fixes 0.9.0 #15

Draft
wants to merge 32 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
720368c
chore(deps): update dependency jinja2 to v3 (#424)
renovate[bot] May 11, 2021
64f67fe
Soften black dependency. (#416)
christhekeele May 12, 2021
e708750
fix: Deserialization of optional nullable properties when no value is…
forest-benchling May 12, 2021
fddf68a
fix(parser): Prevent crash when providing a non-string default to a s…
dbanty May 12, 2021
79acbf8
feat(parser): Allow references to non-object, non-enum types [#371][#…
dbanty May 13, 2021
0f58cfd
chore: Prep 0.9.1 release
dbanty May 13, 2021
588fa23
templates / endpoint_module / form_data: do not use `attr.asdict`, us…
p1-ra May 17, 2021
1b17d1f
e2e / update golden-record
p1-ra May 17, 2021
907208e
templatize api,endpoint init files
Nementon Apr 30, 2021
15c7b13
e2e / add {api_init.py.jina, endpoint_init.py.jinja} custom templates…
p1-ra May 3, 2021
df9ac8a
expose utils module to jinja2
Nementon May 6, 2021
8135d38
test_custom_templates / replace jinja2 marcro with call to utils module
Nementon May 6, 2021
0b43462
task / regen / regen custom template golden record
p1-ra May 3, 2021
074b58d
updated vendored openapi_schema_pydantic / correct oai false negative
Nementon May 12, 2021
1e0620c
vendored openapi_schema_pydantic / correct flake8 warnings
Nementon May 13, 2021
d8c1a9f
correct openapi_schema_pydantic schemas breaking changes
Nementon May 12, 2021
5befdc5
update unit tests
p1-ra May 13, 2021
470be5f
parser / properties / avoid call to isinstance for perf imprv
p1-ra May 13, 2021
b09ebd6
openapi_schema_pydantic / schema / set `nullable` type to `bool`
p1-ra May 13, 2021
e71c4cc
openapi_schema_pydantic / remove ellipsis notation
p1-ra May 13, 2021
2902c21
openapi_schema_pydantic / allow extra values
p1-ra May 13, 2021
59b6e5e
openapi_schema_pydantic / correct typing
p1-ra May 13, 2021
9371b1b
openapi_schema_pydantic / schema / {any,all,one}Of default to `List.E…
p1-ra May 13, 2021
0d66065
parser / schemas / add indirect reference resolution
p1-ra May 7, 2021
58fa3de
e2e / update `openapi.json` and golden-record
p1-ra May 7, 2021
4d67fe5
parser / property / add recursive reference resoltion
p1-ra May 8, 2021
f4d7ff0
e2e / update `openapi.json` and golden-record
p1-ra May 8, 2021
3667232
parser / properties / do not restrict reference pointer type to `enum…
Nementon May 7, 2021
f46d1e6
e2e / update `openapi.json` and golden-record
Nementon May 7, 2021
6d4416d
tpl / model / add missing typing import: `Tuple,Optional,BinaryIO,Tex…
Nementon May 7, 2021
c8abe92
parser / property / correct recursive ref detection logic
p1-ra May 18, 2021
c396e4e
disabled recursive recursion detection, does not properly works
p1-ra May 19, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.9.1

### Features

- Allow references to non-object, non-enum types [#371][#418][#425]. Thanks @p1-ra!
- Allow for attrs 21.x in generated clients [#412]
- Allow for using any version of Black [#416] [#411]. Thanks @christhekeele!

### Fixes

- Prevent crash when providing a non-string default to a string attribute. [#414] [#415]
- Deserialization of optional nullable properties when no value is returned from the API [#420] [#381]. Thanks @forest-benchling!

## 0.9.0 - 2021-05-04

### Breaking Changes
Expand Down Expand Up @@ -45,9 +58,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- `none` will not create a project folder at all, only the inner package folder (which won't be inner anymore)

- Attempt to detect and alert users if they are using an unsupported version of OpenAPI (#281).

- The media type application/vnd.api+json will now be handled just like application/json (#307). Thanks @jrversteegh!

- Support passing models into query parameters (#316). Thanks @forest-benchling!

- Add support for cookie parameters (#326).

- New `--file-encoding` command line option (#330). Sets the encoding used when writing generated files (defaults to utf-8). Thanks @dongfangtianyu!

### Changes
Expand Down Expand Up @@ -96,13 +113,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Breaking Changes

- Any request/response field that is not `required` and wasn't specified is now set to `UNSET` instead of `None`.

- Values that are `UNSET` will not be sent along in API calls

- Schemas defined with `type=object` will now be converted into classes, just like if they were created as ref components. The previous behavior was a combination of skipping and using generic Dicts for these schemas.

- Response schema handling was unified with input schema handling, meaning that responses will behave differently than before. Specifically, instead of the content-type deciding what the generated Python type is, the schema itself will.

- As a result of this, endpoints that used to return `bytes` when content-type was application/octet-stream will now return a `File` object if the type of the data is "binary", just like if you were submitting that type instead of receiving it.

- Instead of skipping input properties with no type, enum, anyOf, or oneOf declared, the property will be declared as `None`.

- Class (models and Enums) names will now contain the name of their parent element (if any). For example, a property declared in an endpoint will be named like {endpoint*name}*{previous*class*name}. Classes will no longer be deduplicated by appending a number to the end of the generated name, so if two names conflict with this new naming scheme, there will be an error instead.

### Additions
Expand Down Expand Up @@ -268,6 +289,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Changes

- The way most imports are handled was changed which _should_ lead to fewer unused imports in generated files.

- Better error messages

- Most error messages will contain some useful information about why it failed instead of a stack trace
Expand Down
6 changes: 3 additions & 3 deletions dobby.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[[workflows]]
name = "Start Task"
name = "task"
[[workflows.steps]]
type = "SelectGitHubIssue"

[[workflows.steps]]
type = "SwitchBranches"

[[workflows]]
name = "Prepare Release"
name = "release"
[[workflows.steps]]
type = "UpdateProjectFromCommits"

[[workflows.steps]]
type = "Command"
command = "prettier --write CHANGELOG.md"
command = "npx prettier --write CHANGELOG.md"

[github]
owner = "triaxtec"
Expand Down
1 change: 1 addition & 0 deletions end_to_end_tests/custom-templates-golden-record/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
my-test-api-client
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
""" Contains methods for accessing the API """

from typing import Type

from my_test_api_client.api.default import DefaultEndpoints
from my_test_api_client.api.parameters import ParametersEndpoints
from my_test_api_client.api.tests import TestsEndpoints


class MyTestApiClientApi:
@classmethod
def tests(cls) -> Type[TestsEndpoints]:
return TestsEndpoints

@classmethod
def default(cls) -> Type[DefaultEndpoints]:
return DefaultEndpoints

@classmethod
def parameters(cls) -> Type[ParametersEndpoints]:
return ParametersEndpoints
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
""" Contains methods for accessing the API Endpoints """

import types

from my_test_api_client.api.default import get_common_parameters, post_common_parameters


class DefaultEndpoints:
@classmethod
def get_common_parameters(cls) -> types.ModuleType:
return get_common_parameters

@classmethod
def post_common_parameters(cls) -> types.ModuleType:
return post_common_parameters
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
""" Contains methods for accessing the API Endpoints """

import types

from my_test_api_client.api.parameters import get_same_name_multiple_locations_param


class ParametersEndpoints:
@classmethod
def get_same_name_multiple_locations_param(cls) -> types.ModuleType:
return get_same_name_multiple_locations_param
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
""" Contains methods for accessing the API Endpoints """

import types

from my_test_api_client.api.tests import (
defaults_tests_defaults_post,
get_basic_list_of_booleans,
get_basic_list_of_floats,
get_basic_list_of_integers,
get_basic_list_of_strings,
get_user_list,
int_enum_tests_int_enum_post,
json_body_tests_json_body_post,
no_response_tests_no_response_get,
octet_stream_tests_octet_stream_get,
optional_value_tests_optional_query_param,
test_inline_objects,
token_with_cookie_auth_token_with_cookie_get,
unsupported_content_tests_unsupported_content_get,
upload_file_tests_upload_post,
)


class TestsEndpoints:
@classmethod
def get_user_list(cls) -> types.ModuleType:
"""
Get a list of things
"""
return get_user_list

@classmethod
def get_basic_list_of_strings(cls) -> types.ModuleType:
"""
Get a list of strings
"""
return get_basic_list_of_strings

@classmethod
def get_basic_list_of_integers(cls) -> types.ModuleType:
"""
Get a list of integers
"""
return get_basic_list_of_integers

@classmethod
def get_basic_list_of_floats(cls) -> types.ModuleType:
"""
Get a list of floats
"""
return get_basic_list_of_floats

@classmethod
def get_basic_list_of_booleans(cls) -> types.ModuleType:
"""
Get a list of booleans
"""
return get_basic_list_of_booleans

@classmethod
def upload_file_tests_upload_post(cls) -> types.ModuleType:
"""
Upload a file
"""
return upload_file_tests_upload_post

@classmethod
def json_body_tests_json_body_post(cls) -> types.ModuleType:
"""
Try sending a JSON body
"""
return json_body_tests_json_body_post

@classmethod
def defaults_tests_defaults_post(cls) -> types.ModuleType:
"""
Defaults
"""
return defaults_tests_defaults_post

@classmethod
def octet_stream_tests_octet_stream_get(cls) -> types.ModuleType:
"""
Octet Stream
"""
return octet_stream_tests_octet_stream_get

@classmethod
def no_response_tests_no_response_get(cls) -> types.ModuleType:
"""
No Response
"""
return no_response_tests_no_response_get

@classmethod
def unsupported_content_tests_unsupported_content_get(cls) -> types.ModuleType:
"""
Unsupported Content
"""
return unsupported_content_tests_unsupported_content_get

@classmethod
def int_enum_tests_int_enum_post(cls) -> types.ModuleType:
"""
Int Enum
"""
return int_enum_tests_int_enum_post

@classmethod
def test_inline_objects(cls) -> types.ModuleType:
"""
Test Inline Objects
"""
return test_inline_objects

@classmethod
def optional_value_tests_optional_query_param(cls) -> types.ModuleType:
"""
Test optional query parameters
"""
return optional_value_tests_optional_query_param

@classmethod
def token_with_cookie_auth_token_with_cookie_get(cls) -> types.ModuleType:
"""
Test optional cookie parameters
"""
return token_with_cookie_auth_token_with_cookie_get
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from typing import Any, Dict

import httpx

from ...client import Client
from ...models.a_form_data import AFormData
from ...types import Response


def _get_kwargs(
*,
client: Client,
form_data: AFormData,
) -> Dict[str, Any]:
url = "{}/tests/post_form_data".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(),
"data": form_data.to_dict(),
}


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


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

response = httpx.post(
**kwargs,
)

return _build_response(response=response)


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

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

return _build_response(response=response)
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
""" Contains all the data models used in inputs/outputs """

from .a_form_data import AFormData
from .a_model import AModel
from .a_model_with_properties_reference_that_are_not_object import AModelWithPropertiesReferenceThatAreNotObject
from .a_model_with_indirect_reference_property import AModelWithIndirectReferenceProperty
from .a_model_with_indirect_self_reference_property import AModelWithIndirectSelfReferenceProperty
from .a_model_with_properties_reference_that_are_not_object import AModelWithPropertiesReferenceThatAreNotObject
from .all_of_sub_model import AllOfSubModel
from .an_all_of_enum import AnAllOfEnum
from .an_enum import AnEnum
Expand Down
Loading