kokuwaio/micronaut-openapi-codegen

Map with reference as value

pulledtim opened this issue · 4 comments

Hey guys,

we wanted to generate code for a spec containing a map with referenced entities like defined in the spec.
For primitive datatypes this works very well but when we use a reference the code is not valid.

Example for spec:

openapi: 3.0.3
info:
  title: Test
  version: 0.0.1
paths: {}
components:
  schemas:
    EmbeddedValue:
      type: object
      properties:
        type:
          type: string
    MapConstruct:
      type: object
      additionalProperties:
        $ref: '#/components/schemas/EmbeddedValue'
        #$ref: '#/components/schemas/Entries'
    Entries:
      type: array
      items:
        $ref: '#/components/schemas/EmbeddedValue'
    Base:
      type: object
      properties:
        mapOfStuff:
          $ref: '#/components/schemas/MapConstruct'

Generated Base class:

...
	@com.fasterxml.jackson.annotation.JsonProperty(JSON_PROPERTY_MAP_OF_STUFF)
	@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
	private MapConstructVO mapOfStuff = new java.util.HashMap<>();
...

Generated MapConstruct:

...
public class MapConstructVO {
	private java.util.Map<java.lang.String,EmbeddedValueVO> additionalProperties;
...

Did we form the API wrongly or is this a missing feature?

Its a bug, i'll investigate later. You are using version 3.x or 4.x?

Thank you very much!
kokuwa codegen -> 3.3.1
openapitools maven generator plugin -> 6.6.0
micronaut -> 3.9.1

I created a testcase: #304

The generated code is compiling, can you verify the testcase?

Verified the test and found the difference in our config: The issue only occurs when the OpenAPIGenerator config flag "generateAliasAsModel" is set to true. Without this option I can reproduce your successful test