OpenAPITools / OpenAPITools/openapi-generator

[BUG] [JAX-RS] can't combine properties and additionalProperties in a schema

Open
#21,584 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Hi!
This issue is similar to the one mentioned here https://github.com/OpenAPITools/openapi-generator/issues/20853 and I think a solution similar to https://github.com/OpenAPITools/openapi-generator/pull/20947 should work (but for JavaJAXRSSpecServerCodegen). However, the issue is that whenever a schema has both properties and additional properties, the generated model extends HashMap but still adds properties as normal class attributes. This caused issued for me when mapping, excluding the attributes and only including the values inside HashMap. I've reproduced this multiple times in the latest version and master. You can reproduce it easily with,

a schema like,

Account:
  type: object
  description: A user account or resource representation
  required:
    - displayName
  properties:
    displayName:
      type: string
      description: Account display name
  additionalProperties: true

and a command like openapi-generator-cli generate -i openapi-v3-7-18.yaml -g jaxrs-spec -o generated-code-7-18
(I've had additional properties in the command to change api and model packages)

Hope this gets fixed soon,
Thank you very much!

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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
openapi-generator version

v7.14.0

OpenAPI declaration file content or url
Generation Details

openapi-generator-cli generate -i openapi-v3-7-18.yaml -g jaxrs-spec -o generated-code-7-18

Steps to reproduce
  1. Create an openapi with a schema that has both properties and additional properties
  2. Use the generate command with jaxrs-spec
Related issues/PRs

Similar issue: https://github.com/OpenAPITools/openapi-generator/issues/20853
Fix to that issue: https://github.com/OpenAPITools/openapi-generator/pull/20947

Suggest a fix

Using @JsonAnySetter / @JsonAnyGetter with a HashMap attribute to handle setting and getting should work, I believe.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with JavaJAXRSSpecServerCodegen and reproduce the issue using the Account schema and the openapi-generator-cli generate command with -g jaxrs-spec. Inspect the generated model and compare its handling of declared properties and additional properties; done means both kinds of values are mapped correctly without the conflicting HashMap inheritance behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.