Skip to content

Contrast Graph API - #159

Open
johnament wants to merge 16 commits into
Contrast-Security-OSS:mainfrom
johnament:contrast-graph-api
Open

Contrast Graph API#159
johnament wants to merge 16 commits into
Contrast-Security-OSS:mainfrom
johnament:contrast-graph-api

Conversation

@johnament

Copy link
Copy Markdown

Summary

  • Adds ContrastGraphApi interface and ContrastGraphApiImpl for the 5 v2 Contrast Graph endpoints served by adr-explorer-aggregator (graph search, incident graph, facets, application libraries, library details)
  • Generates 17 model POJOs from a self-contained contrast-graph.yaml OpenAPI spec via openapi-generator-maven-plugin (models only, okhttp-gson library, dateLibrary=string)
  • Exposes ContrastSDK.graphApi() factory method parallel to the existing scan() factory
  • Adds JSON.java utility (delegates to GsonFactory) required by generated model convenience methods

Notable build changes

  • openapi-generator-maven-plugin 7.9.0 added (models-only, no API stubs)
  • Lombok bumped 1.18.18 → 1.18.30 for JDK 21 annotation processor compatibility
  • jsr305 and javax.annotation-api added as optional compile-scope deps (needed by generated @Nullable / @Generated annotations, not needed at runtime)

Test plan

  • ContrastGraphApiFactoryTest — verifies ContrastSDK.graphApi() returns a ContrastGraphApiImpl instance
  • ContrastGraphApiImplPactTest — 5 Pact consumer contract tests, one per API method, all asserting specific field values
  • Pre-existing CodeArtifactsImplTest / ProjectsImplTest / ScansImplTest failures are a Mockito 3.11.2 + JDK 21 incompatibility that predates this PR — not introduced here

🤖 Generated with Claude Code

johnament and others added 13 commits June 8, 2026 10:06
…eration

- Add openapi-generator-maven-plugin 7.9.0 to sdk/pom.xml generating 16 model
  classes into com.contrastsecurity.sdk.graph from contrast-graph.yaml
- Add jsr305 and javax.annotation-api as provided deps for generated @nullable
  and @generated annotations
- Upgrade Lombok to 1.18.30 for JDK 21 compatibility
- Replace <release>8</release> with <source>/<target> so provided jars are
  visible to the compiler
- Add minimal JSON.java stub providing JSON.getGson() for generated model classes

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…s, GsonFactory delegation

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Make ContrastGraphApiImpl public (class and constructor) so it can be
instantiated from the ContrastSDK.graphApi() factory method. This allows
users to access the Graph API through the main SDK entry point.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Move implementation instantiation to a package-private factory class to enforce encapsulation. Implementation classes should not be directly instantiated outside their package.

Changes:
- Make ContrastGraphApiImpl class package-private (remove public)
- Make ContrastGraphApiImpl constructor package-private (remove public)
- Create ContrastGraphApiFactory as the public factory for instantiation
- Update ContrastSDK.graphApi() to use the factory method

Tests: ContrastGraphApiFactoryTest passes (1 test, 0 failures)
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Comment thread sdk/src/main/java/com/contrastsecurity/sdk/JSON.java
new ContrastSDK.Builder("user", "serviceKey", "apiKey")
.withApiUrl(server.getUrl() + "/Contrast/api")
.build();
return new ContrastGraphApiImpl(sdk, new Gson());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we use JSON.getJson() here instead?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: possibility to use a helper method to reuse code in this class.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think I'm ok with this as is, I think any refactor to not duplicate code affects readability

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I did end up cleaning up the calls as it was ignoring proxy settings the way written.

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