[
https://issues.apache.org/jira/browse/AVRO-3805?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17744975#comment-17744975
]
Christophe Le Saec commented on AVRO-3805:
------------------------------------------
Hello Tom,
Pb could be solved by adding explicit import on avro maven plugin, as
{code:xml}
<configuration>
<imports>
<import>${project.build.directory}/generated-sources/openapi/DocumentInfo.avsc</import>
</imports>
...
</configuration>
{code}
So the file DocumentInfo is compiled before the other, as is it [coded
here|https://github.com/apache/avro/blob/master/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/AbstractAvroMojo.java#L222-L224].
(it doesn't work with
{_}<import>${project.build.directory}/generated-sources/openapi</import>{_};
because we can't know in which order file will be treated)
Nevertheless, this "import" should not be necessary, as source is a whole
directory and imports files are all inside. IMHO the generation should take the
whole directory as one global source, and even enabling to have mutual
references ({_}As if DocumentInfo had a field of nullable ApplicationEvent;
even if in this case, it has no meaning{_} :)).
The issue is similar to AVRO-530 for mutual references in protocol.
I think we should add a method like
{code:java}
List<Schema> Schema.Parser.parse(Iterable<File> sources) throws IOException {
{code}
that would be able to treat mutual references, like with AVRO-530 PR ...
(the algorithm principle would be to parse all record schemas first; then parse
fields)
[~rskraba] : WDYT ?
> Unable to generate AVRO classes with Java source generated from OpenAPI Yaml
> file
> ---------------------------------------------------------------------------------
>
> Key: AVRO-3805
> URL: https://issues.apache.org/jira/browse/AVRO-3805
> Project: Apache Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.11.2
> Reporter: Tom
> Priority: Minor
> Attachments: demo.zip
>
>
> I was unable to generate AVRO classes when using OpenAPI yaml file to
> generate the source code for avro-maven-plugin
> [INFO] BUILD FAILURE
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Total time: 9.450 s
> [INFO] Finished at: 2023-07-19T14:16:26-04:00
> [INFO]
> ------------------------------------------------------------------------
> [ERROR] Failed to execute goal
> org.apache.avro:avro-maven-plugin:1.11.2:schema (default) on project demo:
> Execution default of goal org.apache.avro:avro-maven-plugin:1.11.2:schema
> failed: Undefined name: "model.DocumentInfo" ->
> This occurs when an array is specified In the OpenAPI yaml file as a property
> of an object, for example
> documents:
> type: array
> items:
> $ref: '#/components/schemas/DocumentInfo'
>
> If that was commented out, then proper AVRO classes will be generated.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)