Skip to content

add codegen HTTP client #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 22, 2024
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
77 changes: 77 additions & 0 deletions generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash

if [ -z "$1" ]; then
echo "Required generator file is missing."
exit 1
fi

file="$1"

# Function to remove lines between start and end markers
remove_lines_between_markers() {
local file=$1
local start_marker=$2
local end_marker=$3

# Use sed to remove lines between start and end markers, inclusive
sed -i '' -e "/$start_marker/,/$end_marker/d" "$file"
}

# Function to process a single Rust file
process_rust_file() {
local file=$1

# Temporary file to store line numbers for start and end markers
tmp_file=$(mktemp)

# Find lines that start with 'impl ' and don't contain 'fmt::Display'
grep -n '^impl ' "$file" | grep -vE 'Configuration|fmt::Display|fmt::Debug|From<' > "$tmp_file"

# Read line numbers and process each block in reverse order
tac "$tmp_file" | while IFS= read -r line; do
# Extract line number from grep output
start_line=$(echo "$line" | cut -d: -f1)

# Find the end line (next line with only a '}')
end_line=$(awk "NR>$start_line && /^}$/ {print NR; exit}" "$file")

if [[ -n "$end_line" ]]; then
# Build the marker strings
start_marker="^$(sed "${start_line}q;d" "$file")$"
end_marker="^$(sed "${end_line}q;d" "$file")$"

# Remove lines between markers
remove_lines_between_markers "$file" "$start_marker" "$end_marker"
fi
done

# Clean up temporary file
rm "$tmp_file"

# Remove 'Default' from #[derive(...)] lines
sed -i '' -E 's/(\#\[derive\([^\)]*)Default,?\s*/\1/' "$file"
}

# Function to recursively process all Rust files in a directory
process_directory() {
local dir=$1

# Find all Rust files and process them
find "$dir" -type f -name "*.rs" | while IFS= read -r rust_file; do
echo "Processing $rust_file..."
process_rust_file "$rust_file"
done
}

# Remove codegen output from previous run
rm -rf ./openapi

# Run codegen
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:latest generate \
-i "/local/$file" \
-g rust \
-o /local/openapi \
--additional-properties=packageVersion=0.1.0

