Skip to content

Commit

Permalink
chore: use latest stable openapi-generator-cli
Browse files Browse the repository at this point in the history
Turns out that the openapi-generator-cli npm crate is a whole major
version behind (6 vs 7) of the openapi-generator jar. This change
removes the usage of the npm package as it was only a wrapper for
downloading the jar and running it. Now we have a simple bash script
that uses that latest stable release of openapi-generator.

This means we now have the fix for the extra .clone() calls and can
enable -D warnings for test/example code not just the binary build.
  • Loading branch information
nathanielc committed Jan 24, 2024
1 parent bc3ccea commit c76b9b3
Show file tree
Hide file tree
Showing 21 changed files with 156 additions and 104 deletions.
1 change: 0 additions & 1 deletion .github/workflows/create-release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ jobs:
- run: |
git config user.email "[email protected]"
git config user.name "Github Automation"
- run: npm install @openapitools/[email protected] -g
- name: Create release PR
run: make RELEASE_LEVEL=${{ github.event.inputs.level }} release-pr
1 change: 0 additions & 1 deletion .github/workflows/rust-build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ jobs:
run: make check-clippy
- name: Check generated servers
run: |
npm install @openapitools/[email protected] -g
make check-api-server
make check-kubo-rpc-server
test:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@

peer*
sync_test.sh

openapi-generator-cli.jar
50 changes: 50 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Therefore may be useful in ensuring a change
# is ready to pass CI checks.

RUSTFLAGS = --cfg tokio_unstable
RUSTFLAGS = -D warnings --cfg tokio_unstable
CARGO = RUSTFLAGS='${RUSTFLAGS}' cargo

RELEASE_LEVEL ?= minor
Expand Down Expand Up @@ -55,7 +55,6 @@ check-kubo-rpc-server:
./ci-scripts/check_kubo_rpc_server.sh

.PHONY: release
release: RUSTFLAGS += -D warnings
release:
$(CARGO) build -p ceramic-one --locked --release

Expand Down
2 changes: 1 addition & 1 deletion api-server/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.6.0
7.2.0
1 change: 1 addition & 0 deletions api-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ mime = "0.3"

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

# Crates included if required by the API definition

Expand Down
2 changes: 1 addition & 1 deletion api-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To see how to make this your own, look here:
[README]((https://openapi-generator.tech))

- API version: 0.9.0
- Build date: 2024-01-17T12:46:40.618372865-07:00[America/Denver]
- Build date: 2024-01-24T14:39:40.257161505-07:00[America/Denver]



Expand Down
4 changes: 0 additions & 4 deletions api-server/examples/server/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ where
event: models::Event,
context: &C,
) -> Result<EventsPostResponse, ApiError> {
let context = context.clone();
info!(
"events_post({:?}) - X-Span-ID: {:?}",
event,
Expand All @@ -129,7 +128,6 @@ where

/// Test the liveness of the Ceramic node
async fn liveness_get(&self, context: &C) -> Result<LivenessGetResponse, ApiError> {
let context = context.clone();
info!("liveness_get() - X-Span-ID: {:?}", context.get().0.clone());
Err(ApiError("Generic failure".into()))
}
Expand All @@ -145,14 +143,12 @@ where
limit: Option<f64>,
context: &C,
) -> Result<SubscribeSortKeySortValueGetResponse, ApiError> {
let context = context.clone();
info!("subscribe_sort_key_sort_value_get(\"{}\", \"{}\", {:?}, {:?}, {:?}, {:?}) - X-Span-ID: {:?}", sort_key, sort_value, controller, stream_id, offset, limit, context.get().0.clone());
Err(ApiError("Generic failure".into()))
}

/// Get the version of the Ceramic node
async fn version_post(&self, context: &C) -> Result<VersionPostResponse, ApiError> {
let context = context.clone();
info!("version_post() - X-Span-ID: {:?}", context.get().0.clone());
Err(ApiError("Generic failure".into()))
}
Expand Down
8 changes: 5 additions & 3 deletions api-server/src/models.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#![allow(clippy::useless_vec)]
#![allow(unused_qualifications)]

use validator::Validate;

#[cfg(any(feature = "client", feature = "server"))]
use crate::header;
use crate::models;

/// A Ceramic event as part of a Ceramic Stream
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)]
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
pub struct Event {
/// Multibase encoding of event id bytes.
Expand Down Expand Up @@ -158,7 +160,7 @@ impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderVal
}

