From 156be1821abab7cc15c156f23f62812a59943c08 Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Sat, 31 May 2025 12:03:58 +0200 Subject: [PATCH] Cleaned up api client sources --- backend-actix/gamenight-api.yaml | 19 +- gamenight-api-client-rs/.gitignore | 5 + .../.openapi-generator-ignore | 23 -- .../.openapi-generator/FILES | 27 -- .../.openapi-generator/VERSION | 1 - gamenight-api-client-rs/.travis.yml | 1 - gamenight-api-client-rs/README.md | 2 + gamenight-api-client-rs/build.rs | 9 + .../docs/AddGamenightRequestBody.md | 12 - gamenight-api-client-rs/docs/DefaultApi.md | 158 ------------ gamenight-api-client-rs/docs/Failure.md | 11 - gamenight-api-client-rs/docs/Gamenight.md | 14 -- .../docs/GetGamenightRequest.md | 11 - .../docs/GetToken401Response.md | 11 - gamenight-api-client-rs/docs/Login.md | 12 - gamenight-api-client-rs/docs/Registration.md | 15 -- gamenight-api-client-rs/docs/Token.md | 11 - .../regenerate_openapi_lib.sh | 3 - .../src/apis/configuration.rs | 51 ---- .../src/apis/default_api.rs | 234 ------------------ gamenight-api-client-rs/src/apis/mod.rs | 116 --------- gamenight-api-client-rs/src/lib.rs | 11 - .../src/models/add_gamenight_request_body.rs | 30 --- gamenight-api-client-rs/src/models/failure.rs | 29 --- .../src/models/gamenight.rs | 36 --- .../src/models/get_gamenight_request.rs | 27 -- .../src/models/get_token_401_response.rs | 27 -- gamenight-api-client-rs/src/models/login.rs | 30 --- gamenight-api-client-rs/src/models/mod.rs | 16 -- .../src/models/registration.rs | 39 --- gamenight-api-client-rs/src/models/token.rs | 27 -- 31 files changed, 34 insertions(+), 984 deletions(-) delete mode 100644 gamenight-api-client-rs/.openapi-generator-ignore delete mode 100644 gamenight-api-client-rs/.openapi-generator/FILES delete mode 100644 gamenight-api-client-rs/.openapi-generator/VERSION delete mode 100644 gamenight-api-client-rs/.travis.yml create mode 100644 gamenight-api-client-rs/build.rs delete mode 100644 gamenight-api-client-rs/docs/AddGamenightRequestBody.md delete mode 100644 gamenight-api-client-rs/docs/DefaultApi.md delete mode 100644 gamenight-api-client-rs/docs/Failure.md delete mode 100644 gamenight-api-client-rs/docs/Gamenight.md delete mode 100644 gamenight-api-client-rs/docs/GetGamenightRequest.md delete mode 100644 gamenight-api-client-rs/docs/GetToken401Response.md delete mode 100644 gamenight-api-client-rs/docs/Login.md delete mode 100644 gamenight-api-client-rs/docs/Registration.md delete mode 100644 gamenight-api-client-rs/docs/Token.md delete mode 100755 gamenight-api-client-rs/regenerate_openapi_lib.sh delete mode 100644 gamenight-api-client-rs/src/apis/configuration.rs delete mode 100644 gamenight-api-client-rs/src/apis/default_api.rs delete mode 100644 gamenight-api-client-rs/src/apis/mod.rs delete mode 100644 gamenight-api-client-rs/src/lib.rs delete mode 100644 gamenight-api-client-rs/src/models/add_gamenight_request_body.rs delete mode 100644 gamenight-api-client-rs/src/models/failure.rs delete mode 100644 gamenight-api-client-rs/src/models/gamenight.rs delete mode 100644 gamenight-api-client-rs/src/models/get_gamenight_request.rs delete mode 100644 gamenight-api-client-rs/src/models/get_token_401_response.rs delete mode 100644 gamenight-api-client-rs/src/models/login.rs delete mode 100644 gamenight-api-client-rs/src/models/mod.rs delete mode 100644 gamenight-api-client-rs/src/models/registration.rs delete mode 100644 gamenight-api-client-rs/src/models/token.rs diff --git a/backend-actix/gamenight-api.yaml b/backend-actix/gamenight-api.yaml index 1eb88ef..ebba8dd 100644 --- a/backend-actix/gamenight-api.yaml +++ b/backend-actix/gamenight-api.yaml @@ -39,6 +39,12 @@ paths: $ref: '#/components/responses/FailureResponse' description: 'Create a new user given a registration token and user information, username and email must be unique, and password and password_repeat must match.' parameters: [] + get: + description: 'Get a user from primary id' + parameters: [] + responses: + '200': + $ref: '#/components/responses/UserResponse' /gamenights: get: summary: Your GET endpoint @@ -97,11 +103,16 @@ components: type: string owner_id: type: string + participants: + type: array + items: + type: string required: - id - name - datetime - owner_id + - participants Failure: title: Failure type: object @@ -219,11 +230,17 @@ components: items: $ref: '#/components/schemas/Gamenight' GamenightResponse: - description: Example response + description: A gamenight being hosted content: application/json: schema: $ref: '#/components/schemas/Gamenight' + UserResponse: + description: A user in the gamenight system + content: + application/json: + schema: + $ref: '#/components/schemas/User' securitySchemes: JWT-Auth: type: http diff --git a/gamenight-api-client-rs/.gitignore b/gamenight-api-client-rs/.gitignore index 6aa1064..5a5d79a 100644 --- a/gamenight-api-client-rs/.gitignore +++ b/gamenight-api-client-rs/.gitignore @@ -1,3 +1,8 @@ +src +docs /target/ **/*.rs.bk Cargo.lock +.openapi-generator +.openapi-generator-ignore +.travis.yml diff --git a/gamenight-api-client-rs/.openapi-generator-ignore b/gamenight-api-client-rs/.openapi-generator-ignore deleted file mode 100644 index 7484ee5..0000000 --- a/gamenight-api-client-rs/.openapi-generator-ignore +++ /dev/null @@ -1,23 +0,0 @@ -# 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 diff --git a/gamenight-api-client-rs/.openapi-generator/FILES b/gamenight-api-client-rs/.openapi-generator/FILES deleted file mode 100644 index e073619..0000000 --- a/gamenight-api-client-rs/.openapi-generator/FILES +++ /dev/null @@ -1,27 +0,0 @@ -.gitignore -.travis.yml -Cargo.toml -README.md -docs/AddGamenightRequestBody.md -docs/DefaultApi.md -docs/Failure.md -docs/Gamenight.md -docs/GetGamenightRequest.md -docs/GetToken401Response.md -docs/Login.md -docs/Registration.md -docs/Token.md -git_push.sh -src/apis/configuration.rs -src/apis/default_api.rs -src/apis/mod.rs -src/lib.rs -src/models/add_gamenight_request_body.rs -src/models/failure.rs -src/models/gamenight.rs -src/models/get_gamenight_request.rs -src/models/get_token_401_response.rs -src/models/login.rs -src/models/mod.rs -src/models/registration.rs -src/models/token.rs diff --git a/gamenight-api-client-rs/.openapi-generator/VERSION b/gamenight-api-client-rs/.openapi-generator/VERSION deleted file mode 100644 index eb1dc6a..0000000 --- a/gamenight-api-client-rs/.openapi-generator/VERSION +++ /dev/null @@ -1 +0,0 @@ -7.13.0 diff --git a/gamenight-api-client-rs/.travis.yml b/gamenight-api-client-rs/.travis.yml deleted file mode 100644 index 22761ba..0000000 --- a/gamenight-api-client-rs/.travis.yml +++ /dev/null @@ -1 +0,0 @@ -language: rust diff --git a/gamenight-api-client-rs/README.md b/gamenight-api-client-rs/README.md index ce18ebb..d1f0aa5 100644 --- a/gamenight-api-client-rs/README.md +++ b/gamenight-api-client-rs/README.md @@ -32,6 +32,7 @@ Class | Method | HTTP request | Description *DefaultApi* | [**get_token**](docs/DefaultApi.md#get_token) | **GET** /token | *DefaultApi* | [**post_gamenight**](docs/DefaultApi.md#post_gamenight) | **POST** /gamenight | *DefaultApi* | [**post_register**](docs/DefaultApi.md#post_register) | **POST** /user | +*DefaultApi* | [**user_get**](docs/DefaultApi.md#user_get) | **GET** /user | ## Documentation For Models @@ -44,6 +45,7 @@ Class | Method | HTTP request | Description - [Login](docs/Login.md) - [Registration](docs/Registration.md) - [Token](docs/Token.md) + - [User](docs/User.md) To get access to the crate's generated documentation, use: diff --git a/gamenight-api-client-rs/build.rs b/gamenight-api-client-rs/build.rs new file mode 100644 index 0000000..a950cd5 --- /dev/null +++ b/gamenight-api-client-rs/build.rs @@ -0,0 +1,9 @@ +use std::process::Command; + +fn main() { + let _ = + Command::new("openapi-generator") + .args(["generate", "-i", "../backend-actix/gamenight-api.yaml", "-g", "rust", "--additional-properties=withSeparateModelsAndApi=true,modelPackage=gamenight_model,apiPackage=gamenight_api,packageName=gamenight-api-client-rs,packageVersion=0.1.0"]) + .output() + .expect("Failed to generate models sources for the gamenight API"); +} \ No newline at end of file diff --git a/gamenight-api-client-rs/docs/AddGamenightRequestBody.md b/gamenight-api-client-rs/docs/AddGamenightRequestBody.md deleted file mode 100644 index 394e62d..0000000 --- a/gamenight-api-client-rs/docs/AddGamenightRequestBody.md +++ /dev/null @@ -1,12 +0,0 @@ -# AddGamenightRequestBody - -## Properties - -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**name** | Option<**String**> | | [optional] -**datetime** | Option<**String**> | | [optional] - -[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) - - diff --git a/gamenight-api-client-rs/docs/DefaultApi.md b/gamenight-api-client-rs/docs/DefaultApi.md deleted file mode 100644 index f0339d0..0000000 --- a/gamenight-api-client-rs/docs/DefaultApi.md +++ /dev/null @@ -1,158 +0,0 @@ -# \DefaultApi - -All URIs are relative to *http://localhost:8080* - -Method | HTTP request | Description -------------- | ------------- | ------------- -[**get_gamenight**](DefaultApi.md#get_gamenight) | **GET** /gamenight | -[**get_gamenights**](DefaultApi.md#get_gamenights) | **GET** /gamenights | Your GET endpoint -[**get_token**](DefaultApi.md#get_token) | **GET** /token | -[**post_gamenight**](DefaultApi.md#post_gamenight) | **POST** /gamenight | -[**post_register**](DefaultApi.md#post_register) | **POST** /user | - - - -## get_gamenight - -> models::Gamenight get_gamenight(get_gamenight_request) - - -### Parameters - - -Name | Type | Description | Required | Notes -------------- | ------------- | ------------- | ------------- | ------------- -**get_gamenight_request** | Option<[**GetGamenightRequest**](GetGamenightRequest.md)> | | | - -### Return type - -[**models::Gamenight**](Gamenight.md) - -### Authorization - -[JWT-Auth](../README.md#JWT-Auth) - -### HTTP request headers - -- **Content-Type**: application/json -- **Accept**: application/json, application/xml - -[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) - - -## get_gamenights - -> Vec get_gamenights() -Your GET endpoint - -Retrieve the list of gamenights on this gamenight server. Requires authorization. - -### Parameters - -This endpoint does not need any parameter. - -### Return type - -[**Vec**](Gamenight.md) - -### Authorization - -[JWT-Auth](../README.md#JWT-Auth) - -### HTTP request headers - -- **Content-Type**: Not defined -- **Accept**: application/json, application/xml - -[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) - - -## get_token - -> models::Token get_token(login) - - -Submit your credentials to get a JWT-token to use with the rest of the api. - -### Parameters - - -Name | Type | Description | Required | Notes -------------- | ------------- | ------------- | ------------- | ------------- -**login** | Option<[**Login**](Login.md)> | | | - -### Return type - -[**models::Token**](Token.md) - -### Authorization - -No authorization required - -### HTTP request headers - -- **Content-Type**: application/json -- **Accept**: application/json, application/xml - -[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) - - -## post_gamenight - -> post_gamenight(add_gamenight_request_body) - - -Add a gamenight by providing a name and a date, only available when providing an JWT token. - -### Parameters - - -Name | Type | Description | Required | Notes -------------- | ------------- | ------------- | ------------- | ------------- -**add_gamenight_request_body** | Option<[**AddGamenightRequestBody**](AddGamenightRequestBody.md)> | | | - -### Return type - - (empty response body) - -### Authorization - -[JWT-Auth](../README.md#JWT-Auth) - -### HTTP request headers - -- **Content-Type**: application/json -- **Accept**: application/json, application/xml - -[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) - - -## post_register - -> post_register(registration) - - -Create a new user given a registration token and user information, username and email must be unique, and password and password_repeat must match. - -### Parameters - - -Name | Type | Description | Required | Notes -------------- | ------------- | ------------- | ------------- | ------------- -**registration** | Option<[**Registration**](Registration.md)> | | | - -### Return type - - (empty response body) - -### Authorization - -No authorization required - -### HTTP request headers - -- **Content-Type**: application/json -- **Accept**: application/json, application/xml - -[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) - diff --git a/gamenight-api-client-rs/docs/Failure.md b/gamenight-api-client-rs/docs/Failure.md deleted file mode 100644 index 3d1208a..0000000 --- a/gamenight-api-client-rs/docs/Failure.md +++ /dev/null @@ -1,11 +0,0 @@ -# Failure - -## Properties - -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**message** | Option<**String**> | | [optional] - -[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) - - diff --git a/gamenight-api-client-rs/docs/Gamenight.md b/gamenight-api-client-rs/docs/Gamenight.md deleted file mode 100644 index 87a131d..0000000 --- a/gamenight-api-client-rs/docs/Gamenight.md +++ /dev/null @@ -1,14 +0,0 @@ -# Gamenight - -## Properties - -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**id** | **String** | | -**name** | **String** | | -**datetime** | **String** | | -**owner_id** | **String** | | - -[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) - - diff --git a/gamenight-api-client-rs/docs/GetGamenightRequest.md b/gamenight-api-client-rs/docs/GetGamenightRequest.md deleted file mode 100644 index 2c223f1..0000000 --- a/gamenight-api-client-rs/docs/GetGamenightRequest.md +++ /dev/null @@ -1,11 +0,0 @@ -# GetGamenightRequest - -## Properties - -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**id** | Option<**String**> | | [optional] - -[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) - - diff --git a/gamenight-api-client-rs/docs/GetToken401Response.md b/gamenight-api-client-rs/docs/GetToken401Response.md deleted file mode 100644 index d1720d7..0000000 --- a/gamenight-api-client-rs/docs/GetToken401Response.md +++ /dev/null @@ -1,11 +0,0 @@ -# GetToken401Response - -## Properties - -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**message** | **String** | | - -[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) - - diff --git a/gamenight-api-client-rs/docs/Login.md b/gamenight-api-client-rs/docs/Login.md deleted file mode 100644 index 1ca3108..0000000 --- a/gamenight-api-client-rs/docs/Login.md +++ /dev/null @@ -1,12 +0,0 @@ -# Login - -## Properties - -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**username** | **String** | | -**password** | **String** | | - -[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) - - diff --git a/gamenight-api-client-rs/docs/Registration.md b/gamenight-api-client-rs/docs/Registration.md deleted file mode 100644 index e52dde9..0000000 --- a/gamenight-api-client-rs/docs/Registration.md +++ /dev/null @@ -1,15 +0,0 @@ -# Registration - -## Properties - -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**username** | **String** | | -**email** | **String** | | -**password** | **String** | | -**password_repeat** | **String** | | -**registration_token** | **String** | | - -[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) - - diff --git a/gamenight-api-client-rs/docs/Token.md b/gamenight-api-client-rs/docs/Token.md deleted file mode 100644 index c7a4df2..0000000 --- a/gamenight-api-client-rs/docs/Token.md +++ /dev/null @@ -1,11 +0,0 @@ -# Token - -## Properties - -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**jwt_token** | Option<**String**> | | [optional] - -[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) - - diff --git a/gamenight-api-client-rs/regenerate_openapi_lib.sh b/gamenight-api-client-rs/regenerate_openapi_lib.sh deleted file mode 100755 index 77fd585..0000000 --- a/gamenight-api-client-rs/regenerate_openapi_lib.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -openapi-generator-cli generate -i ../backend-actix/gamenight-api.yaml -g rust --additional-properties=withSeparateModelsAndApi=true,modelPackage=gamenight_model,apiPackage=gamenight_api,packageName=gamenight-api-client-rs,packageVersion=0.1.0 diff --git a/gamenight-api-client-rs/src/apis/configuration.rs b/gamenight-api-client-rs/src/apis/configuration.rs deleted file mode 100644 index c01b7b5..0000000 --- a/gamenight-api-client-rs/src/apis/configuration.rs +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Gamenight - * - * Api specifaction for a Gamenight server - * - * The version of the OpenAPI document: 1.0 - * Contact: dennis@brentj.es - * Generated by: https://openapi-generator.tech - */ - - - -#[derive(Debug, Clone)] -pub struct Configuration { - pub base_path: String, - pub user_agent: Option, - pub client: reqwest::Client, - pub basic_auth: Option, - pub oauth_access_token: Option, - pub bearer_access_token: Option, - pub api_key: Option, -} - -pub type BasicAuth = (String, Option); - -#[derive(Debug, Clone)] -pub struct ApiKey { - pub prefix: Option, - pub key: String, -} - - -impl Configuration { - pub fn new() -> Configuration { - Configuration::default() - } -} - -impl Default for Configuration { - fn default() -> Self { - Configuration { - base_path: "http://localhost:8080".to_owned(), - user_agent: Some("OpenAPI-Generator/1.0/rust".to_owned()), - client: reqwest::Client::new(), - basic_auth: None, - oauth_access_token: None, - bearer_access_token: None, - api_key: None, - } - } -} diff --git a/gamenight-api-client-rs/src/apis/default_api.rs b/gamenight-api-client-rs/src/apis/default_api.rs deleted file mode 100644 index 11efdbe..0000000 --- a/gamenight-api-client-rs/src/apis/default_api.rs +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Gamenight - * - * Api specifaction for a Gamenight server - * - * The version of the OpenAPI document: 1.0 - * Contact: dennis@brentj.es - * Generated by: https://openapi-generator.tech - */ - - -use reqwest; -use serde::{Deserialize, Serialize, de::Error as _}; -use crate::{apis::ResponseContent, models}; -use super::{Error, configuration, ContentType}; - - -/// struct for typed errors of method [`get_gamenight`] -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(untagged)] -pub enum GetGamenightError { - Status401(models::Failure), - Status422(models::Failure), - UnknownValue(serde_json::Value), -} - -/// struct for typed errors of method [`get_gamenights`] -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(untagged)] -pub enum GetGamenightsError { - Status400(models::Failure), - Status401(models::Failure), - UnknownValue(serde_json::Value), -} - -/// struct for typed errors of method [`get_token`] -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(untagged)] -pub enum GetTokenError { - Status401(models::Failure), - UnknownValue(serde_json::Value), -} - -/// struct for typed errors of method [`post_gamenight`] -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(untagged)] -pub enum PostGamenightError { - Status401(models::Failure), - Status422(models::Failure), - UnknownValue(serde_json::Value), -} - -/// struct for typed errors of method [`post_register`] -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(untagged)] -pub enum PostRegisterError { - Status422(models::Failure), - UnknownValue(serde_json::Value), -} - - -pub async fn get_gamenight(configuration: &configuration::Configuration, get_gamenight_request: Option) -> Result> { - // add a prefix to parameters to efficiently prevent name collisions - let p_get_gamenight_request = get_gamenight_request; - - let uri_str = format!("{}/gamenight", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - req_builder = req_builder.json(&p_get_gamenight_request); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); - - if !status.is_client_error() && !status.is_server_error() { - let content = resp.text().await?; - match content_type { - ContentType::Json => serde_json::from_str(&content).map_err(Error::from), - ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Gamenight`"))), - ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Gamenight`")))), - } - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -/// Retrieve the list of gamenights on this gamenight server. Requires authorization. -pub async fn get_gamenights(configuration: &configuration::Configuration, ) -> Result, Error> { - - let uri_str = format!("{}/gamenights", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); - - if !status.is_client_error() && !status.is_server_error() { - let content = resp.text().await?; - match content_type { - ContentType::Json => serde_json::from_str(&content).map_err(Error::from), - ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Gamenight>`"))), - ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Gamenight>`")))), - } - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -/// Submit your credentials to get a JWT-token to use with the rest of the api. -pub async fn get_token(configuration: &configuration::Configuration, login: Option) -> Result> { - // add a prefix to parameters to efficiently prevent name collisions - let p_login = login; - - let uri_str = format!("{}/token", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - req_builder = req_builder.json(&p_login); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - let content_type = resp - .headers() - .get("content-type") - .and_then(|v| v.to_str().ok()) - .unwrap_or("application/octet-stream"); - let content_type = super::ContentType::from(content_type); - - if !status.is_client_error() && !status.is_server_error() { - let content = resp.text().await?; - match content_type { - ContentType::Json => serde_json::from_str(&content).map_err(Error::from), - ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Token`"))), - ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Token`")))), - } - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -/// Add a gamenight by providing a name and a date, only available when providing an JWT token. -pub async fn post_gamenight(configuration: &configuration::Configuration, add_gamenight_request_body: Option) -> Result<(), Error> { - // add a prefix to parameters to efficiently prevent name collisions - let p_add_gamenight_request_body = add_gamenight_request_body; - - let uri_str = format!("{}/gamenight", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - if let Some(ref token) = configuration.bearer_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - req_builder = req_builder.json(&p_add_gamenight_request_body); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - - if !status.is_client_error() && !status.is_server_error() { - Ok(()) - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - -/// Create a new user given a registration token and user information, username and email must be unique, and password and password_repeat must match. -pub async fn post_register(configuration: &configuration::Configuration, registration: Option) -> Result<(), Error> { - // add a prefix to parameters to efficiently prevent name collisions - let p_registration = registration; - - let uri_str = format!("{}/user", configuration.base_path); - let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - if let Some(ref user_agent) = configuration.user_agent { - req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); - } - req_builder = req_builder.json(&p_registration); - - let req = req_builder.build()?; - let resp = configuration.client.execute(req).await?; - - let status = resp.status(); - - if !status.is_client_error() && !status.is_server_error() { - Ok(()) - } else { - let content = resp.text().await?; - let entity: Option = serde_json::from_str(&content).ok(); - Err(Error::ResponseError(ResponseContent { status, content, entity })) - } -} - diff --git a/gamenight-api-client-rs/src/apis/mod.rs b/gamenight-api-client-rs/src/apis/mod.rs deleted file mode 100644 index fdcc89b..0000000 --- a/gamenight-api-client-rs/src/apis/mod.rs +++ /dev/null @@ -1,116 +0,0 @@ -use std::error; -use std::fmt; - -#[derive(Debug, Clone)] -pub struct ResponseContent { - pub status: reqwest::StatusCode, - pub content: String, - pub entity: Option, -} - -#[derive(Debug)] -pub enum Error { - Reqwest(reqwest::Error), - Serde(serde_json::Error), - Io(std::io::Error), - ResponseError(ResponseContent), -} - -impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let (module, e) = match self { - Error::Reqwest(e) => ("reqwest", e.to_string()), - Error::Serde(e) => ("serde", e.to_string()), - Error::Io(e) => ("IO", e.to_string()), - Error::ResponseError(e) => ("response", format!("status code {}", e.status)), - }; - write!(f, "error in {}: {}", module, e) - } -} - -impl error::Error for Error { - fn source(&self) -> Option<&(dyn error::Error + 'static)> { - Some(match self { - Error::Reqwest(e) => e, - Error::Serde(e) => e, - Error::Io(e) => e, - Error::ResponseError(_) => return None, - }) - } -} - -impl From for Error { - fn from(e: reqwest::Error) -> Self { - Error::Reqwest(e) - } -} - -impl From for Error { - fn from(e: serde_json::Error) -> Self { - Error::Serde(e) - } -} - -impl From for Error { - fn from(e: std::io::Error) -> Self { - Error::Io(e) - } -} - -pub fn urlencode>(s: T) -> String { - ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() -} - -pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { - if let serde_json::Value::Object(object) = value { - let mut params = vec![]; - - for (key, value) in object { - match value { - serde_json::Value::Object(_) => params.append(&mut parse_deep_object( - &format!("{}[{}]", prefix, key), - value, - )), - serde_json::Value::Array(array) => { - for (i, value) in array.iter().enumerate() { - params.append(&mut parse_deep_object( - &format!("{}[{}][{}]", prefix, key, i), - value, - )); - } - }, - serde_json::Value::String(s) => params.push((format!("{}[{}]", prefix, key), s.clone())), - _ => params.push((format!("{}[{}]", prefix, key), value.to_string())), - } - } - - return params; - } - - unimplemented!("Only objects are supported with style=deepObject") -} - -/// Internal use only -/// A content type supported by this client. -#[allow(dead_code)] -enum ContentType { - Json, - Text, - Unsupported(String) -} - -impl From<&str> for ContentType { - fn from(content_type: &str) -> Self { - if content_type.starts_with("application") && content_type.contains("json") { - return Self::Json; - } else if content_type.starts_with("text/plain") { - return Self::Text; - } else { - return Self::Unsupported(content_type.to_string()); - } - } -} - -pub mod default_api; - -pub mod configuration; diff --git a/gamenight-api-client-rs/src/lib.rs b/gamenight-api-client-rs/src/lib.rs deleted file mode 100644 index e152062..0000000 --- a/gamenight-api-client-rs/src/lib.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![allow(unused_imports)] -#![allow(clippy::too_many_arguments)] - -extern crate serde_repr; -extern crate serde; -extern crate serde_json; -extern crate url; -extern crate reqwest; - -pub mod apis; -pub mod models; diff --git a/gamenight-api-client-rs/src/models/add_gamenight_request_body.rs b/gamenight-api-client-rs/src/models/add_gamenight_request_body.rs deleted file mode 100644 index 122e904..0000000 --- a/gamenight-api-client-rs/src/models/add_gamenight_request_body.rs +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Gamenight - * - * Api specifaction for a Gamenight server - * - * The version of the OpenAPI document: 1.0 - * Contact: dennis@brentj.es - * Generated by: https://openapi-generator.tech - */ - -use crate::models; -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] -pub struct AddGamenightRequestBody { - #[serde(rename = "name", skip_serializing_if = "Option::is_none")] - pub name: Option, - #[serde(rename = "datetime", skip_serializing_if = "Option::is_none")] - pub datetime: Option, -} - -impl AddGamenightRequestBody { - pub fn new() -> AddGamenightRequestBody { - AddGamenightRequestBody { - name: None, - datetime: None, - } - } -} - diff --git a/gamenight-api-client-rs/src/models/failure.rs b/gamenight-api-client-rs/src/models/failure.rs deleted file mode 100644 index f3a9225..0000000 --- a/gamenight-api-client-rs/src/models/failure.rs +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Gamenight - * - * Api specifaction for a Gamenight server - * - * The version of the OpenAPI document: 1.0 - * Contact: dennis@brentj.es - * Generated by: https://openapi-generator.tech - */ - -use crate::models; -use serde::{Deserialize, Serialize}; - -/// Failure : -#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] -pub struct Failure { - #[serde(rename = "message", skip_serializing_if = "Option::is_none")] - pub message: Option, -} - -impl Failure { - /// - pub fn new() -> Failure { - Failure { - message: None, - } - } -} - diff --git a/gamenight-api-client-rs/src/models/gamenight.rs b/gamenight-api-client-rs/src/models/gamenight.rs deleted file mode 100644 index ca66efc..0000000 --- a/gamenight-api-client-rs/src/models/gamenight.rs +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Gamenight - * - * Api specifaction for a Gamenight server - * - * The version of the OpenAPI document: 1.0 - * Contact: dennis@brentj.es - * Generated by: https://openapi-generator.tech - */ - -use crate::models; -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] -pub struct Gamenight { - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "name")] - pub name: String, - #[serde(rename = "datetime")] - pub datetime: String, - #[serde(rename = "owner_id")] - pub owner_id: String, -} - -impl Gamenight { - pub fn new(id: String, name: String, datetime: String, owner_id: String) -> Gamenight { - Gamenight { - id, - name, - datetime, - owner_id, - } - } -} - diff --git a/gamenight-api-client-rs/src/models/get_gamenight_request.rs b/gamenight-api-client-rs/src/models/get_gamenight_request.rs deleted file mode 100644 index a1e327a..0000000 --- a/gamenight-api-client-rs/src/models/get_gamenight_request.rs +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Gamenight - * - * Api specifaction for a Gamenight server - * - * The version of the OpenAPI document: 1.0 - * Contact: dennis@brentj.es - * Generated by: https://openapi-generator.tech - */ - -use crate::models; -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] -pub struct GetGamenightRequest { - #[serde(rename = "id", skip_serializing_if = "Option::is_none")] - pub id: Option, -} - -impl GetGamenightRequest { - pub fn new() -> GetGamenightRequest { - GetGamenightRequest { - id: None, - } - } -} - diff --git a/gamenight-api-client-rs/src/models/get_token_401_response.rs b/gamenight-api-client-rs/src/models/get_token_401_response.rs deleted file mode 100644 index fb8fcfd..0000000 --- a/gamenight-api-client-rs/src/models/get_token_401_response.rs +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Gamenight - * - * Api specifaction for a Gamenight server - * - * The version of the OpenAPI document: 1.0 - * Contact: dennis@brentj.es - * Generated by: https://openapi-generator.tech - */ - -use crate::models; -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] -pub struct GetToken401Response { - #[serde(rename = "message")] - pub message: String, -} - -impl GetToken401Response { - pub fn new(message: String) -> GetToken401Response { - GetToken401Response { - message, - } - } -} - diff --git a/gamenight-api-client-rs/src/models/login.rs b/gamenight-api-client-rs/src/models/login.rs deleted file mode 100644 index b814207..0000000 --- a/gamenight-api-client-rs/src/models/login.rs +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Gamenight - * - * Api specifaction for a Gamenight server - * - * The version of the OpenAPI document: 1.0 - * Contact: dennis@brentj.es - * Generated by: https://openapi-generator.tech - */ - -use crate::models; -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] -pub struct Login { - #[serde(rename = "username")] - pub username: String, - #[serde(rename = "password")] - pub password: String, -} - -impl Login { - pub fn new(username: String, password: String) -> Login { - Login { - username, - password, - } - } -} - diff --git a/gamenight-api-client-rs/src/models/mod.rs b/gamenight-api-client-rs/src/models/mod.rs deleted file mode 100644 index 9cd49d8..0000000 --- a/gamenight-api-client-rs/src/models/mod.rs +++ /dev/null @@ -1,16 +0,0 @@ -pub mod add_gamenight_request_body; -pub use self::add_gamenight_request_body::AddGamenightRequestBody; -pub mod failure; -pub use self::failure::Failure; -pub mod gamenight; -pub use self::gamenight::Gamenight; -pub mod get_gamenight_request; -pub use self::get_gamenight_request::GetGamenightRequest; -pub mod get_token_401_response; -pub use self::get_token_401_response::GetToken401Response; -pub mod login; -pub use self::login::Login; -pub mod registration; -pub use self::registration::Registration; -pub mod token; -pub use self::token::Token; diff --git a/gamenight-api-client-rs/src/models/registration.rs b/gamenight-api-client-rs/src/models/registration.rs deleted file mode 100644 index 8ae4044..0000000 --- a/gamenight-api-client-rs/src/models/registration.rs +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Gamenight - * - * Api specifaction for a Gamenight server - * - * The version of the OpenAPI document: 1.0 - * Contact: dennis@brentj.es - * Generated by: https://openapi-generator.tech - */ - -use crate::models; -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] -pub struct Registration { - #[serde(rename = "username")] - pub username: String, - #[serde(rename = "email")] - pub email: String, - #[serde(rename = "password")] - pub password: String, - #[serde(rename = "password_repeat")] - pub password_repeat: String, - #[serde(rename = "registration_token")] - pub registration_token: String, -} - -impl Registration { - pub fn new(username: String, email: String, password: String, password_repeat: String, registration_token: String) -> Registration { - Registration { - username, - email, - password, - password_repeat, - registration_token, - } - } -} - diff --git a/gamenight-api-client-rs/src/models/token.rs b/gamenight-api-client-rs/src/models/token.rs deleted file mode 100644 index b985517..0000000 --- a/gamenight-api-client-rs/src/models/token.rs +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Gamenight - * - * Api specifaction for a Gamenight server - * - * The version of the OpenAPI document: 1.0 - * Contact: dennis@brentj.es - * Generated by: https://openapi-generator.tech - */ - -use crate::models; -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] -pub struct Token { - #[serde(rename = "jwt_token", skip_serializing_if = "Option::is_none")] - pub jwt_token: Option, -} - -impl Token { - pub fn new() -> Token { - Token { - jwt_token: None, - } - } -} -