# Apply codemod to codegen
process_directory "openapi"
3 changes: 3 additions & 0 deletions openapi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/target/
**/*.rs.bk
Cargo.lock
23 changes: 23 additions & 0 deletions openapi/.openapi-generator-ignore
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
104 changes: 104 additions & 0 deletions openapi/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
.gitignore
.openapi-generator-ignore
.travis.yml
Cargo.toml
README.md
docs/AppInfo.md
docs/AppResponse.md
docs/AppleUserSocialConnection.md
docs/AppsApi.md
docs/AuthMethods.md
docs/AuthenticateApi.md
docs/AuthenticateVerifyNonceResponse.md
docs/CreateTransactionAuthenticateRequest.md
docs/CreateTransactionRegisterRequest.md
docs/CreateTransactionResponse.md
docs/ElementCustomization.md
docs/FontFamily.md
docs/GithubUserSocialConnection.md
docs/GoogleUserSocialConnection.md
docs/LayoutConfig.md
docs/Layouts.md
docs/Link.md
docs/ListDevicesResponse.md
docs/ListPaginatedUsersItem.md
docs/ListPaginatedUsersResponse.md
docs/MagicLinkAuthMethod.md
docs/Model400Error.md
docs/Model401Error.md
docs/Model403Error.md
docs/Model404Error.md
docs/Model409Error.md
docs/Model500Error.md
docs/Nonce.md
docs/OtpAuthMethod.md
docs/PaginatedLinks.md
docs/PasskeysAuthMethod.md
docs/Technologies.md
docs/TransactionsApi.md
docs/TtlDisplayUnit.md
docs/UserDevicesApi.md
docs/UserEventStatus.md
docs/UserInfo.md
docs/UserMetadataField.md
docs/UserMetadataFieldType.md
docs/UserRecentEvent.md
docs/UserResponse.md
docs/UserSocialConnections.md
docs/UserStatus.md
docs/UsersApi.md
docs/WebAuthnDevices.md
docs/WebAuthnIcons.md
docs/WebAuthnType.md
git_push.sh
src/apis/apps_api.rs
src/apis/authenticate_api.rs
src/apis/configuration.rs
src/apis/mod.rs
src/apis/transactions_api.rs
src/apis/user_devices_api.rs
src/apis/users_api.rs
src/lib.rs
src/models/app_info.rs
src/models/app_response.rs
src/models/apple_user_social_connection.rs
src/models/auth_methods.rs
src/models/authenticate_verify_nonce_response.rs
src/models/create_transaction_authenticate_request.rs
src/models/create_transaction_register_request.rs
src/models/create_transaction_response.rs
src/models/element_customization.rs
src/models/font_family.rs
src/models/github_user_social_connection.rs
src/models/google_user_social_connection.rs
src/models/layout_config.rs
src/models/layouts.rs
src/models/link.rs
src/models/list_devices_response.rs
src/models/list_paginated_users_item.rs
src/models/list_paginated_users_response.rs
src/models/magic_link_auth_method.rs
src/models/mod.rs
src/models/model_400_error.rs
src/models/model_401_error.rs
src/models/model_403_error.rs
src/models/model_404_error.rs
src/models/model_409_error.rs
src/models/model_500_error.rs
src/models/nonce.rs
src/models/otp_auth_method.rs
src/models/paginated_links.rs
src/models/passkeys_auth_method.rs
src/models/technologies.rs
src/models/ttl_display_unit.rs
src/models/user_event_status.rs
src/models/user_info.rs
src/models/user_metadata_field.rs
src/models/user_metadata_field_type.rs
src/models/user_recent_event.rs
src/models/user_response.rs
src/models/user_social_connections.rs
src/models/user_status.rs
src/models/web_authn_devices.rs
src/models/web_authn_icons.rs
src/models/web_authn_type.rs
1 change: 1 addition & 0 deletions openapi/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.8.0-SNAPSHOT
1 change: 1 addition & 0 deletions openapi/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: rust
16 changes: 16 additions & 0 deletions openapi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "openapi"
version = "0.1.0"
authors = ["support@passage.id"]
description = "Passage's management API to manage your Passage apps and users."
# Override this license by providing a License Object in the OpenAPI.
license = "Unlicense"
edition = "2021"

[dependencies]
serde = { version = "^1.0", features = ["derive"] }
serde_json = "^1.0"
serde_repr = "^0.1"
url = "^2.5"
uuid = { version = "^1.8", features = ["serde", "v4"] }
reqwest = { version = "^0.12", features = ["json", "multipart"] }
95 changes: 95 additions & 0 deletions openapi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Rust API client for openapi

Passage's management API to manage your Passage apps and users.

For more information, please visit [https://passage.id/support](https://passage.id/support)

## Overview

This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://openapis.org) from a remote server, you can easily generate an API client.

- API version: 1
- Package version: 0.1.0
- Generator version: 7.8.0-SNAPSHOT
- Build package: `org.openapitools.codegen.languages.RustClientCodegen`

## Installation

Put the package under your project folder in a directory named `openapi` and add the following to `Cargo.toml` under `[dependencies]`:

```
openapi = { path = "./openapi" }
```

## Documentation for API Endpoints

All URIs are relative to *https://api.passage.id/v1/apps/TODO*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*AppsApi* | [**get_app**](docs/AppsApi.md#get_app) | **GET** / | Get App
*AuthenticateApi* | [**authenticate_verify_nonce**](docs/AuthenticateApi.md#authenticate_verify_nonce) | **POST** /authenticate/verify | Verify the nonce received from a WebAuthn ceremony
*TransactionsApi* | [**create_authenticate_transaction**](docs/TransactionsApi.md#create_authenticate_transaction) | **POST** /transactions/authenticate | Create a transaction to start a user's authentication process
*TransactionsApi* | [**create_register_transaction**](docs/TransactionsApi.md#create_register_transaction) | **POST** /transactions/register | Create a transaction to start a user's registration process
*UserDevicesApi* | [**delete_user_devices**](docs/UserDevicesApi.md#delete_user_devices) | **DELETE** /users/{user_id}/devices/{device_id} | Delete a device for a user
*UserDevicesApi* | [**list_user_devices**](docs/UserDevicesApi.md#list_user_devices) | **GET** /users/{user_id}/devices | List User Devices
*UsersApi* | [**get_user**](docs/UsersApi.md#get_user) | **GET** /users/{user_id} | Get User
*UsersApi* | [**list_paginated_users**](docs/UsersApi.md#list_paginated_users) | **GET** /users | List Users


## Documentation For Models

- [AppInfo](docs/AppInfo.md)
- [AppResponse](docs/AppResponse.md)
- [AppleUserSocialConnection](docs/AppleUserSocialConnection.md)
- [AuthMethods](docs/AuthMethods.md)
- [AuthenticateVerifyNonceResponse](docs/AuthenticateVerifyNonceResponse.md)
- [CreateTransactionAuthenticateRequest](docs/CreateTransactionAuthenticateRequest.md)
- [CreateTransactionRegisterRequest](docs/CreateTransactionRegisterRequest.md)
- [CreateTransactionResponse](docs/CreateTransactionResponse.md)
- [ElementCustomization](docs/ElementCustomization.md)
- [FontFamily](docs/FontFamily.md)
- [GithubUserSocialConnection](docs/GithubUserSocialConnection.md)
- [GoogleUserSocialConnection](docs/GoogleUserSocialConnection.md)
- [LayoutConfig](docs/LayoutConfig.md)
- [Layouts](docs/Layouts.md)
- [Link](docs/Link.md)
- [ListDevicesResponse](docs/ListDevicesResponse.md)
- [ListPaginatedUsersItem](docs/ListPaginatedUsersItem.md)
- [ListPaginatedUsersResponse](docs/ListPaginatedUsersResponse.md)
- [MagicLinkAuthMethod](docs/MagicLinkAuthMethod.md)
- [Model400Error](docs/Model400Error.md)
- [Model401Error](docs/Model401Error.md)
- [Model403Error](docs/Model403Error.md)
- [Model404Error](docs/Model404Error.md)
- [Model409Error](docs/Model409Error.md)
- [Model500Error](docs/Model500Error.md)
- [Nonce](docs/Nonce.md)
- [OtpAuthMethod](docs/OtpAuthMethod.md)
- [PaginatedLinks](docs/PaginatedLinks.md)
- [PasskeysAuthMethod](docs/PasskeysAuthMethod.md)
- [Technologies](docs/Technologies.md)
- [TtlDisplayUnit](docs/TtlDisplayUnit.md)
- [UserEventStatus](docs/UserEventStatus.md)
- [UserInfo](docs/UserInfo.md)
- [UserMetadataField](docs/UserMetadataField.md)
- [UserMetadataFieldType](docs/UserMetadataFieldType.md)
- [UserRecentEvent](docs/UserRecentEvent.md)
- [UserResponse](docs/UserResponse.md)
- [UserSocialConnections](docs/UserSocialConnections.md)
- [UserStatus](docs/UserStatus.md)
- [WebAuthnDevices](docs/WebAuthnDevices.md)
- [WebAuthnIcons](docs/WebAuthnIcons.md)
- [WebAuthnType](docs/WebAuthnType.md)


To get access to the crate's generated documentation, use:

```
cargo doc --open
```

## Author

support@passage.id

50 changes: 50 additions & 0 deletions openapi/docs/AppInfo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# AppInfo

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**additional_auth_origins** | **Vec<String>** | |
**allowed_callback_urls** | **Vec<String>** | The valid URLs where users can be redirected after authentication. |
**allowed_identifier** | **String** | |
**allowed_logout_urls** | **Vec<String>** | The valid URLs where users can be redirected after logging out. |
**application_login_uri** | **String** | A route within your application that redirects to the Authorization URL endpoint. |
**auth_fallback_method** | **String** | Deprecated Property. Please refer to `auth_methods` to view settings for individual authentication methods. |
**auth_fallback_method_ttl** | **i32** | Deprecated Property. Please refer to `auth_methods` to view settings for individual authentication methods. |
**auth_methods** | [**models::AuthMethods**](AuthMethods.md) | |
**auth_origin** | **String** | |
**auto_theme_enabled** | **bool** | |
**created_at** | **String** | |
**default_language** | **String** | |
**id** | **String** | |
**layouts** | [**models::Layouts**](Layouts.md) | |
**login_url** | **String** | |
**light_logo_url** | Option<**String**> | | [optional]
**dark_logo_url** | Option<**String**> | | [optional]
**name** | **String** | |
**hosted** | **bool** | whether or not the app's login page hosted by passage |
**hosted_subdomain** | **String** | the subdomain of the app's hosted login page |
**id_token_lifetime** | Option<**i32**> | | [optional]
**passage_branding** | **bool** | |
**profile_management** | **bool** | |
**public_signup** | **bool** | |
**redirect_url** | **String** | |
**refresh_absolute_lifetime** | **i32** | |
**refresh_enabled** | **bool** | |
**refresh_inactivity_lifetime** | **i32** | |
**require_email_verification** | **bool** | |
**require_identifier_verification** | **bool** | |
**required_identifier** | **String** | |
**role** | **String** | |
**rsa_public_key** | **String** | |
**secret** | Option<**String**> | can only be retrieved by an app admin | [optional]
**session_timeout_length** | **i32** | |
**r#type** | **String** | |
**user_metadata_schema** | [**Vec<models::UserMetadataField>**](UserMetadataField.md) | |
**technologies** | [**Vec<models::Technologies>**](Technologies.md) | |
**element_customization** | [**models::ElementCustomization**](ElementCustomization.md) | |
**element_customization_dark** | [**models::ElementCustomization**](ElementCustomization.md) | |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


11 changes: 11 additions & 0 deletions openapi/docs/AppResponse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# AppResponse

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**app** | [**models::AppInfo**](AppInfo.md) | |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


Loading