VincentS
VincentS

Reputation: 592

Open api 3.0 java code generator - How to generate instantiated lists?

A few weeks ago, we migrate our project Swagger 2.0 files to Open api 3.0. We use the Java code generator to generate our classes.

With the Swagger 2.0 and the swagger-codegen-cli-2.2.2.jar, the lists where generated like that:

private List<Betriebspunkt> ist = new ArrayList<Betriebspunkt>();
private List<Betriebspunkt> plan = new ArrayList<Betriebspunkt>();

Now, with Open api 3.0 and openapi-generator-cli-3.3.2-20181022.194157-15.jar, my object is generated like that:

private List<Betriebspunkt> ist = null;
private List<Betriebspunkt> plan = null;

My yaml file looks like that:

Zuglauf:
  properties:
    ist:
      type: array
      items:
        $ref: '#/components/schemas/Betriebspunkt'
    plan:
      type: array
      items:
        $ref: '#/components/schemas/Betriebspunkt'
  type: object

I don't want my lists declared as null. I looked in the generator java options (https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/java.md), but I didn't find any solution. Is there any way to get my lists instantiated?

Upvotes: 3

Views: 3798

Answers (1)

William Cheng
William Cheng

Reputation: 10807

I've filed https://github.com/OpenAPITools/openapi-generator/pull/1683 for OpenAPI Generator to have lists declared properly instead of defaulting to null, e.g. https://github.com/OpenAPITools/openapi-generator/pull/1683/files#diff-8afdfb3025e9e2e0e52f9f5748a2f969R54. Please have a look to see if that's what you're looking for.

PR merged into master and will be included in the 4.0.0-beta release on Dec 20th.

Upvotes: 3

Related Questions