2023.3
#30 (new) object @ annotation
it is now possible to add an annotation to all generated schema/model classes using a single annotation mapping:
map:
types:
- type: object @ lombok.Builder The object string represents all generated object classes (i.e. schema/model classes) and will add the given annotation only at the class level:
@Builder
@Generated(...)
public class Foo {
...
}#3 (new), java record support
openapi-processor is now capable of generating java records instead of pojos for schemas. This is a global setting in the mapping.yaml. It can either have the value default (which is default) to generate pojos or record to generate records.
openapi-processor-mapping: v4
options:
model-type: recordWith model-type: record the processor will generate record s like this:
package generated.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import generated.support.Generated;
@Generated(value = "openapi-processor-core", version = "test")
public record Foo(
@JsonProperty("bar")
String bar
) {}and without model-type or model-type: default it will create a simple pojo:
package generated.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import generated.support.Generated;
@Generated(value = "openapi-processor-core", version = "test")
public class Foo {
@JsonProperty("bar")
private String bar;
public String getBar() {
return bar;
}
public void setBar(String bar) {
this.bar = bar;
}
}#7 (changed), java-format
openapi-processor uses google-java-format to format the generated files (including javadoc). Unfortunately it depends on internal jdk packages that are strongly encapsulated since JDK 16. It is necessary to tell the jdk to export a few packages.
In theory it is not hard to configure it but in real life it is a bit fiddly to get this working. To get started without fighting with it I have modified the default from true to false.
To (re-) enable code formatting add the format-codeoption to the mapping.yaml:
openapi-processor-mapping: v4
options:
format-code: true#33 (fix) add an annotation only to the model class
having an annotation mapping on multiple model classes:
map:
types:
- type: Foo1 @ annotation.Bar
- type: Foo2 @ annotation.Bar where Foo1 has a property of type Foo2 the processor adds the annotation to the Foo2 class only but not on the Foo2 property in Foo1.
Because Foo2 is a generated class, it can put the annotation at the class and it is not necessary to put it on the property too. The annotation will only be placed at the property level if the property type is a mapped type where the class itself can't be modified.
dependency updates
- updated swagger parser to 2.1.15 (was 2.1.14)
- update jackson to 2.15.2 (was 2.15.1)