swagger-api / swagger-api/swagger-codegen

[Rust] Optional parameters should map to Option types

Open
#8,171 3 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

In the current Rust templates, it appears that request parameters not marked required in the Swagger template are still mapped to required function parameters in the API. The Swagger spec (2.0 and 3.0) says that non-required parameters are optional. It would be better to map an optional parameter of type T to an argument of type Option<T> to avoid a bunch of inconvenience and unnecessary construction. The generated code should then arrange to pass these parameters only when Some(value) is passed and not when None is passed.

Swagger-codegen version

Current Git master, but seems to apply to all versions.

Swagger declaration file content or url

https://esi.evetech.net/latest/swagger.json?datasource=tranquility

Command line used for generation

Normal -l rust invocation.

Steps to reproduce

Feed the spec above to swagger-codegen and look at the parameter types of optional request parameters.

Related issues/PRs

None found.

Suggest a fix/enhancement

Hack up the #queryParams code in api.mustache to check whether a parameter is required and add an Option to the param as appropriate. Sorry I can't be more specific: I don't really understand the details of the mustache templating being used here.

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 in the Rust template's api.mustache, focusing on the #queryParams section and how it checks whether parameters are required. Generate the API from the linked Swagger declaration with the normal -l rust invocation; done means non-required parameters use Option and are passed only when Some(value) is provided.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.