-
Notifications
You must be signed in to change notification settings - Fork 12
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
[#174730128] Test cases for external definitions #197
Conversation
Affected stories
Generated by 🚫 dangerJS |
Codecov Report
@@ Coverage Diff @@
## master #197 +/- ##
===========================================
+ Coverage 46.85% 70.66% +23.81%
===========================================
Files 1 10 +9
Lines 254 450 +196
Branches 81 153 +72
===========================================
+ Hits 119 318 +199
+ Misses 133 124 -9
- Partials 2 8 +6
Continue to review full report at Codecov.
|
…utils into 174730128-extenal-definitions
In the end, is this a bug or a feature? I think it's good enough for what we need at the moment, there are some caveats but the behaviour is pretty straightforward. I think it would be unnecessarily complicated for now. |
thank you for the in-depth analysis! AFAIK
is an attempt I've made without success. I think we can proceeed as we're used to, probably we can add warnings (logs) in the parsing procedure (ie. "Type X looks like an external unresolved reference, add it to the specs if you want to resolve it inline") during gen-api-models |
I don't think it's feasible, the parsing mechanism happens in a black-box and we can tell nothing from the result. |
Running e2e tests over the example definitions, I discovered a limitation on the generator. When a transient definition is a composition (that is, it uses As this is not crucial for the demonstration this PR is pursued to, I'd just choose another example. Therefore, I commit to provide another use-case to show such limitation. |
nice job! If I understand well, the same workaround will suffice even in the case of a composed transient definition (define the deps in the original doc) |
Not sure I got the question right but: |
This PR investigates how external definitions are resolved when an OpenAPI spec file is parsed by
swagger-parser
library before they result into generated typescript model definitions.While using
gen-api-models
command in the wild is sometimes counter-intuitive how definitions will end in our generated codebase. The purpose of this is to provide a rationale for what's happening under the hood.Example
For the sake of talking about near-real scenarios, we consider the following definition dependency graph:
dependency diagram
spec.yaml
definitions.yaml
Glossary
To better explain myself we need to be on the same page:
Address
andZipCode
.Rules
OpenAPIV2.SchemaObject
(and consequently in the generated typescript model).OpenAPIV2.SchemaObject
which represents its root definition. The name of the transient definition is lost in the parsed schema object.Takeaways
Person
andBook
will be created; properties ofAddress
andZipCode
will be included inPerson
's definition;Book
'sauthor
field will contain aisDead
field and a reference toPerson
.OpenAPIV2.SchemaObject
for A will only contain the name of B.OpenAPIV2.SchemaObject
for A will only contain the properties of B, and the name B will be lost.