Skip to content
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

fix(openapiv3-indexmap): support indexmap 2 #508

Merged
merged 4 commits into from
Sep 27, 2023
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
24 changes: 12 additions & 12 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ jobs:
command: build
args: --all --features "actix3 cli chrono url uuid swagger-ui rapidoc v3 actix3-validator"

- name: Build actix2 features
uses: actions-rs/cargo@v1
timeout-minutes: 10
with:
command: build
args: --all --features "actix2 cli chrono url uuid swagger-ui rapidoc v3"
# - name: Build actix2 features
# uses: actions-rs/cargo@v1
# timeout-minutes: 10
# with:
# command: build
# args: --all --features "actix2 cli chrono url uuid swagger-ui rapidoc v3"

- name: Run actix tests
uses: actions-rs/cargo@v1
Expand All @@ -91,12 +91,12 @@ jobs:
command: test
args: --all --features "actix3 cli chrono url uuid swagger-ui rapidoc v3 actix3-validator"

- name: Run actix2 tests
uses: actions-rs/cargo@v1
timeout-minutes: 20
with:
command: test
args: --all --features "actix2 cli chrono url uuid swagger-ui rapidoc v3"
# - name: Run actix2 tests
# uses: actions-rs/cargo@v1
# timeout-minutes: 20
# with:
# command: test
# args: --all --features "actix2 cli chrono url uuid swagger-ui rapidoc v3"

