Skip to content

Update generator plugin to support validators #6142

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

Conversation

dagnir
Copy link
Contributor

@dagnir dagnir commented May 29, 2025

Motivation and Context

This commit updates the generation mojo to suppport validators:

  • Add flag for controling whether the validation report is written to disk
  • Build all models to IntermediateModel upfront
  • If a service model targets another for sharing shapes, also pass in the target service IntermedidateModel

Modifications

Testing

Testing report output

$ mvn clean install -P quick -pl :s3
$ cat services/s3/target/generated-sources/sdk/models/validation-report.json
cat: services/s3/target/generated-sources/sdk/models/validation-report.json: No such file or directory
$ mvn clean install -P quick -pl :s3 -DwriteValidationReport=true
$ cat services/s3/target/generated-sources/sdk/models/validation-report.json
{
  "validationEntries" : [ ]
}%

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@dagnir dagnir force-pushed the dongie/shared-models-validation-pt2 branch from b18ecd1 to 692139c Compare May 29, 2025 21:13
This commit updates the generation mojo to suppport validators:

 - Add flag for controling whether the validation report is written to
   disk
 - Build all models to IntermediateModel upfront
 - If a service model targets another for sharing shapes, also pass in
   the target service IntermedidateModel
@dagnir dagnir force-pushed the dongie/shared-models-validation-pt2 branch from 692139c to b910ad2 Compare May 29, 2025 22:24
@dagnir dagnir marked this pull request as ready for review May 29, 2025 22:24
@dagnir dagnir requested a review from a team as a code owner May 29, 2025 22:24
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
50.0% Coverage on New Code (required ≥ 80%)
E Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

IntermediateModel previous = serviceNameToModelMap.put(lowercaseServiceName, model);
if (previous != null) {
String warning = String.format("Multiple service models found with service name %s. Model validation "
+ "will likely be incorrect", lowercaseServiceName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is will likely be incorrect do we have any valid cases where multiple models have same service name , why just warn and not error ?

Copy link
Contributor Author

@dagnir dagnir May 30, 2025

Choose a reason for hiding this comment

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

I can't think of a valid case honestly. I only encountered this in testing when the generator runs for the codegen-generated-classes-test since we have a lot of test models there and some have the same name, and all in the same package, so erroring out in that case is not productive.

The worst case scenario is compilation will just fail in that case so this should be fine. We could consider adding a "skipValidation" flag in the future.

@dagnir dagnir merged commit f981caa into feature/master/codegen-validation May 30, 2025
21 of 22 checks passed
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