OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
20.56k stars 6.28k forks source link

[BUG][Protobuf] Generates circular file imports that don't compile with protoc #15461

Open jeikabu opened 1 year ago

jeikabu commented 1 year ago

Bug Report Checklist

Description

Converting Teamcity's swagger.json to Protocol Buffers results in protobuf specification that doesn't compile with protoc. Specifically because of circular/recursive file references/imports.

openapi-generator version

--version output:

openapi-generator-cli 6.6.0-SNAPSHOT
  commit : ff9b384
  built  : -999999999-01-01T00:00:00+18:00
  source : https://github.com/openapitools/openapi-generator
  docs   : https://openapi-generator.tech/
OpenAPI declaration file content or url

https://teamcity.jetbrains.com/app/rest/swagger.json

Generation Details
docker run -m 24g -it --rm -v "$(pwd):/local" openapitools/openapi-generator-cli java -Xmx20G -jar ./opt/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i https://teamcity.jetbrains.com/app/rest/swagger.json -g protobuf-schema -o /local/out/teamcity

Needs extra mem otherwise fails with Exception in thread "main" java.lang.OutOfMemoryError: Java heap space.

Steps to reproduce
  1. Download/extract protobuf compiler v23.0 (the latest release) for win64 (link)
  2. cd ./out/teamcity
  3. .\protoc-23.0-win64\bin\protoc.exe --csharp_out=./csharp .\models/*
  4. Note resulting errors:
    models/agent.proto:15:1: File recursively imports itself: models/agent.proto -> models/agent_pool.proto -> models/agents.proto -> models/agent.proto
    models/agents.proto:15:1: Import "models/agent.proto" was not found or had errors.
    models/agents.proto:27:12: "Agent" is not defined.
    <SNIP>
    models/build_types.proto:15:1: Import "models/build_type.proto" was not found or had errors.
    models/build_types.proto:27:12: "BuildType" is not defined.
    models/cloud_image.proto:15:1: File recursively imports itself: models/cloud_image.proto -> models/cloud_instances.proto -> models/cloud_instance.proto -> models/cloud_image.proto
    models/cloud_instance.proto:15:1: Import "models/agent.proto" was not found or had errors.
    models/cloud_instance.proto:16:1: Import "models/cloud_image.proto" was not found or had errors.
    models/cloud_instance.proto:32:3: "CloudImage" is not defined.
    models/cloud_instance.proto:34:3: "Agent" is not defined.
    models/cloud_instances.proto:15:1: Import "models/cloud_instance.proto" was not found or had errors.
    models/cloud_instances.proto:27:12: "CloudInstance" is not defined.
    <SNIP>
Related issues/PRs
Suggest a fix
IwantDoit commented 5 months ago

Hello, I have encountered the same issue. Has this problem been resolved?

wing328 commented 5 months ago

looks like no one has contributed a fix yet.

fi anyone wants to contribute a PR to sponsor a fix, please reply to let us know.

IwantDoit commented 5 months ago

Thank you. I am using the openapi-generator-maven-plugin to generate proto files and I want to use additionalProperties to import a template so that I can use protoc to compile the proto files. However, it seems to be ineffective. Is it because protobuf-schema does not support additionalProperties?