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

CLOUDP-271223: Skip conflict when x-xgen-soa-migration is set #243

Merged
merged 23 commits into from
Oct 24, 2024
Merged

Conversation

blva
Copy link
Collaborator

@blva blva commented Oct 8, 2024

Proposed changes

Jira ticket: CLOUDP-271223

No doc diff + duplicated path

➜  cli git:(CLOUDP-271223) ✗ ./bin/foascli merge -b test/data/base_spec.json -e test/data/apiregistry_spec.json --output tes.json
2024/10/08 16:06:56 Detected x-xgen-soa-migration annotation in all operations for path:  /rest/v2/openapi/info
2024/10/08 16:06:56 Skipping conflict for path: /rest/v2/openapi/info
2024/10/08 16:06:56 No doc diff detected for path /rest/v2/openapi/info, merging the paths
2024/10/08 16:06:56 
We silently resolved the conflict with the schemas "OpenApiInfo" because the definition was identical.
2024/10/08 16:06:56 
We silently resolved the conflict with the schemas "info" because the definition was identical.
2024/10/08 16:06:56 
We silently resolved the conflict with the schemas "license" because the definition was identical.
2024/10/08 16:06:56 
We silently resolved the conflict with the schemas "ApiError" because the definition was identical.
2024/10/08 16:06:56 
File was saved in 'tes.json'.

Doc diff + duplicated path

➜  cli git:(CLOUDP-271223) ✗ ./bin/foascli merge -b test/data/base_spec.json -e test/data/apiregistry_spec.json --output tes.json
2024/10/08 17:11:06 Detected x-xgen-soa-migration annotation in all operations for path:  /rest/v2/openapi/info
2024/10/08 17:11:06 Skipping conflict for path: /rest/v2/openapi/info
Error: the path: "/rest/v2/openapi/info" is enabled for merge but it has a diff between the base and external spec. See the diff:
{
  "operations": {
    "modified": {
      "GET": {
        "operationID": {
          "from": "getOpenApiInaafo",
          "to": "getOpenApiInfo"
        }
      }
    }
  }
}
➜  cli git:(CLOUDP-271223) ✗ ./bin/foascli merge -b test/data/base_spec.json -e test/data/apiregistry_spec.json --output tes.json
2024/10/08 17:11:24 Detected x-xgen-soa-migration annotation in all operations for path:  /rest/v2/openapi/info
2024/10/08 17:11:24 Skipping conflict for path: /rest/v2/openapi/info
Error: the path: "/rest/v2/openapi/info" is enabled for merge but the flag to allow docs diff is not supported

Checklist

  • I have signed the MongoDB CLA
  • I have added tests that prove my fix is effective or that my feature works

Further comments

@blva blva marked this pull request as ready for review October 9, 2024 00:20
@blva blva requested a review from a team as a code owner October 9, 2024 00:20
pathDiff, _ = json.MarshalIndent(e.Diff.PathsDiff.Modified[e.Entry], "", " ")
}

return fmt.Sprintf("the path: %q is enabled for merge but it has a diff between the base and external spec. See the diff:\n%s", e.Entry, pathDiff)
Copy link
Collaborator

Choose a reason for hiding this comment

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

could you also provide the two files involved in this mismatch? We have a ticket to improve the error message of a conflict to list also the files that are involved to help investigate the issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

let me do this in another task, so that we can update all the error outputs or else this will grow. maybe we can defer to the ticket you mentioned

external *load.SpecInfo
config *diff.Config
specDiff *diff.Diff
noExtDiff NoExtensionDiff
Copy link
Collaborator

Choose a reason for hiding this comment

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

The name NoExtensionDiff gives fom granted a lot of context on how we use extensions in the spec. Main question from a person without context is what is the difference between specDiff *diff.Diff and noExtDiff NoExtensionDiff?

Question: can we have an interface that includes both specDiff *diff.Diff and noExtDiff NoExtensionDiff as they are both checking differences between specifications

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

starting with decoupling specDiff since we already have an oasdiff result struct in #250

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated!

return nil
}

// allowDocsDiff = true not supported
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you update this comment to add more context: what is allowDocsDiff?, why is not supported? what is the implication in this piece of code?

@@ -417,6 +483,27 @@ func (o OasDiff) areSchemaIdentical(name string) bool {
return !ok
}

// arePathsIdenticalWithExcludeExtensions checks if the paths are identical with the extensions excluded
Copy link
Collaborator

Choose a reason for hiding this comment

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

could you provide an example of the extension in the comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this runs oasdiff with an "ignore extensions" config, I've updated the comment

@@ -417,6 +483,27 @@ func (o OasDiff) areSchemaIdentical(name string) bool {
return !ok
}

// arePathsIdenticalWithExcludeExtensions checks if the paths are identical with the extensions excluded
func (o OasDiff) arePathsIdenticalWithExcludeExtensions(name string) (bool, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

the code seems to be checking if the path are identical with and without extensions 🤔 is this correct? if yes , we should rename the function to reflect this logic

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no, it's excluding extensions from the diff since there will always be Extensions, will update!

Get: &openapi3.Operation{
Extensions: map[string]interface{}{
"x-xgen-soa-migration": map[string]interface{}{
"allowDocsDiff": "true",
Copy link
Collaborator

Choose a reason for hiding this comment

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

if we have AllowDocsDiffNotSupportedError, why allowDocsDiff can be set to true?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think answer is the same as it's a separate ticket to support it (cause initially we were not going to support)

tools/cli/internal/openapi/paths.go Outdated Show resolved Hide resolved
tools/cli/internal/openapi/paths.go Outdated Show resolved Hide resolved
return operation.Extensions[extensionName]
}

func allOperationsAllowDocsDiff(basePath *openapi3.PathItem) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

all of these functions seem to share the logic to check for something in each resource operation. Could you just have a function that runs multiple checks for each operation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

can cover as a follow up as we have many other places in the code where we perform checks for each operation

Copy link
Collaborator

@andreaangiolillo andreaangiolillo 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 all the clarifications!

@blva blva merged commit dbebab7 into main Oct 24, 2024
8 checks passed
@blva blva deleted the CLOUDP-271223 branch October 24, 2024 10:34
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.

2 participants