Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bin/configs/rust-server-ping-bearer-auth-v3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
generatorName: rust-server
outputDir: samples/server/petstore/rust-server/output/ping-bearer-auth
inputSpec: modules/openapi-generator/src/test/resources/3_0/rust-server/ping-bearer-auth.yaml
templateDir: modules/openapi-generator/src/main/resources/rust-server
generateAliasAsModel: true
additionalProperties:
hideGenerationTimestamp: "true"
packageName: ping-bearer-auth
2 changes: 1 addition & 1 deletion docs/generators/rust-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|BasicAuth|✓|OAS2,OAS3
|ApiKey|✓|OAS2,OAS3
|OpenIDConnect|✗|OAS3
|BearerToken||OAS3
|BearerToken||OAS3
|OAuth2_Implicit|✓|OAS2,OAS3
|OAuth2_Password|✗|OAS2,OAS3
|OAuth2_ClientCredentials|✗|OAS2,OAS3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public RustServerCodegen() {
.securityFeatures(EnumSet.of(
SecurityFeature.ApiKey,
SecurityFeature.BasicAuth,
SecurityFeature.BearerToken,
SecurityFeature.OAuth2_Implicit
))
.excludeGlobalFeatures(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,20 @@ Example
{{! TODO: Add API Key example }}
```
{{/isApiKey}}
{{#isBasic}}- **Type**: HTTP basic authentication
{{#isBasicBasic}}- **Type**: HTTP basic authentication

Example
```
{{! TODO: Add HTTP basic authentication }}
```
{{/isBasic}}
{{/isBasicBasic}}
{{#isBasicBearer}}- **Type**: Bearer token authentication

Example
```
{{! TODO: Add Bearer token authentication }}
```
{{/isBasicBearer}}
{{#isOAuth}}- **Type**: OAuth
- **Flow**: {{{flow}}}
- **Authorization URL**: {{{authorizationUrl}}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl<T, A, B, C, D, ReqBody> Service<Request<ReqBody>> for AddContext<T, A, B, C

{{#authMethods}}
{{#isBasic}}
{{#isBasicBasic}}
{
use swagger::auth::Basic;
use std::ops::Deref;
Expand All @@ -117,6 +118,20 @@ impl<T, A, B, C, D, ReqBody> Service<Request<ReqBody>> for AddContext<T, A, B, C
return self.inner.call((request, context))
}
}
{{/isBasicBasic}}
{{#isBasicBearer}}
{
use swagger::auth::Bearer;
use std::ops::Deref;
if let Some(bearer) = swagger::auth::from_headers::<Bearer>(&headers) {
let auth_data = AuthData::Bearer(bearer);
let context = context.push(Some(auth_data));
let context = context.push(None::<Authorization>);

return self.inner.call((request, context))
}
}
{{/isBasicBearer}}
{{/isBasic}}
{{#isOAuth}}
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
openapi: 3.0.1
info:
title: ping test
version: '1.0'
servers:
- url: 'http://localhost:8080/'
paths:
/ping:
get:
operationId: pingGet
responses:
'201':
description: OK
components:
securitySchemes:
bearerAuth:
scheme: bearer
bearerFormat: token
type: http
security:
- bearerAuth: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[build]
rustflags = [
"-W", "missing_docs", # detects missing documentation for public members

"-W", "trivial_casts", # detects trivial casts which could be removed

"-W", "trivial_numeric_casts", # detects trivial casts of numeric types which could be removed

"-W", "unsafe_code", # usage of `unsafe` code

"-W", "unused_qualifications", # detects unnecessarily qualified names

"-W", "unused_extern_crates", # extern crates that are never used

"-W", "unused_import_braces", # unnecessary braces around an imported item

"-D", "warnings", # all warnings should be denied
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target
Cargo.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.cargo/config
.gitignore
Cargo.toml
README.md
api/openapi.yaml
docs/default_api.md
examples/ca.pem
examples/client/main.rs
examples/server-chain.pem
examples/server-key.pem
examples/server/main.rs
examples/server/server.rs
src/client/mod.rs
src/context.rs
src/header.rs
src/lib.rs
src/models.rs
src/server/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.0.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
[package]
name = "ping-bearer-auth"
version = "1.0.0"
authors = []
description = "No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)"
license = "Unlicense"
edition = "2018"

[features]
default = ["client", "server"]
client = [
"hyper", "hyper-openssl", "hyper-tls", "native-tls", "openssl", "url"
]
server = [
"serde_ignored", "hyper", "regex", "percent-encoding", "url", "lazy_static"
]
conversion = ["frunk", "frunk_derives", "frunk_core", "frunk-enum-core", "frunk-enum-derive"]

[target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))'.dependencies]
native-tls = { version = "0.2", optional = true }
hyper-tls = { version = "0.4", optional = true }

[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dependencies]
hyper-openssl = { version = "0.8", optional = true }
openssl = {version = "0.10", optional = true }

[dependencies]
# Common
async-trait = "0.1.24"
chrono = { version = "0.4", features = ["serde"] }
futures = "0.3"
swagger = "5.0.0-alpha-1"
log = "0.4.0"
mime = "0.3"

serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

# Crates included if required by the API definition

# Common between server and client features
hyper = {version = "0.13", optional = true}
serde_ignored = {version = "0.1.1", optional = true}
url = {version = "2.1", optional = true}

# Client-specific

# Server, and client callback-specific
lazy_static = { version = "1.4", optional = true }
percent-encoding = {version = "2.1.0", optional = true}
regex = {version = "1.3", optional = true}

# Conversion
frunk = { version = "0.3.0", optional = true }
frunk_derives = { version = "0.3.0", optional = true }
frunk_core = { version = "0.3.0", optional = true }
frunk-enum-derive = { version = "0.2.0", optional = true }
frunk-enum-core = { version = "0.2.0", optional = true }

[dev-dependencies]
clap = "2.25"
env_logger = "0.7"
tokio = { version = "0.2", features = ["rt-threaded", "macros", "stream"] }
native-tls = "0.2"
tokio-tls = "0.3"

[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dev-dependencies]
tokio-openssl = "0.4"
openssl = "0.10"

[[example]]
name = "client"
required-features = ["client"]

[[example]]
name = "server"
required-features = ["server"]
117 changes: 117 additions & 0 deletions samples/server/petstore/rust-server/output/ping-bearer-auth/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Rust API for ping-bearer-auth

No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

## Overview

This client/server was generated by the [openapi-generator]
(https://openapi-generator.tech) project. By using the
[OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote
server, you can easily generate a server stub.

To see how to make this your own, look here:

[README]((https://openapi-generator.tech))

- API version: 1.0




This autogenerated project defines an API crate `ping-bearer-auth` which contains:
* An `Api` trait defining the API in Rust.
* Data types representing the underlying data model.
* A `Client` type which implements `Api` and issues HTTP requests for each operation.
* A router which accepts HTTP requests and invokes the appropriate `Api` method for each operation.

It also contains an example server and client which make use of `ping-bearer-auth`:

* The example server starts up a web server using the `ping-bearer-auth`
router, and supplies a trivial implementation of `Api` which returns failure
for every operation.
* The example client provides a CLI which lets you invoke
any single operation on the `ping-bearer-auth` client by passing appropriate
arguments on the command line.

You can use the example server and client as a basis for your own code.
See below for [more detail on implementing a server](#writing-a-server).

## Examples

Run examples with:

```
cargo run --example <example-name>
```

To pass in arguments to the examples, put them after `--`, for example:

```
cargo run --example client -- --help
```

### Running the example server
To run the server, follow these simple steps:

```
cargo run --example server
```

### Running the example client
To run a client, follow one of the following simple steps:

```
cargo run --example client PingGet
```

### HTTPS
The examples can be run in HTTPS mode by passing in the flag `--https`, for example:

```
cargo run --example server -- --https
```

This will use the keys/certificates from the examples directory. Note that the
server chain is signed with `CN=localhost`.

## Using the generated library

The generated library has a few optional features that can be activated through Cargo.

* `server`
* This defaults to enabled and creates the basic skeleton of a server implementation based on hyper
* To create the server stack you'll need to provide an implementation of the API trait to provide the server function.
* `client`
* This defaults to enabled and creates the basic skeleton of a client implementation based on hyper
* The constructed client implements the API trait by making remote API call.
* `conversions`
* This defaults to disabled and creates extra derives on models to allow "transmogrification" between objects of structurally similar types.

See https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section for how to use features in your `Cargo.toml`.

## Documentation for API Endpoints

All URIs are relative to *http://localhost:8080*

Method | HTTP request | Description
------------- | ------------- | -------------
[**pingGet**](docs/default_api.md#pingGet) | **GET** /ping |


## Documentation For Models



## Documentation For Authorization

## bearerAuth
- **Type**: Bearer token authentication

Example
```
```

## Author



Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
openapi: 3.0.1
info:
title: ping test
version: "1.0"
servers:
- url: http://localhost:8080/
security:
- bearerAuth: []
paths:
/ping:
get:
operationId: pingGet
responses:
"201":
description: OK
components:
schemas: {}
securitySchemes:
bearerAuth:
bearerFormat: token
scheme: bearer
type: http

Loading