Skip to content

Commit

Permalink
Various fixes to get ready for 2.0 (#82)
Browse files Browse the repository at this point in the history
- update indexmap dep to 2.0.0
- reorder Components to match spec
- coalesce serde pragmas
- add callbacks to Operation
- fix deserialization of subschemas with typed schemas
- fix some clippy nits
  • Loading branch information
ahl authored Oct 21, 2023
1 parent dfe02f7 commit b500ca1
Show file tree
Hide file tree
Showing 12 changed files with 752 additions and 95 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog

## 2.0.0-rc.0 (2023-10-21)

- Bump `indexmap` dependency to 2.0.0
- Add `enum` field to boolean schema
- Add `callbacks` to `Operation` type (out of conformance with spec)
- Fix handling of subschemas with typed Schema objects
- Fixes to SecuritySchema handling
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[package]
name = "openapiv3"
version = "1.0.3"
version = "2.0.0-rc.0"
authors = ["Glade Miller <[email protected]>"]
edition = "2018"
edition = "2021"
license = "MIT/Apache-2.0"
keywords = ["openapi", "v3"]
homepage = "https://github.com/glademiller/openapiv3"
repository = "https://github.com/glademiller/openapiv3"
description = "This crate provides data structures that represent the OpenAPI v3.0.x specification easily deserializable with serde."

[dependencies]
serde = {version = "1.0", features = ["derive"]}
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
indexmap = {version = ">=1.6.1, <3.0.0", features = ["serde"]}
indexmap = { version = "2.0.0", features = ["serde"] }

[dev-dependencies]
newline-converter = "0.3.0"
Expand Down
8 changes: 4 additions & 4 deletions src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Components {
/// An object to hold reusable Security Scheme Objects.
/// An object to hold reusable Schema Objects.
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub security_schemes: IndexMap<String, ReferenceOr<SecurityScheme>>,
pub schemas: IndexMap<String, ReferenceOr<Schema>>,
/// An object to hold reusable Response Objects.
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub responses: IndexMap<String, ReferenceOr<Response>>,
Expand All @@ -27,9 +27,9 @@ pub struct Components {
/// An object to hold reusable Header Objects.
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub headers: IndexMap<String, ReferenceOr<Header>>,
/// An object to hold reusable Schema Objects.
/// An object to hold reusable Security Scheme Objects.
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub schemas: IndexMap<String, ReferenceOr<Schema>>,
pub security_schemes: IndexMap<String, ReferenceOr<SecurityScheme>>,
/// An object to hold reusable Link Objects.
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub links: IndexMap<String, ReferenceOr<Link>>,
Expand Down
3 changes: 1 addition & 2 deletions src/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ pub struct Example {
/// This provides the capability to reference examples that cannot
/// easily be included in JSON or YAML documents. The `value` field and
/// `externalValue` field are mutually exclusive.
#[serde(rename = "externalValue")]
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "externalValue", skip_serializing_if = "Option::is_none")]
pub external_value: Option<String>,
/// Inline extensions to this object.
#[serde(flatten, deserialize_with = "crate::util::deserialize_extensions")]
Expand Down
12 changes: 4 additions & 8 deletions src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ pub struct OpenAPI {
/// An array of Server Objects, which provide connectivity information to a
/// target server. If the servers property is not provided, or is an empty
/// array, the default value would be a Server Object with a url value of /.
#[serde(default)]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub servers: Vec<Server>,
/// REQUIRED. The available paths and operations for the API.
pub paths: Paths,
Expand All @@ -30,21 +29,18 @@ pub struct OpenAPI {
/// be satisfied to authorize a request. Individual operations can override
/// this definition. Global security settings may be overridden on a per-path
/// basis.
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub security: Option<Vec<SecurityRequirement>>,
/// A list of tags used by the specification with additional metadata.
/// The order of the tags can be used to reflect on their order by the
/// parsing tools. Not all tags that are used by the Operation Object
/// must be declared. The tags that are not declared MAY be organized
/// randomly or based on the tool's logic. Each tag name in the list
/// MUST be unique.
#[serde(default)]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub tags: Vec<Tag>,
/// Additional external documentation.
#[serde(rename = "externalDocs")]
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "externalDocs", skip_serializing_if = "Option::is_none")]
pub external_docs: Option<ExternalDocumentation>,
/// Inline extensions to this object.
#[serde(flatten, deserialize_with = "crate::util::deserialize_extensions")]
Expand Down
18 changes: 10 additions & 8 deletions src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ pub struct Operation {
/// A list of tags for API documentation control.
/// Tags can be used for logical grouping of operations
/// by resources or any other qualifier.
#[serde(default)]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub tags: Vec<String>,
/// A short summary of what the operation does.
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -36,8 +35,7 @@ pub struct Operation {
/// parameter is defined by a combination of a name and location.
/// The list can use the Reference Object to link to parameters
/// that are defined at the OpenAPI Object's components/parameters.
#[serde(default)]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub parameters: Vec<ReferenceOr<Parameter>>,
/// The request body applicable for this operation.
/// The requestBody is only supported in HTTP methods
Expand All @@ -49,6 +47,12 @@ pub struct Operation {
/// REQUIRED. The list of possible responses as they are returned
/// from executing this operation.
pub responses: Responses,
/// A map of possible out-of band callbacks related to the parent
/// operation. The key is a unique identifier for the Callback Object. Each
/// value in the map is a Callback Object that describes a request that may
/// be initiated by the API provider and the expected responses.
#[serde(default, skip_serializing_if = "IndexMap::is_empty")]
pub callbacks: IndexMap<String, Callback>,
/// Declares this operation to be deprecated.Default value is false.
#[serde(default, skip_serializing_if = "is_false")]
pub deprecated: bool,
Expand All @@ -57,14 +61,12 @@ pub struct Operation {
/// be used. Only one of the security requirement objects need to be satisfied to
/// authorize a request. This definition overrides any declared top-level security.
/// To remove a top-level security declaration, an empty array can be used.
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub security: Option<Vec<SecurityRequirement>>,
/// An alternative server array to service this operation.
/// If an alternative server object is specified at the
/// Path Item Object or Root level, it will be overridden by this value.
#[serde(default)]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub servers: Vec<Server>,
/// Inline extensions to this object.
#[serde(flatten, deserialize_with = "crate::util::deserialize_extensions")]
Expand Down
3 changes: 1 addition & 2 deletions src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ pub struct PathItem {
/// A unique parameter is defined by a combination of a name and location.
/// The list can use the Reference Object to link to parameters that
/// are defined at the OpenAPI Object's components/parameters.
#[serde(default)]
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub parameters: Vec<ReferenceOr<Parameter>>,
/// Inline extensions to this object.
#[serde(flatten, deserialize_with = "crate::util::deserialize_extensions")]
Expand Down
Loading

0 comments on commit b500ca1

Please sign in to comment.