Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #2424
Closed
Open
Issue created Mar 16, 2019 by Administrator@rootContributor

[BUG][RUST-SERVER] doesn't produce compilable code with simple example API

Created by: piersfinlayson

Description

I have written a simple, sample API, and rust-server generates code which doesn't compile.

Full cargo build output here, but there are three problems:

  • models::models::models::TYPE used instead of models::TYPE, e.g.
error[E0603]: module `models` is private
  --> src/lib.rs:77:35
   |
77 |     fn a_post(&self, arg: models::models::models::Arg) -> Box<Future<Item=APostResponse, Error=ApiError>>;
  • wrong variable used to log parameter e.g.
error[E0277]: `()` doesn't implement `std::fmt::Display`
   --> src/server/mod.rs:210:173
    |
210 |                         Err(e) => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't parse path parameter arg: {}", e)))),

In this case , e) should be , param_arg)

  • invalid FromStr implementation e.g.
error[E0308]: match arms have incompatible types
  --> src/models.rs:42:9
   |
42 | /         match s {
43 | |             "0" => Ok(Arg::_0),
   | |                    ----------- match arm with an incompatible type
44 | |             "1" => Ok(Arg::_1),
45 | |             "2" => Ok(Arg::_2),
46 | |             _ => Err(()),
47 | |         }
   | |_________^ expected enum `std::result::Result`, found struct `models::Ok`
   |
   = note: expected type `std::result::Result<models::Arg, ()>`
              found type `models::Ok`

This might be a little harsh! The problem is that Ok here is models::Ok not Result::Ok.

Commit fixing the compilation errors here.

There are also similar errors with the client and server examples, plus also an extraneous use swagger::auth::Authorization; causing the server example to fail to compile:

error: unused import: `swagger::auth::Authorization`
  --> examples/server_lib/mod.rs:16:5
   |
16 | use swagger::auth::Authorization;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `-D unused-imports` implied by `-D warnings`

Fixes for the client and server examples are in this commit.

openapi-generator version

4.0.0-SNAPSHOT

Using container openapitools/openapi-generator-cli:latest

OpenAPI declaration file content or url

openapi.yaml

Command line used for generation
docker run --rm \
           -v ~/openapi-generator-rust-server-test/openapi_client:/local \
           openapitools/openapi-generator-cli \
           generate \
           -g rust-server \
           -i /local/openapi.yaml \
           -o /local
Steps to reproduce
cd ~
git clone https://github.com/piersfinlayson/openapi-generator-rust-server-test
cd openapi-generator-rust-server-test
docker pull openapitools/openapi-generator-cli
docker run --rm \
           -v ~/openapi-generator-rust-server-test/openapi_client:/local \
           openapitools/openapi-generator-cli \
           generate \
           -g rust-server \
           -i /local/openapi.yaml \
           -o /local
cd openapi_client
cargo build
cargo build --example client
cargo build --example server
Related issues/PRs

None that I can see

Suggest a fix

See above

Assignee
Assign to
Time tracking