Skip to content

additionalProperties:false generates invalid Java code with Map<String,> #367

@akstatic

Description

@akstatic

I have used AI to do the analysis of the bug to help me out. Below was its finding.

Description

When an AsyncAPI schema includes additionalPropertioes: false, the code generator produced invalid java code with malformed Map declaration: private Map<String, > additionalProperties;

This causes compilation failure.

Steps to Reproduce

  1. Create an AsyncAPI schema with
Document:
  title: Document
  type: object
  additionalProperties: false
  1. Run the code generator in maven plugin
  2. The generated Document.java contains

private Map<String, > additionalProperties; //Invalid - missing value type

  1. Compilation fails

Expected Behaviour

When additionalPropertioes: false is specified, no field should be generated because this directive means "do not allow any additional properties beyond those explicitly defined."

According to AsyncAPI specification

  • additionalPropertioes: false = No additional properties allowed (strict schema)
  • additionalPropertioes: true = Allow any additional properties (generates Map<String, Object>)
  • additionalPropertioes:{schema} = Allow additional properties matching the schema

Actual behaviour

The generator attempts to create a field but produced invalid code with an incomplete generic type

Root cause

The bug is in the ModelBuilder.java line 542 in the processAdditionalProperties() method:
File: https://github.com/sngular/scs-multiapi-plugin/blob/main/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/tools/ModelBuilder.java#L542

if (TypeConstants.isBoolean(addPropObj.asText())) {
      fieldObjectArrayList
          .add(SchemaFieldObject
                   .builder()
                   .baseName(fieldName)
                   .dataType(SchemaFieldObjectType.fromTypeList(TypeConstants.MAP, TypeConstants.OBJECT))
                   .build());
    }

The TypeConstants.isBoolean() method is incorrectly implemented:
File: https://github.com/sngular/scs-multiapi-plugin/blob/main/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/TypeConstants.java#L101

public static boolean isBoolean(final String isBoolean) {
    return Boolean.parseBoolean(isBoolean.toLowerCase());
  }

The Problem Explained

The TypeConstants.isBoolean() method parses the string as a boolean and returns the parsed value, not whether it's a boolean literal

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions