Skip to content

Conversation

@Prsolver
Copy link

Fixed #12666

Description

This PR fixes an issue where string, boolean, and integer properties were being incorrectly converted to Object types when generating code from OpenAPI 3.1.0 specifications. The root cause was that the swagger-parser may return properties with null types when parsing OpenAPI 3.1.0 schemas (which use JSON Schema 2020-12), causing the getSwaggerType() method to return null, which then propagated through to the generated code as Object.

Changes:

  • Modified getSwaggerType() in DefaultCodegen.java to handle null property types gracefully
  • Added inferTypeFromFormat() helper method to infer types from format strings when type is null (e.g., int32integer, date-timeDateTime)
  • Added final fallback to return "object" instead of null, preventing the "String to be sanitized is null. Default to Object" error
  • Added comprehensive test cases to verify the fix works correctly for various scenarios
  • Preserved all existing functionality
  • Maintained backward compatibility - the public API is unchanged

Contribution by Gittensor, see my contribution statistics at https://gittensor.io/miners/details?githubId=100145226

Fixed issue swagger-api#12666 where string, boolean, and integer properties were
being incorrectly converted to Object types when generating code from
OpenAPI 3.1.0 specifications.

Changes:
- Modified getSwaggerType() to handle null property types gracefully
- Added inferTypeFromFormat() helper to infer types from format strings
- Added final fallback to return 'object' instead of null
- Added comprehensive test cases for the fix
@Prsolver
Copy link
Author

Hi, @djankows

This is ready for review, thanks

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.

[Bug]: String and Boolean and Int properties are being turned into Objects in OpenAPI 3.1.0

2 participants