/// Version of the Ceramic node in semver format, e.g. 2.1.0
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)]
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
pub struct Version {
/// Version of the Ceramic node
Expand All @@ -182,7 +184,7 @@ impl std::string::ToString for Version {
let params: Vec<Option<String>> = vec![self
.version
.as_ref()
.map(|version| vec!["version".to_string(), version.to_string()].join(","))];
.map(|version| ["version".to_string(), version.to_string()].join(","))];

params.into_iter().flatten().collect::<Vec<_>>().join(",")
}
Expand Down
8 changes: 4 additions & 4 deletions api-server/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,9 @@ where
CONTENT_TYPE,
HeaderValue::from_str("application/json")
.expect("Unable to create Content-Type header for SUBSCRIBE_SORT_KEY_SORT_VALUE_GET_SUCCESS"));
let body = serde_json::to_string(&body)
let body_content = serde_json::to_string(&body)
.expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body);
*response.body_mut() = Body::from(body_content);
}
},
Err(_) => {
Expand Down Expand Up @@ -461,9 +461,9 @@ where
CONTENT_TYPE,
HeaderValue::from_str("application/json")
.expect("Unable to create Content-Type header for VERSION_POST_SUCCESS"));
let body = serde_json::to_string(&body)
let body_content = serde_json::to_string(&body)
.expect("impossible to fail to serialize");
*response.body_mut() = Body::from(body);
*response.body_mut() = Body::from(body_content);
}
},
Err(_) => {
Expand Down
2 changes: 1 addition & 1 deletion ci-scripts/gen_api_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cd $DIR/..


# Generate crate
npx @openapitools/openapi-generator-cli \
./ci-scripts/openapi-generator-cli.sh \
generate \
-i api/ceramic.yaml \
-g rust-server \
Expand Down
2 changes: 1 addition & 1 deletion ci-scripts/gen_kubo_rpc_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cd $DIR/..


# Generate crate
npx @openapitools/openapi-generator-cli \
./ci-scripts/openapi-generator-cli.sh \
generate \
-i kubo-rpc/kubo-rpc.yaml \
-g rust-server \
Expand Down
17 changes: 17 additions & 0 deletions ci-scripts/openapi-generator-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
#
# This script is a small wrapper to download the jar file for openapi-generator-cli and run it.

VERSION='7.2.0'
jar=openapi-generator-cli.jar

if [ ! -f $jar ]
then
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/${VERSION}/openapi-generator-cli-${VERSION}.jar -O $jar
fi

java -ea \
-Xms512M \
-Xmx1024M \
-server \
-jar ./${jar} "$@"
2 changes: 1 addition & 1 deletion kubo-rpc-server/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.6.0
7.2.0
1 change: 1 addition & 0 deletions kubo-rpc-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ mime = "0.3"

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

# Crates included if required by the API definition
mime_0_2 = { package = "mime", version = "0.2.6", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion kubo-rpc-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To see how to make this your own, look here:
[README]((https://openapi-generator.tech))

- API version: 0.9.0
- Build date: 2024-01-17T12:46:50.987533413-07:00[America/Denver]
- Build date: 2024-01-24T14:39:45.959361295-07:00[America/Denver]



Expand Down
13 changes: 0 additions & 13 deletions kubo-rpc-server/examples/server/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ where
offline: Option<bool>,
context: &C,
) -> Result<BlockGetPostResponse, ApiError> {
let context = context.clone();
info!(
"block_get_post(\"{}\", {:?}, {:?}) - X-Span-ID: {:?}",
arg,
Expand All @@ -142,7 +141,6 @@ where
pin: Option<bool>,
context: &C,
) -> Result<BlockPutPostResponse, ApiError> {
let context = context.clone();
info!(
"block_put_post({:?}, {:?}, {:?}, {:?}) - X-Span-ID: {:?}",
file,
Expand All @@ -160,7 +158,6 @@ where
arg: String,
context: &C,
) -> Result<BlockStatPostResponse, ApiError> {
let context = context.clone();
info!(
"block_stat_post(\"{}\") - X-Span-ID: {:?}",
arg,
Expand All @@ -176,7 +173,6 @@ where
output_codec: Option<models::Codecs>,
context: &C,
) -> Result<DagGetPostResponse, ApiError> {
let context = context.clone();
info!(
"dag_get_post(\"{}\", {:?}) - X-Span-ID: {:?}",
arg,
Expand All @@ -192,7 +188,6 @@ where
file: swagger::ByteArray,
context: &C,
) -> Result<DagImportPostResponse, ApiError> {
let context = context.clone();
info!(
"dag_import_post({:?}) - X-Span-ID: {:?}",
file,
Expand All @@ -209,7 +204,6 @@ where
input_codec: Option<models::Codecs>,
context: &C,
) -> Result<DagPutPostResponse, ApiError> {
let context = context.clone();
info!(
"dag_put_post({:?}, {:?}, {:?}) - X-Span-ID: {:?}",
file,
Expand All @@ -226,7 +220,6 @@ where
arg: String,
context: &C,
) -> Result<DagResolvePostResponse, ApiError> {
let context = context.clone();
info!(
"dag_resolve_post(\"{}\") - X-Span-ID: {:?}",
arg,
Expand All @@ -237,7 +230,6 @@ where

/// Report identifying information about a node
async fn id_post(&self, arg: Option<String>, context: &C) -> Result<IdPostResponse, ApiError> {
let context = context.clone();
info!(
"id_post({:?}) - X-Span-ID: {:?}",
arg,
Expand All @@ -254,7 +246,6 @@ where
progress: Option<bool>,
context: &C,
) -> Result<PinAddPostResponse, ApiError> {
let context = context.clone();
info!(
"pin_add_post(\"{}\", {:?}, {:?}) - X-Span-ID: {:?}",
arg,
Expand All @@ -267,7 +258,6 @@ where

/// Remove a block from the pin store
async fn pin_rm_post(&self, arg: String, context: &C) -> Result<PinRmPostResponse, ApiError> {
let context = context.clone();
info!(
"pin_rm_post(\"{}\") - X-Span-ID: {:?}",
arg,
Expand All @@ -282,7 +272,6 @@ where
arg: &Vec<String>,
context: &C,
) -> Result<SwarmConnectPostResponse, ApiError> {
let context = context.clone();
info!(
"swarm_connect_post({:?}) - X-Span-ID: {:?}",
arg,
Expand All @@ -293,7 +282,6 @@ where

/// Report connected peers
async fn swarm_peers_post(&self, context: &C) -> Result<SwarmPeersPostResponse, ApiError> {
let context = context.clone();
info!(
"swarm_peers_post() - X-Span-ID: {:?}",
context.get().0.clone()
Expand All @@ -303,7 +291,6 @@ where

/// Report server version
async fn version_post(&self, context: &C) -> Result<VersionPostResponse, ApiError> {
let context = context.clone();
info!("version_post() - X-Span-ID: {:?}", context.get().0.clone());
Err(ApiError("Generic failure".into()))
}
Expand Down
Loading

0 comments on commit c76b9b3

Please sign in to comment.