Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When setting disallowAdditionalPropertiesIfNotPresent
to false
, the generator should add support for additional properties to model classes for schemas that have no additionalProperties
attribute. This is explicitly stated in the documentation of the generator:
If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
Instead, the generated code is the same, independent of the value for disallowAdditionalPropertiesIfNotPresent
.
openapi-generator version
5.2.1
OpenAPI declaration file content or url
openapi: 3.0.3
info:
version: "v1"
title: Example
paths: {}
components:
schemas:
Example:
type: object
properties:
a:
type: integer
Generation Details
openapi-generator-cli generate \
-i openapi.yaml \
--additional-properties=disallowAdditionalPropertiesIfNotPresent=false \
-g jaxrs-cxf \
-o output
Steps to reproduce
- Generate Code from the example above with the cli command.
- Check the generated file
src/gen/java/org/openapitools/model/Example.java
in the output path
Expected result: The class supports additional properties. As described in #1466 this means it extends from HashMap
Actual result: The class has no support for additional properties.
Related issues/PRs
A similar issue was mentioned in #10306.
Without a fix for #1466 this might be less helpful, as the generated Code will not work as expected.
Suggest a fix
When checking for additionalProperties, the flag disallowAdditionalPropertiesIfNotPresent needs to be considered. Maybe ModelUtils#isMapSchema
should return true in this case, as it does when additionalProperties is set explicitly.