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: updating ast #1

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4d23b80
updating ast
shashitnak Mar 29, 2024
5d52d99
Bump taiki-e/install-action from 2.29.7 to 2.32.0 (#39)
dependabot[bot] Apr 1, 2024
b7cb2b4
Bump taiki-e/install-action from 2.32.0 to 2.32.9 (#40)
dependabot[bot] Apr 8, 2024
2215e33
Bump taiki-e/install-action from 2.32.9 to 2.32.17 (#41)
dependabot[bot] Apr 15, 2024
c136969
Bump taiki-e/install-action from 2.32.17 to 2.33.3 (#42)
dependabot[bot] Apr 22, 2024
29eefc0
Bump dependabot/fetch-metadata from 2.0.0 to 2.1.0 (#45)
dependabot[bot] Apr 29, 2024
191a8d1
Bump taiki-e/install-action from 2.33.3 to 2.33.9 (#46)
dependabot[bot] Apr 29, 2024
d1f6936
Bump taiki-e/install-action from 2.33.9 to 2.33.16 (#47)
dependabot[bot] May 6, 2024
704143e
Bump taiki-e/install-action from 2.33.16 to 2.33.22 (#48)
dependabot[bot] May 13, 2024
ac8390e
ci: update nightly for public-api-diff
robjtede May 18, 2024
2b045cb
build: add msrv (#49)
robjtede May 18, 2024
a261b99
chore: prepare release 0.5.0
robjtede May 18, 2024
87bbba3
Bump taiki-e/install-action from 2.33.22 to 2.33.26 (#50)
dependabot[bot] May 20, 2024
f80ac07
Bump taiki-e/install-action from 2.33.26 to 2.33.34 (#51)
dependabot[bot] May 27, 2024
4782a5b
Bump taiki-e/install-action from 2.33.34 to 2.34.0 (#53)
dependabot[bot] Jun 3, 2024
17294b6
Bump actions-rust-lang/setup-rust-toolchain from 1.8.0 to 1.9.0 (#54)
dependabot[bot] Jun 10, 2024
26bebbd
Bump taiki-e/install-action from 2.34.0 to 2.38.0 (#55)
dependabot[bot] Jun 10, 2024
2d858d5
Merge branch 'main' into spotify
shashitnak Jun 14, 2024
3329122
updating ast
shashitnak Mar 29, 2024
a4e5612
Merge branch 'spotify' of github.com:tailcallhq/oas3-rs into spotify
shashitnak Jun 14, 2024
b52259d
lint fix
shashitnak Jun 14, 2024
f5446a6
fixing warnings
shashitnak Jun 14, 2024
1b70160
fixing test warnings
shashitnak Jun 14, 2024
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
16 changes: 11 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: CI

on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened]
merge_group:
types: [checks_requested]
pull_request:
push:
branches: [main]

permissions:
Expand All @@ -16,21 +16,27 @@ concurrency:
cancel-in-progress: true

jobs:
read_msrv:
name: Read MSRV
uses: actions-rust-lang/msrv/.github/workflows/msrv.yml@main

test:
needs: read_msrv

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
toolchain:
- { name: msrv, version: "1.68" }
- { name: msrv, version: "${{ needs.read_msrv.outputs.msrv }}" }
- { name: stable, version: stable }

name: Test / ${{ matrix.toolchain.name }}
steps:
- uses: actions/checkout@v4

- name: Install Rust (${{ matrix.toolchain.name }})
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
uses: actions-rust-lang/setup-rust-toolchain@v1.9.0
with:
toolchain: ${{ matrix.toolchain.version }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependabot-reviewer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- name: Fetch Dependabot metadata
id: dependabot-metadata
uses: dependabot/fetch-metadata@v2.0.0
uses: dependabot/fetch-metadata@v2.1.0

- name: Enable auto-merge for Dependabot PRs
run: gh pr merge --auto --squash "$PR_URL"
Expand Down
23 changes: 10 additions & 13 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,25 @@ jobs:
- uses: actions/checkout@v4

- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
uses: actions-rust-lang/setup-rust-toolchain@v1.9.0
with:
components: clippy

- name: Install cargo-hack
uses: taiki-e/install-action@v2.29.7
- name: Install just, cargo-hack
uses: taiki-e/install-action@v2.38.0
with:
tool: cargo-hack
tool: just,cargo-hack

- name: Check with Clippy
run: |
cargo clippy --workspace --no-default-features
cargo clippy --workspace --no-default-features --all-features
cargo hack --feature-powerset --depth=3 clippy --workspace
run: just clippy

rustfmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust (nightly)
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
uses: actions-rust-lang/setup-rust-toolchain@v1.9.0
with:
toolchain: nightly
components: rustfmt
Expand All @@ -58,7 +55,7 @@ jobs:
- uses: actions/checkout@v4

- name: Install Rust (nightly)
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
uses: actions-rust-lang/setup-rust-toolchain@v1.9.0
with:
toolchain: nightly
components: rust-docs
Expand All @@ -80,12 +77,12 @@ jobs:
uses: actions/checkout@v4

- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
uses: actions-rust-lang/setup-rust-toolchain@v1.9.0
with:
toolchain: nightly-2023-08-25
toolchain: nightly-2024-04-26

- name: Install cargo-public-api
uses: taiki-e/install-action@v2.29.7
uses: taiki-e/install-action@v2.38.0
with:
tool: cargo-public-api

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

## 0.5.0

- Update `http` dependency to `1`.

## 0.4.0

- The `bearer_format` field of `SecurityScheme::Http` is now optional.
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "oas3"
description = "Structures and tools to parse, navigate and validate OpenAPI v3 specifications."
version = "0.4.0"
version = "0.5.0"
authors = [
"softprops <[email protected]>",
"Rob Ede <[email protected]>",
Expand All @@ -11,6 +11,7 @@ categories = ["data-structures", "development-tools::testing", "parsing"]
repository = "https://github.com/x52dev/oas3-rs"
license = "MIT"
edition = "2021"
rust-version = "1.65"

[features]
default = ["validation"]
Expand All @@ -21,7 +22,7 @@ conformance = ["validation", "reqwest", "prettytable-rs", "colored"]
bytes = "1.5"
derive_more = "0.99"
futures-util = "0.3"
http = "0.2"
http = "1"
log = "0.4"
once_cell = "1"
regex = "1"
Expand Down
37 changes: 37 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
_list:
@just --list

msrv := ```
cargo metadata --format-version=1 \
| jq -r 'first(.packages[] | select(.source == null and .rust_version)) | .rust_version' \
| sed -E 's/^1\.([0-9]{2})$/1\.\1\.0/'
```
msrv_rustup := "+" + msrv

# Format project.
fmt:
just --unstable --fmt
fd --hidden --extension=toml --exec-batch taplo format
fd --hidden --type=file --extension=md --extension=yml --exec-batch prettier --write
cargo +nightly fmt

# Lint workspace with Clippy.
clippy:
cargo clippy --workspace --no-default-features
cargo clippy --workspace --no-default-features --all-features
cargo hack --feature-powerset clippy --workspace

# Downgrade dev-dependencies necessary to run MSRV checks/tests.
[private]
downgrade-msrv:
@ echo "No downgrades currently necessary"

# Test workspace using MSRV
test-msrv: downgrade-msrv (test msrv_rustup)

# Test workspace.
test toolchain="":
cargo {{ toolchain }} nextest run --workspace --no-default-features
cargo {{ toolchain }} nextest run --workspace --all-features
cargo {{ toolchain }} test --doc --workspace --all-features
RUSTDOCFLAGS="-D warnings" cargo {{ toolchain }} doc --workspace --no-deps --all-features
31 changes: 31 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#![deny(rust_2018_idioms, nonstandard_style)]
#![warn(missing_debug_implementations)]

use serde::de::{Deserializer, MapAccess, Visitor};
use std::fmt;
use std::{fs::File, io::Read, path::Path};

mod error;
Expand Down Expand Up @@ -61,6 +63,35 @@ pub fn to_json(spec: &OpenApiV3Spec) -> Result<String, Error> {
Ok(serde_json::to_string_pretty(spec)?)
}

pub fn deserialize_extensions<'de, D>(deserializer: D) -> Result<serde_yaml::Value, D::Error>
where
D: Deserializer<'de>,
{
struct ExtraFieldsVisitor;

impl<'de> Visitor<'de> for ExtraFieldsVisitor {
type Value = serde_yaml::Value;

fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("extensions")
}

fn visit_map<M>(self, mut access: M) -> Result<Self::Value, M::Error>
where
M: MapAccess<'de>,
{
let mut map = serde_yaml::Mapping::new();
while let Some((key, value)) = access.next_entry()? {
map.insert(key, value);
}

Ok(map.into())
}
}

deserializer.deserialize_map(ExtraFieldsVisitor)
}

#[cfg(test)]
mod tests {
use std::{
Expand Down
6 changes: 5 additions & 1 deletion src/spec/components.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::BTreeMap;

use crate::deserialize_extensions;
use serde::{Deserialize, Serialize};

use super::{
Expand Down Expand Up @@ -64,5 +65,8 @@ pub struct Components {
#[serde(default)]
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
pub callbacks: BTreeMap<String, ObjectOrReference<Callback>>,
// TODO: Add "Specification Extensions" https://github.com/OAI/OpenAPI-Specification/blob/HEAD/versions/3.1.0.md#specificationExtensions}

#[serde(default)]
#[serde(deserialize_with = "deserialize_extensions")]
pub extensions: serde_yaml::Value,
}
8 changes: 8 additions & 0 deletions src/spec/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,21 @@ pub struct Parameter {
/// `header` - `simple`; for cookie - `form`.
#[serde(skip_serializing_if = "Option::is_none")]
style: Option<ParameterStyle>,

#[serde(skip_serializing_if = "Option::is_none")]
explode: Option<bool>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "in")]
param_in: Option<String>,
}

#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "camelCase")]
enum ParameterStyle {
Form,
Simple,
DeepObject,
}

impl FromRef for Parameter {
Expand Down
10 changes: 8 additions & 2 deletions src/spec/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ pub enum Type {
Array,
Object,
}
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
#[serde(untagged)]
pub enum ObjectOrFalse<T> {
False(bool),
Object(T),
}

// FIXME: Verify against OpenAPI 3.0
/// The Schema Object allows the definition of input and output data types.
Expand Down Expand Up @@ -84,7 +90,7 @@ pub struct Schema {
/// See <https://github.com/OAI/OpenAPI-Specification/blob/HEAD/versions/3.1.0.md#properties>.
#[serde(rename = "additionalProperties")]
#[serde(skip_serializing_if = "Option::is_none")]
pub additional_properties: Option<Box<ObjectOrReference<Schema>>>,
pub additional_properties: Option<Box<ObjectOrFalse<ObjectOrReference<Schema>>>>,

//
// additional metadata
Expand All @@ -104,7 +110,7 @@ pub struct Schema {
#[serde(default)]
#[serde(rename = "enum")]
#[serde(skip_serializing_if = "Vec::is_empty")]
pub enum_values: Vec<String>,
pub enum_values: Vec<serde_yaml::Value>,

#[serde(skip_serializing_if = "Option::is_none")]
pub pattern: Option<String>,
Expand Down
2 changes: 1 addition & 1 deletion src/spec/security_scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod tests {
#[test]
fn test_http_basic_deser() {
const HTTP_BASIC_SAMPLE: &str = r#"{"type": "http", "scheme": "basic"}"#;
let obj: SecurityScheme = serde_json::from_str(&HTTP_BASIC_SAMPLE).unwrap();
let obj: SecurityScheme = serde_json::from_str(HTTP_BASIC_SAMPLE).unwrap();

assert!(matches!(
obj,
Expand Down