Skip to content

Handle array schemas with empty or missing items (fix #165) - #202

Merged
en-milie merged 5 commits into
masterfrom
codex/fix-issue-#165-and-add-regression-test
Jul 3, 2026
Merged

Handle array schemas with empty or missing items (fix #165)#202
en-milie merged 5 commits into
masterfrom
codex/fix-issue-#165-and-add-regression-test

Conversation

@en-milie

@en-milie en-milie commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Motivation

  • Avoid NullPointerExceptions and incorrect reference resolution when OpenAPI array schemas either omit items or declare an empty items: {} value.
  • Ensure CATS can generate request/response examples for those contracts instead of crashing or producing incorrect schema refs.

Description

  • Replace direct getItems().get$ref() dereferences with the safe helper CatsModelUtils.getSchemaItems(...) when deriving request schema names and extracting response schema references in FuzzingDataFactory.
  • Apply the same safe-item resolution in OpenApiUtils.addToSchemas(...) when collecting schemas from Content.
  • Add a regression OpenAPI contract src/test/resources/issue165.yml that includes an array with items: {} and an array missing items, and add the unit test shouldHandleArraySchemasWithEmptyOrMissingItems to FuzzingDataFactoryTest to cover both request and response scenarios.

Testing

  • Added the JUnit test FuzzingDataFactoryTest#shouldHandleArraySchemasWithEmptyOrMissingItems which asserts payload generation for the issue165.yml contract.
  • Attempted to run mvn -Dtest=FuzzingDataFactoryTest#shouldHandleArraySchemasWithEmptyOrMissingItems test, but the execution failed due to Maven dependency resolution problems contacting Maven Central (HTTP 403).
  • Attempted offline execution with mvn -o -Dtest=FuzzingDataFactoryTest#shouldHandleArraySchemasWithEmptyOrMissingItems test, but it failed because required artifacts were not present in the local Maven cache.

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 36ab59aec6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/main/java/com/endava/cats/factory/FuzzingDataFactory.java Outdated
en-milie added 4 commits July 3, 2026 09:46
### Motivation
- Avoid NullPointerExceptions and incorrect reference resolution when OpenAPI `array` schemas either omit `items` or declare an empty `items: {}` value.
- Ensure CATS can generate request/response examples for those contracts instead of crashing or producing incorrect schema refs.

### Description
- Replace direct `getItems().get$ref()` dereferences with the safe helper `CatsModelUtils.getSchemaItems(...)` when deriving request schema names and extracting response schema references in `FuzzingDataFactory`.
- Apply the same safe-item resolution in `OpenApiUtils.addToSchemas(...)` when collecting schemas from `Content`.
- Add a regression OpenAPI contract `src/test/resources/issue165.yml` that includes an array with `items: {}` and an array missing `items`, and add the unit test `shouldHandleArraySchemasWithEmptyOrMissingItems` to `FuzzingDataFactoryTest` to cover both request and response scenarios.

### Testing
- Added the JUnit test `FuzzingDataFactoryTest#shouldHandleArraySchemasWithEmptyOrMissingItems` which asserts payload generation for the `issue165.yml` contract.
- Attempted to run `mvn -Dtest=FuzzingDataFactoryTest#shouldHandleArraySchemasWithEmptyOrMissingItems test`, but the execution failed due to Maven dependency resolution problems contacting Maven Central (HTTP 403).
- Attempted offline execution with `mvn -o -Dtest=FuzzingDataFactoryTest#shouldHandleArraySchemasWithEmptyOrMissingItems test`, but it failed because required artifacts were not present in the local Maven cache.
### Motivation
- Avoid NullPointerExceptions and incorrect reference resolution when OpenAPI `array` schemas either omit `items` or declare an empty `items: {}` value.
- Ensure CATS can generate request/response examples for those contracts instead of crashing or producing incorrect schema refs.

### Description
- Replace direct `getItems().get$ref()` dereferences with the safe helper `CatsModelUtils.getSchemaItems(...)` when deriving request schema names and extracting response schema references in `FuzzingDataFactory`.
- Apply the same safe-item resolution in `OpenApiUtils.addToSchemas(...)` when collecting schemas from `Content`.
- Add a regression OpenAPI contract `src/test/resources/issue165.yml` that includes an array with `items: {}` and an array missing `items`, and add the unit test `shouldHandleArraySchemasWithEmptyOrMissingItems` to `FuzzingDataFactoryTest` to cover both request and response scenarios.

### Testing
- Added the JUnit test `FuzzingDataFactoryTest#shouldHandleArraySchemasWithEmptyOrMissingItems` which asserts payload generation for the `issue165.yml` contract.
- Attempted to run `mvn -Dtest=FuzzingDataFactoryTest#shouldHandleArraySchemasWithEmptyOrMissingItems test`, but the execution failed due to Maven dependency resolution problems contacting Maven Central (HTTP 403).
- Attempted offline execution with `mvn -o -Dtest=FuzzingDataFactoryTest#shouldHandleArraySchemasWithEmptyOrMissingItems test`, but it failed because required artifacts were not present in the local Maven cache.
…, and add test for issue 165

### Motivation
- Fix crashes and incorrect behavior when encountering array schemas that have empty or missing `items` definitions or when `items` refs are accessed directly.
- Use a single utility accessor for schema `items` to avoid NPEs and inconsistent handling across the codebase.
- Add a regression test and an OpenAPI example to cover the scenario described in issue 165.

### Description
- Replaced direct calls to `getItems()` with the centralized helper `CatsModelUtils.getSchemaItems(...)` in `FuzzingDataFactory` and `OpenApiUtils` to safely obtain array item schemas.
- Updated `extractSchemaRef` logic in `FuzzingDataFactory` to use `CatsModelUtils.getSchemaItems(...)` when resolving array response schemas.
- In `OpenAPIModelGeneratorV2.createExamplesArray` added an early check to extract and use an example from the array schema (`extractExampleFromSchema`) and return immediately when present.
- Added `OpenApiUtils.getExamples(OpenAPI)` helper to safely retrieve component examples.
- Added a unit test `shouldHandleArraySchemasWithEmptyOrMissingItems` and a new example OpenAPI file `issue165.yml` to reproduce and validate arrays with empty or missing `items` and zero `maxItems`.

### Testing
- Ran the updated unit tests including the new `FuzzingDataFactoryTest.shouldHandleArraySchemasWithEmptyOrMissingItems`, and the new test passed.
- Executed the full test suite (`mvn test`), and all unit tests completed successfully.
- Verified the new sample `issue165.yml` is parsed and produces the expected payload and response examples in the test.
…, and add test for issue 165

### Motivation
- Fix crashes and incorrect behavior when encountering array schemas that have empty or missing `items` definitions or when `items` refs are accessed directly.
- Use a single utility accessor for schema `items` to avoid NPEs and inconsistent handling across the codebase.
- Add a regression test and an OpenAPI example to cover the scenario described in issue 165.

### Description
- Replaced direct calls to `getItems()` with the centralized helper `CatsModelUtils.getSchemaItems(...)` in `FuzzingDataFactory` and `OpenApiUtils` to safely obtain array item schemas.
- Updated `extractSchemaRef` logic in `FuzzingDataFactory` to use `CatsModelUtils.getSchemaItems(...)` when resolving array response schemas.
- In `OpenAPIModelGeneratorV2.createExamplesArray` added an early check to extract and use an example from the array schema (`extractExampleFromSchema`) and return immediately when present.
- Added `OpenApiUtils.getExamples(OpenAPI)` helper to safely retrieve component examples.
- Added a unit test `shouldHandleArraySchemasWithEmptyOrMissingItems` and a new example OpenAPI file `issue165.yml` to reproduce and validate arrays with empty or missing `items` and zero `maxItems`.

### Testing
- Ran the updated unit tests including the new `FuzzingDataFactoryTest.shouldHandleArraySchemasWithEmptyOrMissingItems`, and the new test passed.
- Executed the full test suite (`mvn test`), and all unit tests completed successfully.
- Verified the new sample `issue165.yml` is parsed and produces the expected payload and response examples in the test.
@en-milie
en-milie merged commit a1730bd into master Jul 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant