Skip to content

fix(parser): honor inferSchemaType for OAS 3.1 enum schemas#2299

Open
zetacollab wants to merge 1 commit intoswagger-api:masterfrom
zetacollab:fix/issue-1964-oas31-repro
Open

fix(parser): honor inferSchemaType for OAS 3.1 enum schemas#2299
zetacollab wants to merge 1 commit intoswagger-api:masterfrom
zetacollab:fix/issue-1964-oas31-repro

Conversation

@zetacollab
Copy link
Copy Markdown

@zetacollab zetacollab commented Mar 27, 2026

Pull Request


Description

This PR fixes an OpenAPI 3.1 parser inconsistency when ParseOptions.setInferSchemaType(false) is used.

In the OAS 3.1 getJsonSchema(...) path, enum-based type inference was still applied even when schema type inference was explicitly disabled. As a result, schemas like:

contains:
  enum:
    - 1

were parsed with an invented type instead of preserving an unset type.

This PR updates that path to honor inferSchemaType(false) and adds a regression test covering the issue.

Fixes [#1964](https://github.com/swagger-api/swagger-parser/pull/2299)

## Type of Change

- [x] 🐛 Bug fix
- [ ] ✨ New feature
- [ ] ♻️ Refactor (non-breaking change)
- [x] 🧪 Tests
- [ ] 📝 Documentation
- [ ] 🧹 Chore (build or tooling)

## Checklist

- [x] I have added/updated tests as needed
- [ ] I have added/updated documentation where applicable
- [x] The PR title is descriptive
- [x] The code builds and passes tests locally
- [x] I have linked related issues (if any)

## Screenshots / Additional Context

Locally verified with:

mvn -pl modules/swagger-parser-v3 -am -Dsurefire.failIfNoSpecifiedTests=false -Dtest=OAI31DeserializationTest#test31Issue1964InferSchemaTypeDisabled test
mvn -pl modules/swagger-parser-v3 -am -Dsurefire.failIfNoSpecifiedTests=false -Dtest=OAI31DeserializationTest#testSchemaKeysOAS31 test

The regression test confirms that with inferSchemaType(false):

- contains: { enum: [1] } does not get an inferred type
- additionalProperties: false does not force an object type

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.

1 participant