swagger-api / swagger-api/swagger-codegen

Recursive types in rust can't compile.

Open
#12,384 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Q&A (please complete the following information)
  • OS: Fedora 39
  • Browser: Firefox
  • Version:
  • Method of installation: docker
  • Swagger-Editor version: [e.g. 3.10.0]
  • Swagger/OpenAPI version: [Swagger 2.0, ]
Content & configuration

I will not share our yaml, as it can contain confidential information I am not allowed to share.

Describe the bug you're encountering

There are a couple of issues with the rust code generation.
Firstly when there is a recursive type, in our case three structs that reference each other. The rust compiler complains that there is an infinite size.
This can be easily solved by adding a Box<> around those members.

To reproduce...

Steps to reproduce the behavior:

  1. Make a yaml with a circular reference within its models
  2. Generate a rust client
  3. Try to build
  4. See compiler error
Expected behavior

I expect the rust client generator to generate working code.

Additional context or thoughts

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Rust client generator and reproduce the issue using a minimal YAML model with circular references, as described in the reproduction steps. Build the generated client to confirm the compiler error; done means recursive models generate working Rust code that compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.