Skip to content

Inherit parameters from path item to its operations. #530

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

Merged
merged 4 commits into from
Mar 24, 2021

Conversation

henhal
Copy link
Contributor

@henhal henhal commented Mar 18, 2021

A path item may declare common parameters to all operations outside of the operation map.
If this is the case, all operations should inherit those parameters and merge them with
any operation specific parameters.
In case of conflicting parameters, the one defined in the operation has precedence over
path item parameters.

To fix this, operations need a reference to their path item, so modifying the record of operations built during path item parsing to hold { operation, pathItem } objects.

globalParameters?: Record<string, ParameterObject>;
}
): string {
let output = "";

if (operation.parameters) {
output += ` parameters: {\n ${transformParametersArray(operation.parameters, {
if (operation.parameters || pathItem?.parameters) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line seemed to throw ts-jest. If you could rebase off latest main and push again, we should see the tests run.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional chaining is not supported by the current typescript settings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dnalborczyk. But weird, I obviously ran this locally and ts-jest should have used tsconfig.json with the correct transpile options. Could this possibly be related to Node 12 being used in CI while I use Node 14?
But no problem changing it obviously.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question. not quite sure. the test run also failed in the ci with node.js v14: https://github.com/drwpow/openapi-typescript/runs/2141031952 . I'd have to pull your PR with that commit and run it locally as well.

Copy link
Contributor

@dnalborczyk dnalborczyk Mar 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there seems to be a bug in the ci setup: v14.x and v12.x are essentially running node v10.x

image

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in: #539

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for improving this.

@drwpow
Copy link
Contributor

drwpow commented Mar 20, 2021

I think this looks good! But please run the tests locally yourself, and make sure that they’re all passing (and please update any expected/*.ts files, as you’ll very likely find the generation changed for those)


}`);
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great tests! 💯

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The tests obviously did work when I ran this locally, but not in CI for some reason. Checking if removing Node 14 stuff solves it.

@codecov
Copy link

codecov bot commented Mar 23, 2021

Codecov Report

Merging #530 (6e8f517) into main (ca0018d) will increase coverage by 0.12%.
The diff coverage is 83.72%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #530      +/-   ##
==========================================
+ Coverage   84.87%   85.00%   +0.12%     
==========================================
  Files           9        9              
  Lines         324      340      +16     
  Branches      105      110       +5     
==========================================
+ Hits          275      289      +14     
- Misses         46       47       +1     
- Partials        3        4       +1     
Impacted Files Coverage Δ
src/transform/headers.ts 27.27% <50.00%> (-2.73%) ⬇️
src/transform/index.ts 57.40% <50.00%> (+0.80%) ⬆️
src/transform/responses.ts 87.50% <78.57%> (+0.65%) ⬆️
src/transform/paths.ts 92.00% <88.88%> (+0.33%) ⬆️
src/transform/schema.ts 96.92% <90.90%> (-1.47%) ⬇️
src/index.ts 77.77% <100.00%> (+1.30%) ⬆️
src/transform/operation.ts 96.87% <100.00%> (+0.44%) ⬆️
src/transform/parameters.ts 97.50% <100.00%> (+0.06%) ⬆️
src/utils.ts 90.90% <100.00%> (+0.34%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6537a31...6e8f517. Read the comment docs.

@@ -74,3 +74,112 @@ describe("requestBodies", () => {
);
});
});

describe.only("parameters", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 only

Copy link
Contributor

@drwpow drwpow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks for contributing

henhal and others added 4 commits March 24, 2021 16:34
A path item may declare common parameters to all operations outside of the operation map.
If this is the case, all operations should inherit those parameters and merge them with
any operation specific parameters.
In case of conflicting parameters, the one defined in the operation has precedence over
path item parameters.
@drwpow drwpow force-pushed the inherited-path-parameters branch from 32b75a4 to 6e8f517 Compare March 24, 2021 22:44
@drwpow
Copy link
Contributor

drwpow commented Mar 24, 2021

@henhal I rebased your branch and fixed the conflict, but kept everything in your code the same. Hope that’s OK. Wanted to merge this to release soon! 🚀

@drwpow drwpow merged commit 38b9097 into openapi-ts:main Mar 24, 2021
@drwpow
Copy link
Contributor

drwpow commented Mar 24, 2021

@all-contributors please add @henhal for code, test

@allcontributors
Copy link
Contributor

@drwpow

I've put up a pull request to add @henhal! 🎉

@henhal
Copy link
Contributor Author

henhal commented Mar 25, 2021

@drwpow Thanks for rebasing and accepting the PR. 🎈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants