Closed cdprete closed 2 years ago
Yes, that is really annoying.
Not sure I can do anything about it apart from removing the formatter...
(see also: https://github.com/openapi-processor/openapi-processor-core/issues/79) I should probably move that info to the docs.
... another workaround would be an option to skip the formatting step. It is generated code, so we do not have to read it very often.
... another workaround would be an option to skip the formatting step. It is generated code, so we do not have to read it very often.
How can I do it? Moreover, is there a way to generate just the models (without the API)?
disable formatting
I'm working on it. It is not possible with the current release.
What I found is that you can create a .mvn/jvm.config
file in you project and add the exports to it:
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
I checked it with the sample project and it works.
just generate models
There is no option to generate models only. It is generating only models which are in use, i.e. used by a interface method.
Best you can do is to ignore the generated interfaces.
I'll give it a try
Hi. While that suggestion fixed the issue with the module system from the JDK, it seems like the project is not able to properly generate all the models. From the Maven execution I get the following output:
[INFO] Changes detected - generating target files!
[INFO] using OPENAPI4J parser
[INFO] ref BasicContactDetails 1
[INFO] ref BasicContactDetails 2
[INFO] ref ContactsPostRequestBody 1
[INFO] ref BasicContactDetails 3
[INFO] ref SingleContactRead 1
[INFO] ref BasicContactDetails 4
[INFO] ref ContactsIdPutRequestBody 1
[INFO] ref BasicContactDetails 5
with just BasicContactDetails
and SingleContactRead
being generated when I should, instead, get other models as well.
For example:
ContactRead:
type: object
description: Object providing all the information about a contact in the system without e-mail addresses and phone numbers.
allOf:
- $ref: '#/components/schemas/BasicContactDetails'
required:
- id
properties:
id:
$ref: '#/components/schemas/Id'
image:
$ref: '#/components/schemas/Image'
Also, the classes are wrongly generated when composing a model with multiple allOf
.
For example, given:
SingleContactRead:
type: object
description: Object providing all the information about a single contact in the system, including e-mail addresses and phone numbers.
allOf:
- $ref: '#/components/schemas/ContactDetailsWithoutImage'
- $ref: '#/components/schemas/ContactRead'
required:
- id
properties:
id:
$ref: '#/components/schemas/Id'
image:
$ref: '#/components/schemas/Image'
I get the following class out:
/*
* DO NOT MODIFY - this class was auto generated by openapi-processor-spring
*
* 2021.5
* 2022-02-02T18:39:10.231468100Z
* https://docs.openapiprocessor.io/spring
*/
package com.cdprete.phonebook.dto.model;
import com.fasterxml.jackson.annotation.JsonProperty;
public class SingleContactRead {
@JsonProperty("name")
private String name;
@JsonProperty("surname")
private String surname;
@JsonProperty("name")
private String name;
@JsonProperty("surname")
private String surname;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
}
Maybe I should specify something in the mapping.yaml
file?
I'm using the "empty" mapping
openapi-processor-mapping: v2
options:
package-name: com.cdprete.phonebook.dto
That said, the original issue with this ticket is for me solved (or, at least, patched) and therefore I close this ticket. If you need more input about the other issues, just let me know ;)
oh, I guess you found some missing logic...
allOf
and properties
at the same level. This explains the missing classes.allOf
, it doesn't check for duplicates. name
& surname
are part of both objects?I don't have any tests for either case, so it is not implement... yet.
Looking at it, thanks for reporting :-)
... and no you don't need to configure anything in the mapping.yaml
for this.
Yes, name and surname are present in both the definitions. It would also be nice to have the mapping.yaml file being optional (implying the default content)
I have improved the processor. It recognizes the properties
on the same level as the allOf
and handles duplicate properties.
You can check this with version 2022.2-SNAPSHOT
Maven needs this to find the snapshot:
<project>
<pluginRepositories>
<pluginRepository>
<id>openapi-processor-snapshots</id>
<name>openapi-processor-snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</pluginRepository>
</pluginRepositories>
<project>
Hi. I wanted to test your plugin to see if it fits my needs, but when I try to use it it crashes with the following error:
Plugin configuration in Maven
This is probably caused by https://github.com/google/google-java-format#jdk-16