Skip to content

Commit

Permalink
openapi - rename media type objects
Browse files Browse the repository at this point in the history
  • Loading branch information
commonism committed Oct 24, 2023
1 parent c896c9a commit 308dac1
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions aiopenapi3/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ def is_schema(v: Tuple[str, "SchemaType"]) -> bool:
schema = parameter.schema_._target
else:
schema = parameter.schema_
assert schema is not None
name = schema._get_identity("I2", f"{path}.{m}.{parameter.name}")
byname[name] = schema
else:
Expand All @@ -514,22 +515,22 @@ def is_schema(v: Tuple[str, "SchemaType"]) -> bool:
byname[name] = schema

if op.requestBody:
for content_type, request in op.requestBody.content.items():
if request.schema_ is None:
for mt, mto in op.requestBody.content.items():
if mto.schema_ is None:
continue
byname[request.schema_._get_identity("B")] = request.schema_
byname[mto.schema_._get_identity("B")] = mto.schema_

for r, response in op.responses.items():
if isinstance(response, ReferenceBase):
response = response._target
if isinstance(response, (v30.paths.Response, v31.paths.Response)):
assert response.content is not None
for c, content in response.content.items():
if content.schema_ is None:
for mt, mto in response.content.items():
if mto.schema_ is None:
continue
if isinstance(content.schema_, (v30.Schema, v31.Schema)):
name = content.schema_._get_identity("I2", f"{path}.{m}.{r}.{c}")
byname[name] = content.schema_
if isinstance(mto.schema_, (v30.Schema, v31.Schema)):
name = mto.schema_._get_identity("I2", f"{path}.{m}.{r}.{mt}")
byname[name] = mto.schema_
else:
raise TypeError(f"{type(response)} at {path}")

Expand All @@ -538,10 +539,10 @@ def is_schema(v: Tuple[str, "SchemaType"]) -> bool:
for responses in map(lambda x: x.responses, components):
assert responses is not None
for rname, response in responses.items():
for content_type, media_type in response.content.items():
if media_type.schema_ is None:
for mt, mto in response.content.items():
if mto.schema_ is None:
continue
byname[media_type.schema_._get_identity("R")] = media_type.schema_
byname[mto.schema_._get_identity("R")] = mto.schema_

byname = self.plugins.init.schemas(initialized=self._root, schemas=byname).schemas
return byname
Expand Down

0 comments on commit 308dac1

Please sign in to comment.