- name: Install cargo-cache
continue-on-error: true
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.9.0] - Unreleased
### Fixed
- Support latest openapiv3 and indexmap. [PR#507](https://github.com/paperclip-rs/paperclip/pull/507)

## [0.8.2] - 2023-09-27
### Fixed
- Pin openapiv3 to wa breaking change. [PR#508](https://github.com/paperclip-rs/paperclip/pull/508)

## [0.8.1] - 2023-08-20
### Added
- Add support for `PathBuf` type. [PR#502](https://github.com/paperclip-rs/paperclip/pull/502)
Expand Down
13 changes: 6 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "paperclip"
version = "0.8.1"
version = "0.9.0"
edition = "2018"
description = "OpenAPI tooling library for type-safe compile-time checked HTTP APIs"
documentation = "https://paperclip-rs.github.io/paperclip/paperclip"
Expand All @@ -17,8 +17,8 @@ path = "src/bin/main.rs"
required-features = ["cli"]

[dependencies]
paperclip-actix = { path = "plugins/actix-web", version = "0.6.1", optional = true }
paperclip-core = { path = "core", version = "0.6.1" }
paperclip-actix = { path = "plugins/actix-web", version = "0.7.0", optional = true }
paperclip-core = { path = "core", version = "0.7.0" }
paperclip-macros = { path = "macros", version = "0.6.3", optional = true }

env_logger = { version = "0.8", optional = true }
Expand All @@ -40,16 +40,15 @@ url_dep = { version = ">=1.7,<3", package = "url" }
thiserror = "1.0"
anyhow = "1.0"
once_cell = "1.4"
openapiv3 = { version = "1.0.2", optional = true }
indexmap = { version = "1.0", features = ["serde-1", "std"], optional = true }
openapiv3 = { version = "1.0.3", optional = true }

[dev-dependencies]
actix-rt1 = { version = "1.0", package = "actix-rt" }
actix-service1 = { version = "1", package = "actix-service" }
actix-service2 = { version = "2", package = "actix-service" }
actix-web-validator2 = { version = "2.2", package = "actix-web-validator" }
actix-web-validator3 = { version = "3.0", package = "actix-web-validator" }
actix-web2 = { version = "2", default-features = false, package = "actix-web" }
#actix-web2 = { version = "2", default-features = false, package = "actix-web" }
actix-web3 = { version = "3", default-features = false, package = "actix-web" }
actix-web4 = { version = "4", default-features = false, package = "actix-web" }
chrono_dev = { version = "0.4", features = ["serde"], package = "chrono" }
Expand Down Expand Up @@ -83,7 +82,7 @@ cli = ["env_logger", "structopt", "git2", "v2", "codegen"]
codegen = ["heck", "http", "log", "regex", "tinytemplate", "paperclip-core/codegen"]
v2 = ["paperclip-macros/v2", "paperclip-core/v2"]
# OpenAPI v2 to v3 support
v3 = ["openapiv3", "indexmap", "v2", "paperclip-core/v3", "paperclip-actix/v3"]
v3 = ["openapiv3", "v2", "paperclip-core/v3", "paperclip-actix/v3"]


# Features for implementing traits for dependencies.
Expand Down
6 changes: 3 additions & 3 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "paperclip-core"
version = "0.6.1"
version = "0.7.0"
edition = "2018"
description = "Core types and traits for paperclip OpenAPI tooling library"
documentation = "https://paperclip-rs.github.io/paperclip/paperclip_core"
Expand Down Expand Up @@ -37,8 +37,8 @@ actix-web-validator2 = { version = "2.2", optional = true, package = "actix-web-
actix-web-validator3 = { version = "3.0", optional = true, package = "actix-web-validator" }
validator12 = { version = "0.12", features = ["derive"], optional = true, package = "validator" }
validator14 = { version = "0.14", features = ["derive"], optional = true, package = "validator" }
openapiv3 = { version = "1.0.2", optional = true }
indexmap = { version = "1.0", features = ["serde-1", "std"], optional = true }
openapiv3 = { version = "1.0.3", optional = true }
indexmap = { version = "2.0", features = ["serde"], optional = true }

[features]
# actix-web support
Expand Down
6 changes: 3 additions & 3 deletions plugins/actix-web/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "paperclip-actix"
version = "0.6.1"
version = "0.7.0"
edition = "2018"
description = "Paperclip OpenAPI plugin for actix-web framework"
documentation = "https://paperclip-rs.github.io/paperclip/paperclip_actix"
Expand All @@ -9,7 +9,7 @@ homepage = "https://github.com/paperclip-rs/paperclip"
repository = "https://github.com/paperclip-rs/paperclip"

[dependencies]
paperclip-core = { path = "../../core", version = "0.6.1", optional = true }
paperclip-core = { path = "../../core", version = "0.7.0", optional = true }
paperclip-macros = { path = "../../macros", version = "0.6.3", features = ["actix"] }
futures = "0.3"
actix-service1 = { version = "1", package = "actix-service", optional = true }
Expand All @@ -20,7 +20,7 @@ actix-web4 = { version = "4", default-features = false, optional = true, package
mime_guess = { version = "2.0.4", default-features = false }
serde_json = "1.0"
once_cell = "1.4"
openapiv3 = { version = "1.0.2", optional = true }
openapiv3 = { version = "1.0.3", optional = true }
include_dir = { version = "0.7.2", optional = true }
tinytemplate = { version = "1.1", optional = true }

Expand Down
2 changes: 1 addition & 1 deletion plugins/actix-web/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ where
F: Mountable,
{
let mut api = self.spec.write().unwrap();
api.definitions.extend(factory.definitions().into_iter());
api.definitions.extend(factory.definitions());
SecurityScheme::append_map(
factory.security_definitions(),
&mut api.security_definitions,
Expand Down
4 changes: 2 additions & 2 deletions plugins/actix-web/src/app3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::{
Mountable,
};
use actix_service1::ServiceFactory;
#[cfg(any(feature = "swagger-ui"))]
#[cfg(feature = "swagger-ui")]
use actix_web::web::HttpRequest;
use actix_web::{
dev::{HttpServiceFactory, MessageBody, ServiceRequest, ServiceResponse, Transform},
Expand Down Expand Up @@ -454,7 +454,7 @@ where
F: Mountable,
{
let mut api = self.spec.write().unwrap();
api.definitions.extend(factory.definitions().into_iter());
api.definitions.extend(factory.definitions());
SecurityScheme::append_map(
factory.security_definitions(),
&mut api.security_definitions,
Expand Down
6 changes: 2 additions & 4 deletions plugins/actix-web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ pub trait Mountable {
fn update_operations(&mut self, map: &mut BTreeMap<String, DefaultPathItemRaw>) {
let operations = self.operations();
if !operations.is_empty() {
let op_map = map
.entry(self.path().into())
.or_insert_with(Default::default);
op_map.methods.extend(operations.into_iter());
let op_map = map.entry(self.path().into()).or_default();
op_map.methods.extend(operations);
}
}
}
20 changes: 10 additions & 10 deletions plugins/actix-web/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ where
/// Wrapper for [`actix_web::Resource::route`](https://docs.rs/actix-web/*/actix_web/struct.Resource.html#method.route).
pub fn route(mut self, route: Route) -> Self {
let w = RouteWrapper::from(&self.path, route);
self.operations.extend(w.operations.into_iter());
self.definitions.extend(w.definitions.into_iter());
self.operations.extend(w.operations);
self.definitions.extend(w.definitions);
SecurityScheme::append_map(w.security, &mut self.security);
self.inner = self.inner.route(w.inner);
self
Expand Down Expand Up @@ -248,7 +248,7 @@ where
self.operations.insert(method.into(), op.clone());
}

self.definitions.extend(U::definitions().into_iter());
self.definitions.extend(U::definitions());
SecurityScheme::append_map(U::security_definitions(), &mut self.security);
}
}
Expand Down Expand Up @@ -444,7 +444,7 @@ where
where
M: Mountable,
{
self.definitions.extend(factory.definitions().into_iter());
self.definitions.extend(factory.definitions());
let mut path_map = BTreeMap::new();
factory.update_operations(&mut path_map);
for (path, mut map) in path_map {
Expand Down Expand Up @@ -488,8 +488,8 @@ impl<T> Mountable for Scope<T> {

fn update_operations(&mut self, map: &mut BTreeMap<String, DefaultPathItemRaw>) {
for (path, item) in mem::take(&mut self.path_map) {
let op_map = map.entry(path).or_insert_with(Default::default);
op_map.methods.extend(item.methods.into_iter());
let op_map = map.entry(path).or_default();
op_map.methods.extend(item.methods);
}
}
}
Expand Down Expand Up @@ -719,8 +719,8 @@ impl<'a> Mountable for ServiceConfig<'a> {

fn update_operations(&mut self, map: &mut BTreeMap<String, DefaultPathItemRaw>) {
for (path, item) in mem::take(&mut self.path_map) {
let op_map = map.entry(path).or_insert_with(Default::default);
op_map.methods.extend(item.methods.into_iter());
let op_map = map.entry(path).or_default();
op_map.methods.extend(item.methods);
}
}
}
Expand All @@ -729,7 +729,7 @@ impl<'a> ServiceConfig<'a> {
/// Wrapper for [`actix_web::web::ServiceConfig::route`](https://docs.rs/actix-web/*/actix_web/web/struct.ServiceConfig.html#method.route).
pub fn route(&mut self, path: &str, route: Route) -> &mut Self {
let mut w = RouteWrapper::from(path, route);
self.definitions.extend(w.definitions().into_iter());
self.definitions.extend(w.definitions());
w.update_operations(&mut self.path_map);
SecurityScheme::append_map(w.security, &mut self.security);
self.inner.route(path, w.inner);
Expand All @@ -741,7 +741,7 @@ impl<'a> ServiceConfig<'a> {
where
F: Mountable + HttpServiceFactory + 'static,
{
self.definitions.extend(factory.definitions().into_iter());
self.definitions.extend(factory.definitions());
factory.update_operations(&mut self.path_map);
SecurityScheme::append_map(factory.security_definitions(), &mut self.security);
self.inner.service(factory);
Expand Down
20 changes: 10 additions & 10 deletions plugins/actix-web/src/web3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ where
/// Wrapper for [`actix_web::Resource::route`](https://docs.rs/actix-web/*/actix_web/struct.Resource.html#method.route).
pub fn route(mut self, route: Route) -> Self {
let w = RouteWrapper::from(&self.path, route);
self.operations.extend(w.operations.into_iter());
self.definitions.extend(w.definitions.into_iter());
self.operations.extend(w.operations);
self.definitions.extend(w.definitions);
SecurityScheme::append_map(w.security, &mut self.security);
self.inner = self.inner.route(w.inner);
self
Expand Down Expand Up @@ -271,7 +271,7 @@ where
self.operations.insert(method.into(), op.clone());
}

self.definitions.extend(U::definitions().into_iter());
self.definitions.extend(U::definitions());
SecurityScheme::append_map(U::security_definitions(), &mut self.security);
}
}
Expand Down Expand Up @@ -479,7 +479,7 @@ where
where
M: Mountable,
{
self.definitions.extend(factory.definitions().into_iter());
self.definitions.extend(factory.definitions());
let mut path_map = BTreeMap::new();
factory.update_operations(&mut path_map);
for (path, mut map) in path_map {
Expand Down Expand Up @@ -523,8 +523,8 @@ impl<T> Mountable for Scope<T> {

fn update_operations(&mut self, map: &mut BTreeMap<String, DefaultPathItemRaw>) {
for (path, item) in mem::take(&mut self.path_map) {
let op_map = map.entry(path).or_insert_with(Default::default);
op_map.methods.extend(item.methods.into_iter());
let op_map = map.entry(path).or_default();
op_map.methods.extend(item.methods);
}
}
}
Expand Down Expand Up @@ -752,8 +752,8 @@ impl<'a> Mountable for ServiceConfig<'a> {

fn update_operations(&mut self, map: &mut BTreeMap<String, DefaultPathItemRaw>) {
for (path, item) in mem::take(&mut self.path_map) {
let op_map = map.entry(path).or_insert_with(Default::default);
op_map.methods.extend(item.methods.into_iter());
let op_map = map.entry(path).or_default();
op_map.methods.extend(item.methods);
}
}
}
Expand All @@ -762,7 +762,7 @@ impl<'a> ServiceConfig<'a> {
/// Wrapper for [`actix_web::web::ServiceConfig::route`](https://docs.rs/actix-web/*/actix_web/web/struct.ServiceConfig.html#method.route).
pub fn route(&mut self, path: &str, route: Route) -> &mut Self {
let mut w = RouteWrapper::from(path, route);
self.definitions.extend(w.definitions().into_iter());
self.definitions.extend(w.definitions());
w.update_operations(&mut self.path_map);
SecurityScheme::append_map(w.security, &mut self.security);
self.inner.route(path, w.inner);
Expand All @@ -774,7 +774,7 @@ impl<'a> ServiceConfig<'a> {
where
F: Mountable + HttpServiceFactory + 'static,
{
self.definitions.extend(factory.definitions().into_iter());
self.definitions.extend(factory.definitions());
factory.update_operations(&mut self.path_map);
SecurityScheme::append_map(factory.security_definitions(), &mut self.security);
self.inner.service(factory);
Expand Down
6 changes: 3 additions & 3 deletions src/v2/codegen/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ where
let mut mods = state.mod_children.borrow_mut();
for (i, path) in rel_path.ancestors().enumerate() {
if let (Some(parent), Some(name)) = (path.parent(), path.file_name()) {
let entry = mods.entry(parent.into()).or_insert_with(HashSet::new);
let entry = mods.entry(parent.into()).or_default();
entry.insert(ChildModule {
name: name.to_string_lossy().into_owned(),
is_final: i == 0,
Expand Down Expand Up @@ -973,7 +973,7 @@ where
let ops = obj[0] // first object is always the globally defined object.
.paths
.entry(self.path.into())
.or_insert_with(Default::default);
.or_default();

let mut response_contains_any = false;
let response_ty_path = if let Some(s) = Self::get_2xx_response_schema(op) {
Expand Down Expand Up @@ -1093,7 +1093,7 @@ where
let ops = obj[0] // first object is always the globally defined object.
.paths
.entry(self.path.into())
.or_insert_with(Default::default);
.or_default();

ops.req.insert(
meth,
Expand Down