-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat: Add support for handling refs within OpenAPI path items #276
Conversation
src/projen/rest-api.ts
Outdated
@@ -43,10 +48,10 @@ export class RestApi extends pj.Component { | |||
} | |||
} | |||
} | |||
if (!fs.existsSync('./src/generated')) { | |||
fs.mkdirSync('./src/generated'); | |||
if (!fs.existsSync(`${this.project.outdir}/src/generated`)) { |
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.
Love it
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.
Oh, completely forgot to mention this! I stumbled over these hardcoded paths when writing unit tests. I hope this doesn't break something else!
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.
Will check
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.
Datastore and GraphQL aspects share the same relative paths, my gut says if it breaks something, I'd rather fix that than leave the old paths, even if currently unit testing was the first time I ran into problems with this.
Thanks I will review it and merge it afterwards |
Oh, another thing I forgot: The Shouldn't matter, but as this is adapted from a copypaste from another project, I feel obligated to mention this. |
@DerDackel please rebase onto merged PR #277 |
ba9a01d
to
55ce731
Compare
Done! |
Fixes a bug due to a recently addressed gap in the OpenAPI spec implementation of openapi-typescript where refs to path items within the
paths
section of the API defnition weren't supported. This resulted in a type signature change on openapi-typescriptsPathsObject
that broke the RestApi projen aspect.I took the liberty of adding some error handling for processing malformed OpenAPI definitions (read below), so some definitions where older versions of cdk-serverless would have ignored e.g. invalid refs will now throw an error upon project synthesiziation.
Project won't compile with recent versions of openapi-typescript due to a type signature change in the dependency.
Current behavior would alreadys have guarded against accidentally creating superfluous lambdas for refs otherwise as the RestApi component only follows paths in the definition where the child has keys that correspond to the keys of a
PathItemObject
.Refs introduce two error states though: Cyclical refs and refs to nonexistant or malformed nodes in the definition. Currently openapi-typescript will terminate on cyclical references to avoid endless loops, but will gladly generate types that reference paths that don't exist, or that are not path items at all. This might probably occur in other parts of the code generation too.
While someone can probably come up with a case that can hack this into some nifty feature, I couldn't and would personally prefer it the synthesizer stops and delivers a specific error rather than wondering what the type checker is complaining about. So I have the RestApi component check whether any path item refs in the definition file point to valid path items. Cycle checks are a required necessity for this.
If this behavior is explicitly not desired, please close this and I'll submit a minimal fix to satisfy the compiler as a new PR.
cdk-serverless will compile again with newer versions of openapi-typescript. Runtime behavior will now throw errors upon encountering OpenAPI definitions with invalid or cyclical path item references.
No API changes were introduced, but abovementioned changes may affect existing projects making use of existing unspecified/error-tolerant behavior.
This will hopefully be enough to make cdk-serverless build again with updated dependencies