0

I am using additionalPropertes in my OpenAPI definition to refer a map object. The part of my OAS is given below:

Configuration:
  title: Configuration Info
  type: object
  additionalProperties:
    type: string
  description: The config parameters.
  example:
    configName: header
    configValue: Context
    configId: "12"

When generating code using maven codegen plugin of openapi-generator, version - 4.3.1 with the following configurations, no model class is generated for the model Configuration.

           <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>api.yaml</inputSpec>
                            <language>jaxrs-cxf-cdi</language>
                            <configOptions>
                                <apiPackage>${api-package}</apiPackage>
                                <modelPackage>${model-package}</modelPackage>
                                <sourceFolder>src/gen/java</sourceFolder>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

How can we generate model classes for objects with additionalProperties in OAS?

Vithursa Mahendrarajah
  • 1,194
  • 2
  • 15
  • 28

1 Answers1

1

Setting the configuration generateAliasAsModel as true will generate model classes for Maps defined in OAS. The correct configuration is given below:

            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>api.yaml</inputSpec>
                            <language>jaxrs-cxf-cdi</language>
                            <configOptions>
                                <apiPackage>${api-package}</apiPackage>
                                <modelPackage>${model-package}</modelPackage>
                                <sourceFolder>src/gen/java</sourceFolder>
                            </configOptions>
                            <generateAliasAsModel>true</generateAliasAsModel>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Vithursa Mahendrarajah
  • 1,194
  • 2
  • 15
  • 28