Skip to content
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

Add support for common parameters for resources and data sources #114

Merged
merged 2 commits into from
Jan 16, 2024

Conversation

randomswdev
Copy link
Contributor

The current parameters overriding logic has two flaws:

  1. The openapi specification allows to define "Common Parameters" for a path, that apply to all the operations (GET, PUT, ...). The openapi generator do not consider these parameters, but only the ones explicitly specified in an operation.
  2. It is currently impossible to associate a parameter to a nested attribute, like for example the name parameter of a kubernetes resource to the metadata.name attribute.

This pull request attempts to address both these issues.

@randomswdev randomswdev requested a review from a team as a code owner January 3, 2024 21:02
Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

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

Hey there @randomswdev 👋🏻, this is awesome, thanks for opening the PR!

After a quick glance, I have a couple of small tweaks for the PR itself, but before I do a review, I'd prefer if we could split this PR into multiple PRs so the two issues noted in your description can be reviewed/discussed independently.

As you'll see below, I think the common parameters issue is pretty cut and dry, but I need some clarification on the "overriding nested attributes with parameters" issue that I think would be best discussed first in a GitHub issue before opening a PR.

Common Parameters

I'll open a GH issue for this one (#115), just for reference, however I don't think there is too much to discuss around the solution.

Your PR changes makes sense to me, the only real tweak I think we could make is supporting operations being able to override parameters with the same name/location from a common parameter, as described in the specification:

parameters - A list of parameters that are applicable for all the operations described under this path. These parameters can be overridden at the operation level, but cannot be removed there. The list MUST NOT include duplicated parameters. A unique parameter is defined by a combination of a name and location.

Might need to decide what best to do if a path parameter name is the same as a query parameter name, as that would result in a duplicate attribute.

Parameters overriding nested attributes

Before accepting a PR, I'd like to understand a little more about this issue, perhaps with an example OpenAPI spec and expected output. This would best be discussed in a GH issue if you wouldn't mind opening one.

Specifically I have some questions about the solution, which could be discussed in that issue:

  • Reading through the PR it seems that in order for a parameter name to match a nested attribute, it would need to be adjusted in the OpenAPI spec with the dot-separated syntax.
    • Is this dot-syntax documented in the OpenAPI specification somewhere?
    • You mentioned a kubernetes example (would be great to include this in the GH issue) with name mapping to metadata.name. For a path parameter it might be okay to name the actual parameter metadata.name, since it's not included in the API URL, but I'd imagine a query parameter wouldn't be able to utilize this dot-syntax. Perhaps we could support an extension to the parameter object to indicate the mapping to support both types of parameters?

General contributing notes

Apologies that this repo doesn't have a CONTRIBUTING.MD that describes what we're looking for, but your PR will need:

  • A changelog, we use changie, which you can figure out how we use it from one of our other repositories CONTRIBUTING.md.
  • Unit tests and/or an acceptance test that cover the changes implemented
    • This repo has a set of golden testdata files that can be generated with make testdata. There are e2e tests that use actual OpenAPI specifications (including kubernetes), if you think there is an applicable example that covers your feature, feel free to add a test this way.
    • There are also more "integration tests" for the resource/datasource/provider mappers if you can't find an example in one of the testdata OpenAPI specs.
    • Then there are unit tests for the more single-purpose Go code like the config_explorer
    • e2e, integration, and unit tests all run via the standard go test command
  • Any documentation updates I can help identify and submit those, as most of our documentation lives in another repo 😄

If you're not 100% sure about the changelogs or what tests to add, I can help with that, just let me know!

@austinvalle austinvalle added this to the v0.3.0 milestone Jan 4, 2024
@austinvalle austinvalle added the enhancement New feature or request label Jan 4, 2024
@randomswdev randomswdev force-pushed the main branch 2 times, most recently from 334f285 to 3a68def Compare January 5, 2024 18:04
@randomswdev
Copy link
Contributor Author

Hi @austinvalle I simplified the pull request, keeping only the changes required for supporting Common Parameters. I added some tests for the new methods.

What do I have to do for the changelog and the docemantation?

@randomswdev
Copy link
Contributor Author

randomswdev commented Jan 5, 2024

@austinvalle

As you'll see below, I think the common parameters issue is pretty cut and dry, but I need some clarification on the "overriding nested attributes with parameters" issue that I think would be best discussed first in a GitHub issue before opening a PR.

I just opened an issue describing the problem and plan to submit later today a pull request containing just the related changes.
The issue is: #117

Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

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

Thanks for separating those two PRs and adding the tests @randomswdev!

Overall this PR is looking good, just left some feedback around naming and test separation.

internal/explorer/config_explorer.go Outdated Show resolved Hide resolved
internal/explorer/config_explorer.go Outdated Show resolved Hide resolved
internal/explorer/explorer.go Outdated Show resolved Hide resolved
internal/explorer/explorer_utils.go Outdated Show resolved Hide resolved
internal/explorer/config_explorer.go Outdated Show resolved Hide resolved
internal/explorer/eplorer_utils_test.go Outdated Show resolved Hide resolved
internal/explorer/eplorer_utils_test.go Outdated Show resolved Hide resolved
internal/explorer/eplorer_utils_test.go Outdated Show resolved Hide resolved
@austinvalle austinvalle changed the title Support global parameters and overriding nested attributes Add support for common parameters for resources and data sources Jan 9, 2024
@austinvalle
Copy link
Member

Another note, the kubernetes spec was incorrectly not apart of the test suite, which I just added back in #121.

Your changes will likely update that golden file, so you'll want to run make testdata and commit the changes to your PR 👍🏻

@randomswdev
Copy link
Contributor Author

@austinvalle I should have addressed all the review comments. Let me know if additional changes are required.

Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for making the changes! 🚀

@austinvalle austinvalle merged commit 8425855 into hashicorp:main Jan 16, 2024
4 checks passed
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants