Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #124 from syastrov/bugfix/123/schema-with-multiple…
Browse files Browse the repository at this point in the history
…-unions

Bugfix: schema generation outputted references rather than primitives
  • Loading branch information
seandstewart authored Aug 10, 2020
2 parents a7379b8 + c3bf776 commit 45557bb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
7 changes: 7 additions & 0 deletions tests/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ class G:
h: typing.Optional[int] = None


@dataclasses.dataclass
class ThreeOptionals:
a: typing.Optional[str]
b: typing.Optional[str] = None
c: typing.Optional[str] = None


class Class:
var: str

Expand Down
24 changes: 24 additions & 0 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,30 @@ class Container:
definitions=typic.FrozenDict(),
),
),
(
objects.ThreeOptionals,
typic.ObjectSchemaField(
title=objects.ThreeOptionals.__name__,
description=objects.ThreeOptionals.__doc__,
properties=typic.FrozenDict(
a=typic.MultiSchemaField(
title="A",
anyOf=(typic.StrSchemaField(), typic.NullSchemaField()),
),
b=typic.MultiSchemaField(
title="B",
anyOf=(typic.StrSchemaField(), typic.NullSchemaField()),
),
c=typic.MultiSchemaField(
title="C",
anyOf=(typic.StrSchemaField(), typic.NullSchemaField()),
),
),
required=("a",),
additionalProperties=False,
definitions=typic.FrozenDict(),
),
),
(
objects.A,
typic.ObjectSchemaField(
Expand Down
3 changes: 2 additions & 1 deletion typic/ext/schema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ def get_field(
if protocol.annotation in self.__stack:
name = self.defname(protocol.annotation.resolved_origin, name)
return Ref(f"#/definitions/{name}")
self.__stack.add(protocol.annotation)
anno = protocol.annotation
if anno in self.__cache:
return self.__cache[anno]
Expand Down Expand Up @@ -188,6 +187,8 @@ def get_field(
self.__cache[anno] = schema
return schema

self.__stack.add(anno)

# Check if this should be ro/wo
if use in {ReadOnly, WriteOnly, Final}:
ro = (use in {ReadOnly, Final}) or None
Expand Down

0 comments on commit 45557bb

Please sign in to comment.