Browse Source

Merge branch 'dev' into 'master'

Release 0.2.4:

See merge request Hares-Lab/openapi-parser!11
master v0.2.4
Peter Zaitcev 6 months ago
parent
commit
a53017f948
2 changed files with 13 additions and 6 deletions
  1. + 1
    - 1
      src/openapi_parser/__init__.py
  2. + 12
    - 5
      src/openapi_parser/exporter/client_writer.py

+ 1
- 1
src/openapi_parser/__init__.py

@ -8,7 +8,7 @@ __title__ = 'openapi-parser'
__author__ = 'Peter Zaitcev / USSX Hares'
__license__ = 'BSD 2-clause'
__copyright__ = 'Copyright 2020 Peter Zaitcev'
__version__ = '0.2.3'
__version__ = '0.2.4'
VersionInfo = namedtuple('VersionInfo', 'major minor micro releaselevel serial')
version_info = VersionInfo(*__version__.split('.'), releaselevel='alpha', serial=0)

+ 12
- 5
src/openapi_parser/exporter/client_writer.py

@ -58,7 +58,7 @@ class ClientWriter(HeaderWriter, InspectWriter, MethodWriter, FooterWriter):
yield from self.objects_to_from_imports(imports)
yield from other_imports
def parse_server_data(self, client_name: str, servers: List[ModelServer]) -> Option[Tuple[str, Iterator[str]]]:
def parse_server_data(self, client_name: str, servers: List[ModelServer]) -> Option[Tuple[str, str, Iterator[str]]]:
servers = [ s for s in servers if (s.url != '/') ]
if (not servers):
return OptionNone
@ -78,7 +78,7 @@ class ClientWriter(HeaderWriter, InspectWriter, MethodWriter, FooterWriter):
yield f'{s_name} = {s.url!r}'
yield
return Some((f'{enum_name}.{default_server_name}' , _gen()))
return Some((enum_name, f'{enum_name}.{default_server_name}', _gen()))
def dump_security_schema(self, security_schema: ModelSecurityScheme, *, flow: Optional[OAuthFlowsType] = None) -> Iterator[str]:
method_name = self.method_name_pretty(f'provide_{security_schema.name}_authorization')
@ -199,7 +199,8 @@ class ClientWriter(HeaderWriter, InspectWriter, MethodWriter, FooterWriter):
logger_name = f'{parser.name}.client'
self.export(client_name)
default_server, enum_gen = tuple_transform(self.parse_server_data(client_name, parser.metadata.servers), 2)
enum_name, default_server, enum_gen = tuple_transform(self.parse_server_data(client_name, parser.metadata.servers), 2)
server_type = enum_name.map('Union[{}, str]'.format).get_or_else('str')
if (enum_gen.non_empty):
yield from enum_gen.get
@ -207,13 +208,19 @@ class ClientWriter(HeaderWriter, InspectWriter, MethodWriter, FooterWriter):
with self.indent():
yield from self.smart_description(partial(self.generate_item_description, item=parser.metadata.info, item_type='client'))
yield 'server: str'
yield f'server: {server_type}'
yield f'logger_name: str = {logger_name!r}'
yield f'model_encoder: Type[IEncoder] = {self.ref_name_pretty(FilteringJsonEncoder)}'
yield
yield from self.write_method_head('__init__', params=[ "server: str" + default_server.map(' = {}'.format).get_or_else('') ], method_type=MethodType.RegularMethod)
yield from self.write_method_head('__init__', params=[ self.join_attribute('server', Some(server_type), default_server) ], method_type=MethodType.RegularMethod)
with self.indent():
if (enum_name.non_empty):
yield f'if (isinstance(server, {enum_name.get})):'
with self.indent():
yield 'server = server.value'
yield
code = \
"""
super().__init__()

Loading…
Cancel
Save