Map with reference as value #303

Closed
opened 2023-09-05 10:38:35 +02:00 by pulledtim · 4 comments
pulledtim commented 2023-09-05 10:38:35 +02:00 (Migrated from github.com)

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?

Hey guys, we wanted to generate code for a spec containing a map with referenced entities like defined in the [spec](https://spec.openapis.org/oas/v3.1.0#model-with-map-dictionary-properties). 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?
sschnabe commented 2023-09-05 11:12:38 +02:00 (Migrated from github.com)

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

Its a bug, i'll investigate later. You are using version [3.x](https://github.com/kokuwaio/micronaut-openapi-codegen/tree/3.x) or [4.x](https://github.com/kokuwaio/micronaut-openapi-codegen/tree/main)?
pulledtim commented 2023-09-05 11:31:07 +02:00 (Migrated from github.com)

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

Thank you very much! kokuwa codegen -> 3.3.1 openapitools maven generator plugin -> 6.6.0 micronaut -> 3.9.1
sschnabe commented 2023-09-07 13:36:56 +02:00 (Migrated from github.com)

I created a testcase: https://github.com/kokuwaio/micronaut-openapi-codegen/pull/304

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

I created a testcase: https://github.com/kokuwaio/micronaut-openapi-codegen/pull/304 The generated code is compiling, can you verify the testcase?
pulledtim commented 2023-09-08 08:40:56 +02:00 (Migrated from github.com)

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

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
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
kokuwaio/micronaut-openapi-codegen#303
No description provided.