swagger-api / swagger-api/swagger-codegen

[Rust] Add support for array schemas in Rust template

Open
#7,293 0 comments 0 reactions 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

Description

Currently, the Rust template will generate an empty struct when trying to generate a model from an array schema. This is incorrect and undesirable. Instead, we should generate a 1-item tuple like struct Test(Vec<f64>);

Swagger-codegen version

3.0.0

Swagger declaration file content or url
components:
  schemas:
    Test:
      type: array
      items:
        type: number
        format: double

This currently generates struct Test { }.

Command line used for generation
java -jar swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
   -i apis/gdax/openapi.yaml \
   -l rust \
   -o apis/gdax/generated_api
Steps to reproduce

Try to generate a model from an array schema for Rust.

Suggest a fix/enhancement

A proposed fix is to use vendorExtensions.x-is-array-model in the rust template and to generate different code depending on it.

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 template used by the -l rust generator and inspect how vendorExtensions.x-is-array-model is handled. Reproduce the issue with the supplied array schema and generation command; done when Test is generated as a one-item tuple such as struct Test(Vec); rather than an empty struct.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.