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
Nested object #116
Nested object #116
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good!
I think that traversing the tree within a State
is definitely the way to go.
I think the implementation could be made more efficient by adding more information in the state though. And I also have a question about some corner cases.
src/test/scala/higherkindness/skeuomorph/openapi/NestedObjectSpecification.scala
Show resolved
Hide resolved
src/main/scala/higherkindness/skeuomorph/openapi/Optimize.scala
Outdated
Show resolved
Hide resolved
src/main/scala/higherkindness/skeuomorph/openapi/Optimize.scala
Outdated
Show resolved
Hide resolved
src/main/scala/higherkindness/skeuomorph/openapi/Optimize.scala
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks Beni :)
Objective
You can find, the objectives for all these PRs here: https://github.com/47deg/marlow/issues/188
Problem
Open api spec is based on Yaml/Json to define types, this means that not all the types have a name. You can inline objects if you want to. However, this can create a problematic situation when the objects are nested inside the Yaml/Json tree. Let's look at an example when
Person
is inline inside aOwner
.However, when we generate code, we can create the following situations:
As we can see this code is not valid scala code, then we need to figure out a way to extract these nested objects from the json/yaml tree. Ideally, we should try to generate the following code:
We need to apply this solution to the schemas itself (
T
) and to thecomponents
,requestBody
andresponses
in the OpenApi Tree.Solution
In order to solve this, we have created the following entry functions to avoid the problem described above:
NestedObjectSpecification
for more details):NestedTypesState
is type used to accumulate the(String, T)
we find (e.g.Person
) and with a counter to avoid duplicated types (anonymous or not). At the end of the execution ofNestedTypesState
we should incorporate all the new schemas found into#/components/schemas
.OpenApiNestedObjectSpecification
for more details):Previous PRs