openapi-processor / openapi-processor-spring

an OpenAPI 3.0 & 3.1 interface & model java code generator for Spring Boot
https://docs.openapiprocessor.io
Apache License 2.0
40 stars 9 forks source link

OffsetDateTime is not imported with allOf using #128

Closed romif closed 3 years ago

romif commented 3 years ago

Hello. I noticed an incorrect model generation for date-time type with allOf using: OffsetDateTime is not imported.

openapi.yaml:

openapi: 3.0.2
info:
  title: openapi-processor-spring sample api
  version: 1.0.0

paths:
  /test:
    get:
      tags:
        - test
      responses:
        '200':
          description: echo of the source parameter
          content:
            text/plain:
              schema:
                $ref: '#/components/schemas/Model'

components:
  schemas:
    SubModelWithDateTime:
      type: object
      properties:
        dateTime:
          type: string
          format: date-time

    SubModel:
      type: object
      properties:
        name:
          type: string

    Model:
      type: object
      allOf:
        - $ref: '#/components/schemas/SubModelWithDateTime'
        - $ref: '#/components/schemas/SubModel'

Expected result: all classes are imported.

Actual result: OffsetDateTime is not imported:

package io.openapiprocessor.model;

import com.fasterxml.jackson.annotation.JsonProperty;

public class Model {

    @JsonProperty("dateTime")
    private OffsetDateTime dateTime;

    @JsonProperty("name")
    private String name;

    public OffsetDateTime getDateTime() {
        return dateTime;
    }

    public void setDateTime(OffsetDateTime dateTime) {
        this.dateTime = dateTime;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}

Thank you.

hauner commented 3 years ago

Hi, thanks for reporting. :-)

It is fixed in core 2021.4.1. To use it with spring 2021.4, you can add the core library as an additional dependency.

in gradle:

openapiProcessor {
    // ...
    spring {
        // the spring processor dependency
        processor 'io.openapiprocessor:openapi-processor-core:2021.4.1'
        processor 'io.openapiprocessor:openapi-processor-spring:2021.4'
    }
}

with maven this should work:

<plugins>
  <plugin>
    <dependencies>
      <dependency>
        <groupId>io.openapiprocessor</groupId>
        <artifactId>openapi-processor-core</artifactId>
        <version>2021.4.1</version>
      </dependency>
      <dependency>
        <groupId>io.openapiprocessor</groupId>
        <artifactId>openapi-processor-spring</artifactId>
        <version>2021.4</version>
      </dependency>
    </dependencies>
  </plugin>
</plugins>