Skip to content

[BUG] [AVRO] MR 3728 broke the package handling of the avro generator #3987

Closed
@Choobz

Description

@Choobz

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Package handling was broken for the avro generator during MR 3728.

cliOptions.add(new CliOption(CodegenConstants.INVOKER_PACKAGE, CodegenConstants.INVOKER_PACKAGE_DESC));
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));

That part was removed so now all ref type point toward the model package no matter the namespace of the targeted object.

openapi-generator version

4.1.1

OpenAPI declaration file content or url
components:
  schemas:
    Pet:
      type: object
      required:
      - id
      - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string
        friend:
          $ref: '#/components/schemas/Friend'
    Friend:
      type: object
      properties:
        id:
          type: string

Result

{
  "namespace": "fr.test",
  "type": "record",
  "doc": "",
  "name": "Pet",
  "fields": [
 ...
    {
      "name": "friend",
      "type": ["null", "model.Friend"],
      "doc": ""
    }
  ]
}

Expected

{
  "namespace": "fr.test",
  "type": "record",
  "doc": "",
  "name": "Pet",
  "fields": [
 ...
    {
      "name": "friend",
      "type": ["null", "fr.test.Friend"],
      "doc": ""
    }
  ]
}
Command line used for generation
<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <!-- RELEASE_VERSION -->
    <version>4.1.1</version>
    <!-- /RELEASE_VERSION -->
    <executions>
        <execution>
            <id>avro-schema</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
                <generatorName>avro-schema</generatorName>
                <configOptions>
                    <packageName>fr.test</packageName>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>
Steps to reproduce

mvn compile

Related issues/PRs
Suggest a fix

Not entirely sure about the fix, I don't think the original proposition for package handling was really standard and/or accepted by the maintaining team.
Could do the MR if pointed toward the right way to handle packages and namespaces for imported avsc files.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions