diff --git a/Cargo.lock b/Cargo.lock index 6defcc6..79c6edf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -356,7 +356,7 @@ version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", "syn", @@ -622,7 +622,7 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "796be76b11b79de0decd7be2105add01220f8bbe04cf1f83214c0b801414a722" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", "serde", @@ -935,6 +935,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "heck" version = "0.5.0" @@ -1368,6 +1374,7 @@ dependencies = [ "libmdns", "moonraker", "multer", + "openapi-lint", "openapiv3", "opentelemetry", "opentelemetry-otlp", @@ -1667,6 +1674,18 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +[[package]] +name = "openapi-lint" +version = "0.4.0" +source = "git+https://github.com/oxidecomputer/openapi-lint?branch=main#ef442ee4343e97b6d9c217d3e7533962fe7d7236" +dependencies = [ + "heck 0.4.1", + "indexmap 2.6.0", + "lazy_static", + "openapiv3", + "regex", +] + [[package]] name = "openapiv3" version = "2.0.0" diff --git a/Cargo.toml b/Cargo.toml index 4e28324..c58ce5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,6 +64,7 @@ uuid = "1.11.0" [dev-dependencies] async-trait = "0.1" expectorate = "1" +openapi-lint = { git = "https://github.com/oxidecomputer/openapi-lint", branch = "main" } openapiv3 = "2" portpicker = "0.1.1" pretty_assertions = "1" diff --git a/openapi/api.json b/openapi/api.json index d4b4479..d5a9238 100644 --- a/openapi/api.json +++ b/openapi/api.json @@ -36,60 +36,62 @@ "description": "Extra machine-specific information regarding a connected machine.", "oneOf": [ { - "additionalProperties": false, "properties": { - "Moonraker": { - "type": "object" + "type": { + "enum": [ + "moonraker" + ], + "type": "string" } }, "required": [ - "Moonraker" + "type" ], "type": "object" }, { - "additionalProperties": false, "properties": { - "Usb": { - "type": "object" + "type": { + "enum": [ + "usb" + ], + "type": "string" } }, "required": [ - "Usb" + "type" ], "type": "object" }, { - "additionalProperties": false, "properties": { - "Bambu": { - "properties": { - "current_stage": { - "allOf": [ - { - "$ref": "#/components/schemas/Stage" - } - ], - "description": "The current stage of the machine as defined by Bambu which can include errors, etc.", - "nullable": true - }, - "nozzle_diameter": { - "allOf": [ - { - "$ref": "#/components/schemas/NozzleDiameter" - } - ], - "description": "The nozzle diameter of the machine." + "current_stage": { + "allOf": [ + { + "$ref": "#/components/schemas/Stage" + } + ], + "description": "The current stage of the machine as defined by Bambu which can include errors, etc.", + "nullable": true + }, + "nozzle_diameter": { + "allOf": [ + { + "$ref": "#/components/schemas/NozzleDiameter" } - }, - "required": [ - "nozzle_diameter" ], - "type": "object" + "description": "The nozzle diameter of the machine." + }, + "type": { + "enum": [ + "bambu" + ], + "type": "string" } }, "required": [ - "Bambu" + "nozzle_diameter", + "type" ], "type": "object" } diff --git a/src/server/endpoints.rs b/src/server/endpoints.rs index 1792c4d..31ed950 100644 --- a/src/server/endpoints.rs +++ b/src/server/endpoints.rs @@ -43,6 +43,7 @@ pub async fn ping(_rqctx: RequestContext>) -> Result TestResult { assert!(!spec.paths.paths.is_empty()); assert!(spec.paths.paths.get("/ping").is_some()); + // Check for lint errors. + let errors = openapi_lint::validate(&spec); + assert!(errors.is_empty(), "{}", errors.join("\n\n")); + // Construct a string that helps us identify the organization of tags and // operations. let mut ops_by_tag = BTreeMap::>::new();