Skip to content

Commit

Permalink
Update swagger and schemas to 7.2.0, update dotnet in readme to 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dani-garcia committed Feb 7, 2024
1 parent 1595306 commit b42f189
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 137 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ The first step is to generate the swagger documents from the server repository.

```bash
# src/Api
dotnet swagger tofile --output ../../api.json ./bin/Debug/net6.0/Api.dll internal
dotnet swagger tofile --output ../../api.json ./bin/Debug/net8.0/Api.dll internal

# src/Identity
ASPNETCORE_ENVIRONMENT=development dotnet swagger tofile --output ../../identity.json ./bin/Debug/net6.0/Identity.dll v1
ASPNETCORE_ENVIRONMENT=development dotnet swagger tofile --output ../../identity.json ./bin/Debug/net8.0/Identity.dll v1
```

### OpenApi Generator
Expand Down
2 changes: 1 addition & 1 deletion openapitools.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "6.5.0"
"version": "7.2.0"
}
}
57 changes: 42 additions & 15 deletions support/openapi-template/Cargo.mustache
Original file line number Diff line number Diff line change
@@ -1,42 +1,69 @@
[package]
name = "{{{packageName}}}"
version = "{{#lambdaVersion}}{{{packageVersion}}}{{/lambdaVersion}}"
{{#infoEmail}}
authors = ["{{{.}}}"]
{{/infoEmail}}
{{^infoEmail}}
authors = ["OpenAPI Generator team and contributors"]
{{/infoEmail}}
{{#appDescription}}
description = "{{{.}}}"
{{/appDescription}}
{{#licenseInfo}}
license = "{{.}}"
{{/licenseInfo}}
{{^licenseInfo}}
# Override this license by providing a License Object in the OpenAPI.
license = "Unlicense"
{{/licenseInfo}}
edition = "2018"
{{#publishRustRegistry}}
publish = ["{{.}}"]
{{/publishRustRegistry}}
{{#repositoryUrl}}
repository = "{{.}}"
{{/repositoryUrl}}
{{#documentationUrl}}
documentation = "{{.}}"
{{/documentationUrl}}
{{#homePageUrl}}
homepage = "{{.}}
{{/homePageUrl}}

[dependencies]
serde = "^1.0"
serde_derive = "^1.0"
{{#serdeWith}}
serde_with = "^2.0"
{{/serdeWith}}
serde_json = "^1.0"
serde_repr = "^0.1"
url = "^2.2"
uuid = { version = "^1.0", features = ["serde"] }
uuid = { version = "^1.0", features = ["serde", "v4"] }
{{#hyper}}
hyper = { version = "~0.14", features = ["full"] }
hyper-tls = "~0.5"
http = "~0.2"
serde_yaml = "0.7"
base64 = "~0.7.0"
futures = "^0.3"
{{/hyper}}
{{#withAWSV4Signature}}
aws-sigv4 = "0.3.0"
http = "0.2.5"
secrecy = "0.8.0"
{{/withAWSV4Signature}}
{{#reqwest}}
{{^supportAsync}}
reqwest = "~0.9"
[dependencies.reqwest]
version = "^0.11"
features = ["json", "blocking", "multipart"]
{{/supportAsync}}
{{#supportAsync}}
{{#supportMiddleware}}
reqwest-middleware = "0.2.0"
{{/supportMiddleware}}
[dependencies.reqwest]
version = "^0.11"
features = ["json", "multipart"]
default-features = false
{{/supportAsync}}
{{/reqwest}}
{{#withAWSV4Signature}}
aws-sigv4 = "0.3.0"
http = "0.2.5"
secrecy = "0.8.0"
{{/withAWSV4Signature}}

[dev-dependencies]
{{#hyper}}
tokio-core = "*"
{{/hyper}}
Empty file modified support/openapi-template/git_push.sh.mustache
100644 → 100755
Empty file.
16 changes: 8 additions & 8 deletions support/openapi-template/hyper/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<C: hyper::client::connect::Connect> {{{classname}}}Client<C>
pub trait {{{classname}}} {
{{#operations}}
{{#operation}}
fn {{{operationId}}}(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}&str{{/isString}}{{#isUuid}}uuid::Uuid{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Pin<Box<dyn Future<Output = Result<{{^returnType}}(){{/returnType}}{{#returnType}}{{{returnType}}}{{/returnType}}, Error>>>>;
fn {{{operationId}}}(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}{{^isUuid}}&str{{/isUuid}}{{/isString}}{{#isUuid}}&str{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Pin<Box<dyn Future<Output = Result<{{^returnType}}(){{/returnType}}{{#returnType}}{{{returnType}}}{{/returnType}}, Error>>>>;
{{/operation}}
{{/operations}}
}
Expand All @@ -38,7 +38,7 @@ impl<C: hyper::client::connect::Connect>{{{classname}}} for {{{classname}}}Clien
{{#operations}}
{{#operation}}
#[allow(unused_mut)]
fn {{{operationId}}}(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}&str{{/isString}}{{#isUuid}}uuid::Uuid{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Pin<Box<dyn Future<Output = Result<{{^returnType}}(){{/returnType}}{{#returnType}}{{{.}}}{{/returnType}}, Error>>>> {
fn {{{operationId}}}(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}{{^isUuid}}&str{{/isUuid}}{{/isString}}{{#isUuid}}&str{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Pin<Box<dyn Future<Output = Result<{{^returnType}}(){{/returnType}}{{#returnType}}{{{.}}}{{/returnType}}, Error>>>> {
let mut req = __internal_request::Request::new(hyper::Method::{{{httpMethod.toUpperCase}}}, "{{{path}}}".to_string())
{{#hasAuthMethods}}
{{#authMethods}}
Expand All @@ -49,9 +49,9 @@ impl<C: hyper::client::connect::Connect>{{{classname}}} for {{{classname}}}Clien
param_name: "{{{keyParamName}}}".to_owned(),
}))
{{/isApiKey}}
{{#isBasic}}
{{#isBasicBasic}}
.with_auth(__internal_request::Auth::Basic)
{{/isBasic}}
{{/isBasicBasic}}
{{#isOAuth}}
.with_auth(__internal_request::Auth::Oauth)
{{/isOAuth}}
Expand All @@ -66,7 +66,7 @@ impl<C: hyper::client::connect::Connect>{{{classname}}} for {{{classname}}}Clien
{{#isNullable}}
match {{{paramName}}} {
Some(param_value) => { req = req.with_query_param("{{{baseName}}}".to_string(), param_value{{#isArray}}.join(","){{/isArray}}.to_string()); },
None => { req = req.with_query_param("{{{baseName}}}".to_string(), String::new()); },
None => { req = req.with_query_param("{{{baseName}}}".to_string(), "".to_string()); },
}
{{/isNullable}}
{{/required}}
Expand All @@ -85,7 +85,7 @@ impl<C: hyper::client::connect::Connect>{{{classname}}} for {{{classname}}}Clien
{{#isNullable}}
match {{{paramName}}} {
Some(param_value) => { req = req.with_path_param("{{{baseName}}}".to_string(), param_value{{#isArray}}.join(","){{/isArray}}.to_string()); },
None => { req = req.with_path_param("{{{baseName}}}".to_string(), String::new()); },
None => { req = req.with_path_param("{{{baseName}}}".to_string(), "".to_string()); },
}
{{/isNullable}}
{{/required}}
Expand All @@ -104,7 +104,7 @@ impl<C: hyper::client::connect::Connect>{{{classname}}} for {{{classname}}}Clien
{{#isNullable}}
match {{{paramName}}} {
Some(param_value) => { req = req.with_header_param("{{{baseName}}}".to_string(), param_value{{#isArray}}.join(","){{/isArray}}.to_string()); },
None => { req = req.with_header_param("{{{baseName}}}".to_string(), String::new()); },
None => { req = req.with_header_param("{{{baseName}}}".to_string(), "".to_string()); },
}
{{/isNullable}}
{{/required}}
Expand Down Expand Up @@ -143,7 +143,7 @@ impl<C: hyper::client::connect::Connect>{{{classname}}} for {{{classname}}}Clien
{{#isNullable}}
match {{{paramName}}} {
Some(param_value) => { req = req.with_form_param("{{{baseName}}}".to_string(), param_value{{#isArray}}.join(","){{/isArray}}.to_string()); },
None => { req = req.with_form_param("{{{baseName}}}".to_string(), String::new()); },
None => { req = req.with_form_param("{{{baseName}}}".to_string(), "".to_string()); },
}
{{/isNullable}}
{{/required}}
Expand Down
5 changes: 0 additions & 5 deletions support/openapi-template/lib.mustache
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#![allow(warnings)]
#![allow(clippy::all)]

#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate serde_repr;

extern crate serde;
extern crate serde_json;
Expand Down
46 changes: 5 additions & 41 deletions support/openapi-template/model.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,8 @@
/// {{{classname}}} : {{{description}}}
{{/description}}

{{!-- for repr(int) enum schemas --}}
{{#isEnum}}
{{#isInteger}}
/// {{{description}}}
#[repr(i64)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize_repr, Deserialize_repr)]
pub enum {{{classname}}} {
{{#allowableValues}}
{{#enumVars}}
{{{name}}} = {{{value}}},
{{/enumVars}}{{/allowableValues}}
}

impl ToString for {{{classname}}} {
fn to_string(&self) -> String {
match self {
{{#allowableValues}}
{{#enumVars}}
Self::{{{name}}} => String::from("{{{value}}}"),
{{/enumVars}}
{{/allowableValues}}
}
}
}

impl Default for {{{classname}}} {
fn default() -> {{{classname}}} {
{{#allowableValues}}
Self::{{ enumVars.0.name }}
{{/allowableValues}}
}
}
{{/isInteger}}
{{/isEnum}}
{{!-- for enum schemas --}}
{{#isEnum}}
{{^isInteger}}
/// {{{description}}}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum {{{classname}}} {
Expand Down Expand Up @@ -71,7 +36,6 @@ impl Default for {{{classname}}} {
{{/allowableValues}}
}
}
{{/isInteger}}
{{/isEnum}}

{{!-- for schemas that have a discriminator --}}
Expand Down Expand Up @@ -100,25 +64,25 @@ pub enum {{{classname}}} {
{{!-- for non-enum schemas --}}
{{^isEnum}}
{{^discriminator}}
#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct {{{classname}}} {
{{#vars}}
{{#description}}
/// {{{.}}}
{{/description}}
#[serde(rename = "{{{baseName}}}"{{^required}}, skip_serializing_if = "Option::is_none"{{/required}})]
pub {{{name}}}: {{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{^required}}Option<{{/required}}{{#isEnum}}{{#isArray}}{{#uniqueItems}}std::collections::HashSet<{{/uniqueItems}}{{^uniqueItems}}Vec<{{/uniqueItems}}{{/isArray}}{{{enumName}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{^isEnum}}{{#isModel}}Box<{{{dataType}}}>{{/isModel}}{{^isModel}}{{{dataType}}}{{/isModel}}{{/isEnum}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^required}}>{{/required}},
#[serde(rename = "{{{baseName}}}"{{^required}}{{#isNullable}}, default, with = "::serde_with::rust::double_option"{{/isNullable}}{{/required}}{{^required}}, skip_serializing_if = "Option::is_none"{{/required}}{{#required}}{{#isNullable}}, deserialize_with = "Option::deserialize"{{/isNullable}}{{/required}})]
pub {{{name}}}: {{#isNullable}}Option<{{/isNullable}}{{^required}}Option<{{/required}}{{#isEnum}}{{#isArray}}{{#uniqueItems}}std::collections::HashSet<{{/uniqueItems}}{{^uniqueItems}}Vec<{{/uniqueItems}}{{/isArray}}{{{enumName}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{^isEnum}}{{#isModel}}Box<{{{dataType}}}>{{/isModel}}{{^isModel}}{{{dataType}}}{{/isModel}}{{/isEnum}}{{#isNullable}}>{{/isNullable}}{{^required}}>{{/required}},
{{/vars}}
}

impl {{{classname}}} {
{{#description}}
/// {{{.}}}
{{/description}}
pub fn new({{#requiredVars}}{{{name}}}: {{#isNullable}}Option<{{/isNullable}}{{#isEnum}}{{{enumName}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}}>{{/isNullable}}{{^-last}}, {{/-last}}{{/requiredVars}}) -> {{{classname}}} {
pub fn new({{#requiredVars}}{{{name}}}: {{#isNullable}}Option<{{/isNullable}}{{#isEnum}}{{#isArray}}{{#uniqueItems}}std::collections::HashSet<{{/uniqueItems}}{{^uniqueItems}}Vec<{{/uniqueItems}}{{/isArray}}{{{enumName}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}}>{{/isNullable}}{{^-last}}, {{/-last}}{{/requiredVars}}) -> {{{classname}}} {
{{{classname}}} {
{{#vars}}
{{{name}}}{{^required}}{{#isArray}}: None{{/isArray}}{{#isMap}}: None{{/isMap}}{{^isContainer}}: None{{/isContainer}}{{/required}}{{#required}}{{#isModel}}: Box::new({{{name}}}){{/isModel}}{{/required}},
{{{name}}}{{^required}}{{#isContainer}}{{#isArray}}: None{{/isArray}}{{#isMap}}: None{{/isMap}}{{^isArray}}{{^isMap}}{{#isNullable}}: None{{/isNullable}}{{/isMap}}{{/isArray}}{{/isContainer}}{{^isContainer}}: None{{/isContainer}}{{/required}}{{#required}}{{#isModel}}: {{^isNullable}}Box::new({{{name}}}){{/isNullable}}{{#isNullable}}if let Some(x) = {{{name}}} {Some(Box::new(x))} else {None}{{/isNullable}}{{/isModel}}{{/required}},
{{/vars}}
}
}
Expand Down
Loading

0 comments on commit b42f189

Please sign in to comment.