Skip to content

Commit

Permalink
chore(bors): merge pull request #879
Browse files Browse the repository at this point in the history
879: refactor(openapi/rust): use paperclip as code generator r=tiagolobocastro a=tiagolobocastro

We can now stop using our fork and use paperclip which allows us to keep the templates locally on openapi/templates.

Co-authored-by: Tiago Castro <[email protected]>
  • Loading branch information
mayastor-bors and tiagolobocastro committed Oct 23, 2024
2 parents 7158a9c + 58cc57c commit c02e0cb
Show file tree
Hide file tree
Showing 70 changed files with 2,604 additions and 263 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ __pycache__
/chart/charts/
/chart/Chart.lock
/openapi/*
!/openapi/templates/
!/openapi/Cargo.toml
!/openapi/build.rs
!/openapi/src/lib.rs
Expand Down
5 changes: 1 addition & 4 deletions control-plane/csi-driver/src/bin/controller/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,7 @@ impl RestApiClient {
// This call should be idempotent and should return success if the volume
// size is already greater than or equal to the target_volume_size.
let resize_result = vol_client
.put_volume_size(
volume_id,
ResizeVolumeBody::new(required_volume_size as usize),
)
.put_volume_size(volume_id, ResizeVolumeBody::new(required_volume_size))
.await
.map(|response| response.into_body());

Expand Down
6 changes: 3 additions & 3 deletions control-plane/plugin/src/resources/volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl Scale for Volume {
output: &utils::OutputFormat,
) -> PluginResult {
let req = openapi::models::ResizeVolumeBody {
size: requested_size as usize,
size: requested_size,
};
match RestClient::client()
.volumes_api()
Expand Down Expand Up @@ -431,6 +431,6 @@ fn child_uuid(uri: &str) -> String {
}
}

fn to_human_readable(val: isize) -> String {
::utils::bytes::into_human(val as u64)
fn to_human_readable(val: u64) -> String {
::utils::bytes::into_human(val)
}
1 change: 1 addition & 0 deletions control-plane/rest/openapi-specs/v0_api_spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2890,6 +2890,7 @@ components:
- startTime
- endTime
RebuildHistory:
type: object
properties:
targetUuid:
description: Id of the volume target
Expand Down
12 changes: 6 additions & 6 deletions control-plane/rest/service/src/v0/volumes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl apis::actix_server::Volumes for RestApi {
.resize(
&ResizeVolume {
uuid: volume_id.into(),
requested_size: resize_volume_body.size as u64,
requested_size: resize_volume_body.size,
cluster_capacity_limit: None,
},
None,
Expand Down Expand Up @@ -304,11 +304,11 @@ fn rebuild_record_to_rest(value: RebuildRecord) -> models::RebuildRecord {
value.child_uri,
value.src_uri,
state,
value.blocks_total as isize,
value.blocks_recovered as isize,
value.blocks_transferred as isize,
value.blocks_remaining as isize,
value.block_size as isize,
value.blocks_total,
value.blocks_recovered,
value.blocks_transferred,
value.blocks_remaining,
value.block_size,
value.is_partial,
start,
end,
Expand Down
2 changes: 1 addition & 1 deletion nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ self: super: {
sourcer = super.callPackage ./lib/sourcer.nix { };
images = super.callPackage ./pkgs/images { inherit img_tag img_org img_prefix; };
control-plane = super.callPackage ./pkgs/control-plane { inherit allInOne incremental tag rustFlags; };
openapi-generator = super.callPackage ./pkgs/openapi-generator { };
xfsprogs_5_16 = (import (super.sources).nixpkgs-22_05 { }).xfsprogs;
paperclip = super.callPackage ./pkgs/paperclip { };
}
5 changes: 3 additions & 2 deletions nix/pkgs/control-plane/cargo-project.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
, sources
, pkgs
, gitVersions
, openapi-generator
, paperclip
, which
, rdma-core
, systemdMinimal
Expand Down Expand Up @@ -57,6 +57,7 @@ let
"openapi/Cargo.toml"
"openapi/build.rs"
"openapi/src/lib.rs"
"openapi/templates"
"rpc"
"scripts/rust/generate-openapi-bindings.sh"
"scripts/rust/branch_ancestor.sh"
Expand All @@ -72,7 +73,7 @@ let
GIT_VERSION = "${gitVersions.tag_or_long}";

inherit LIBCLANG_PATH PROTOC PROTOC_INCLUDE;
nativeBuildInputs = [ clang pkg-config openapi-generator which git llvmPackages.bintools ];
nativeBuildInputs = [ clang pkg-config paperclip which git llvmPackages.bintools ];
buildInputs = [ llvmPackages.libclang protobuf openssl.dev systemdMinimal.dev utillinux.dev rdma-core ];
doCheck = false;
};
Expand Down
71 changes: 0 additions & 71 deletions nix/pkgs/openapi-generator/default.nix

This file was deleted.

6 changes: 0 additions & 6 deletions nix/pkgs/openapi-generator/source.json

This file was deleted.

28 changes: 28 additions & 0 deletions nix/pkgs/paperclip/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{ lib, sources, pkgs }:
let
src_json = lib.importJSON ./source.json;
hostPlatform = pkgs.rust.toRustTargetSpec pkgs.pkgsStatic.stdenv.hostPlatform;
in
pkgs.stdenv.mkDerivation {
pname = src_json.repo;
version = src_json.rev;

src = pkgs.fetchurl {
name = "paperclip-${src_json.rev}.tar.gz";
url = "https://github.com/${src_json.owner}/${src_json.repo}/releases/download/${src_json.rev}/paperclip-${hostPlatform}.tar.gz";
sha256 = src_json.hash;
};

sourceRoot = ".";

installPhase = ''
runHook preInstall
install -m755 -D paperclip-ng $out/bin/paperclip-ng
runHook postInstall
'';

meta = with lib; {
homepage = "https://github.com/${src_json.owner}/${src_json.repo}";
description = "OpenApi v3 Generator";
};
}
6 changes: 6 additions & 0 deletions nix/pkgs/paperclip/source.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"owner": "paperclip-rs",
"repo": "paperclip",
"rev": "v0.9.4",
"hash": "sha256-DIt+09p4TnTQq4b9ZNdq9f08Yiqc+Llco6B7zceX5FU="
}
2 changes: 1 addition & 1 deletion openapi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn main() {
panic!("openapi update failed: {:?}", output);
}

println!("cargo:rerun-if-changed=../nix/pkgs/openapi-generator");
println!("cargo:rerun-if-changed=../nix/pkgs/paperclip");
println!("cargo:rerun-if-changed=../control-plane/rest/openapi-specs");
// seems the internal timestamp is taken before build.rs runs, so we can't set this
// directive against files created during the build of build.rs??
Expand Down
61 changes: 61 additions & 0 deletions openapi/templates/default/Cargo.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
[package]
name = "{{{packageName}}}"
version = "{{{packageVersion}}}"
edition = "{{{packageEdition}}}"

[lib]
name = "{{{packageLibname}}}"
path = "src/lib.rs"

[features]
default = [ "tower-client-rls", "tower-trace" ]
actix-server = [ "actix" ]
actix-client = [ "actix", "actix-web-opentelemetry", "awc" ]
actix = [ "actix-web", "rustls" ]
tower-client-rls = [ "tower-client", "rustls_feat" ]
tower-client-tls = [ "tower-client", "hyper_tls_feat" ]
tower-client = [ "tower-hyper" ]
tower-hyper = [ "hyper", "tower", "tower-http", "http-body", "futures", "pin-project", "tokio" ]
hyper_tls_feat = [ "hyper-tls", "tokio-native-tls" ]
rustls_feat = [ "rustls", "webpki", "hyper-rustls" ]
tower-trace = [ "opentelemetry-jaeger", "tracing-opentelemetry", "opentelemetry", "opentelemetry-http", "tracing", "tracing-subscriber" ]

[dependencies]
serde = "^1.0"
serde_derive = "^1.0"
serde_json = "^1.0"
url = { version = "^2.4", features = ["serde"] }
async-trait = "0.1.73"
dyn-clonable = "0.9.0"
uuid = { version = "1.4.1", features = ["serde", "v4"] }
serde_urlencoded = "0.7"

# actix dependencies
actix-web = { version = "4.4.0", features = ["rustls-0_21"], optional = true }
actix-web-opentelemetry = { version = "0.17.0", optional = true }
awc = { version = "3.2.0", optional = true }

# tower and hyper dependencies
hyper = { version = "0.14.27", features = [ "client", "http1", "http2", "tcp", "stream" ], optional = true }
tower = { version = "0.4.13", features = [ "timeout", "util", "limit" ], optional = true }
tower-http = { version = "0.4.4", features = [ "trace", "map-response-body", "auth" ], optional = true }
tokio = { version = "1.32.0", features = ["full"], optional = true }
http-body = { version = "0.4.5", optional = true }
futures = { version = "0.3.28", optional = true }
pin-project = { version = "1.1.3", optional = true }

# SSL
rustls = { version = "0.21.12", optional = true, features = [ "dangerous_configuration" ] }
rustls-pemfile = "1.0.3"
webpki = { version = "0.22.2", optional = true }
hyper-rustls = { version = "0.24.1", optional = true }
hyper-tls = { version = "0.5.0", optional = true }
tokio-native-tls = { version = "0.3.1", optional = true }

# tracing and telemetry
opentelemetry-jaeger = { version = "0.21.0", features = ["rt-tokio-current-thread"], optional = true }
tracing-opentelemetry = { version = "0.23.0", optional = true }
opentelemetry = { version = "0.22.0", optional = true }
opentelemetry-http = { version = "0.11.1", optional = true }
tracing = { version = "0.1.37", optional = true }
tracing-subscriber = { version = "0.3.18", optional = true }
50 changes: 50 additions & 0 deletions openapi/templates/default/README.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Rust API client for {{{packageName}}}

{{#appDescriptionWithNewLines}}
{{{appDescriptionWithNewLines}}}
{{/appDescriptionWithNewLines}}

## Overview

- API version: {{{appVersion}}}
- Package version: {{{packageVersion}}}
{{^hideGenerationTimestamp}}
- Build date: {{{generatedDate}}}
{{/hideGenerationTimestamp}}
- Build package: {{{generatorClass}}}
{{#infoUrl}}
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
{{/infoUrl}}

## Installation

Put the package under your project folder and add the following to `Cargo.toml` under `[dependencies]`:

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

## Documentation for API Endpoints

All URIs are relative to *{{{basePath}}}*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{{classname}}}* | [**{{{operationId}}}**]({{{apiDocPath}}}{{classname}}.md#{{{operationIdLowerCase}}}) | **{{{httpMethod}}}** {{{path}}} | {{#summary}}{{{summary}}}{{/summary}}
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}

## Documentation For Models

{{#models}}{{#model}} - [{{{classname}}}]({{{modelDocPath}}}{{{classname}}}.md)
{{/model}}{{/models}}

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

```
cargo doc --open
```

## Author

{{#apiInfo}}{{#apis}}{{#-last}}{{{infoEmail}}}
{{/-last}}{{/apis}}{{/apiInfo}}
Loading

0 comments on commit c02e0cb

Please sign in to comment.