From f255025b7f9ddfa87994ee07e051d48cbd5585bd Mon Sep 17 00:00:00 2001 From: Raimundo Henriques Date: Thu, 6 Jun 2024 12:36:05 +0100 Subject: [PATCH 1/3] feat: assert whether generated and versioned schema are identical --- .github/workflows/ci.yml | 9 ++++++--- schema/data-model-schema.json | 2 +- src/main.rs | 6 +++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 00f0efb..553e50b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,12 +14,15 @@ jobs: cargo test cargo clippy -- -Dwarnings - generate_schema: + validate_schema: runs-on: ubuntu-latest needs: build_and_test - if: github.ref == 'refs/heads/main' + # if: github.ref == 'refs/heads/main' steps: - uses: actions/checkout@v3 - - name: Generate schema + - name: Test schema run: | + cp schema/data-model-schema.json schema/data-model-schema.json.orig cargo run + # assert the generated and versioned file equal + diff -u schema/data-model-schema.json schema/data-model-schema.json.orig diff --git a/schema/data-model-schema.json b/schema/data-model-schema.json index 2920b90..7cd1e96 100644 --- a/schema/data-model-schema.json +++ b/schema/data-model-schema.json @@ -801,4 +801,4 @@ "pattern": "^\\d+\\.\\d+\\.\\d+(-\\d{8})?$" } } -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index 5c42108..d5b6e56 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,11 @@ use std::io::{Error, Write}; fn main() -> Result<(), Error> { let schema = schema_for!(ProductFootprint); - let schema_json = to_string_pretty(&schema).expect("Failed to serialize schema"); + let mut schema_json = to_string_pretty(&schema).expect("Failed to serialize schema"); + + if !schema_json.ends_with('\n') { + schema_json.push('\n'); + } let mut file = File::create("./schema/data-model-schema.json")?; From 4f29b5365a1e4610538c38edb6a61578acb5ce6f Mon Sep 17 00:00:00 2001 From: Raimundo Henriques Date: Thu, 6 Jun 2024 16:30:25 +0100 Subject: [PATCH 2/3] feat: use openAPI schema settings and skip Global --- schema/data-model-schema.json | 351 ++++++++++++++-------------------- src/lib.rs | 2 + src/main.rs | 8 +- 3 files changed, 152 insertions(+), 209 deletions(-) diff --git a/schema/data-model-schema.json b/schema/data-model-schema.json index 7cd1e96..aad8dec 100644 --- a/schema/data-model-schema.json +++ b/schema/data-model-schema.json @@ -1,5 +1,5 @@ { - "$schema": "http://json-schema.org/draft-07/schema#", + "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", "title": "ProductFootprint", "description": "Data Type \"ProductFootprint\" of Tech Spec Version 2", "type": "object", @@ -23,87 +23,75 @@ "type": "string" }, "companyIds": { - "$ref": "#/definitions/CompanyIdSet" + "$ref": "#/components/schemas/CompanyIdSet" }, "companyName": { - "$ref": "#/definitions/NonEmptyString" + "$ref": "#/components/schemas/NonEmptyString" }, "created": { "type": "string", "format": "date-time" }, "extensions": { - "type": [ - "array", - "null" - ], + "type": "array", "items": { - "$ref": "#/definitions/DataModelExtension" - } + "$ref": "#/components/schemas/DataModelExtension" + }, + "nullable": true }, "id": { - "$ref": "#/definitions/PfId" + "$ref": "#/components/schemas/PfId" }, "pcf": { - "$ref": "#/definitions/CarbonFootprint" + "$ref": "#/components/schemas/CarbonFootprint" }, "precedingPfIds": { - "anyOf": [ + "allOf": [ { - "$ref": "#/definitions/NonEmptyPfIdVec" - }, - { - "type": "null" + "$ref": "#/components/schemas/NonEmptyPfIdVec" } - ] + ], + "nullable": true }, "productCategoryCpc": { - "$ref": "#/definitions/NonEmptyString" + "$ref": "#/components/schemas/NonEmptyString" }, "productDescription": { "type": "string" }, "productIds": { - "$ref": "#/definitions/ProductIdSet" + "$ref": "#/components/schemas/ProductIdSet" }, "productNameCompany": { - "$ref": "#/definitions/NonEmptyString" + "$ref": "#/components/schemas/NonEmptyString" }, "specVersion": { - "$ref": "#/definitions/VersionString" + "$ref": "#/components/schemas/VersionString" }, "status": { - "$ref": "#/definitions/PfStatus" + "$ref": "#/components/schemas/PfStatus" }, "statusComment": { - "type": [ - "string", - "null" - ] + "type": "string", + "nullable": true }, "updated": { - "type": [ - "string", - "null" - ], - "format": "date-time" + "type": "string", + "format": "date-time", + "nullable": true }, "validityPeriodEnd": { - "type": [ - "string", - "null" - ], - "format": "date-time" + "type": "string", + "format": "date-time", + "nullable": true }, "validityPeriodStart": { - "type": [ - "string", - "null" - ], - "format": "date-time" + "type": "string", + "format": "date-time", + "nullable": true }, "version": { - "$ref": "#/definitions/VersionInteger" + "$ref": "#/components/schemas/VersionInteger" } }, "definitions": { @@ -119,56 +107,44 @@ "type": "boolean" }, "boundary": { - "anyOf": [ - { - "$ref": "#/definitions/AssuranceBoundary" - }, + "allOf": [ { - "type": "null" + "$ref": "#/components/schemas/AssuranceBoundary" } - ] + ], + "nullable": true }, "comments": { - "type": [ - "string", - "null" - ] + "type": "string", + "nullable": true }, "completedAt": { - "type": [ - "string", - "null" - ], - "format": "date-time" + "type": "string", + "format": "date-time", + "nullable": true }, "coverage": { - "anyOf": [ - { - "$ref": "#/definitions/AssuranceCoverage" - }, + "allOf": [ { - "type": "null" + "$ref": "#/components/schemas/AssuranceCoverage" } - ] + ], + "nullable": true }, "level": { - "anyOf": [ - { - "$ref": "#/definitions/AssuranceLevel" - }, + "allOf": [ { - "type": "null" + "$ref": "#/components/schemas/AssuranceLevel" } - ] + ], + "nullable": true }, "providerName": { "type": "string" }, "standardName": { - "type": [ - "string", - "null" - ] + "type": "string", + "nullable": true } } }, @@ -208,9 +184,6 @@ "description": "Data Type \"CarbonFootprint\" of Spec Version 2", "type": "object", "anyOf": [ - { - "type": "null" - }, { "type": "object", "required": [ @@ -218,7 +191,7 @@ ], "properties": { "geographyRegionOrSubregion": { - "$ref": "#/definitions/UNRegionOrSubregion" + "$ref": "#/components/schemas/UNRegionOrSubregion" } } }, @@ -229,7 +202,7 @@ ], "properties": { "geographyCountry": { - "$ref": "#/definitions/ISO3166CC" + "$ref": "#/components/schemas/ISO3166CC" } } }, @@ -240,7 +213,7 @@ ], "properties": { "geographyCountrySubdivision": { - "$ref": "#/definitions/NonEmptyString" + "$ref": "#/components/schemas/NonEmptyString" } } } @@ -265,169 +238,143 @@ ], "properties": { "aircraftGhgEmissions": { - "anyOf": [ + "allOf": [ { - "$ref": "#/definitions/PositiveDecimal" - }, - { - "type": "null" + "$ref": "#/components/schemas/PositiveDecimal" } - ] + ], + "nullable": true }, "allocationRulesDescription": { - "type": [ - "string", - "null" - ] + "type": "string", + "nullable": true }, "assurance": { - "anyOf": [ - { - "$ref": "#/definitions/Assurance" - }, + "allOf": [ { - "type": "null" + "$ref": "#/components/schemas/Assurance" } - ] + ], + "nullable": true }, "biogenicAccountingMethodology": { - "anyOf": [ - { - "$ref": "#/definitions/BiogenicAccountingMethodology" - }, + "allOf": [ { - "type": "null" + "$ref": "#/components/schemas/BiogenicAccountingMethodology" } - ] + ], + "nullable": true }, "biogenicCarbonContent": { - "$ref": "#/definitions/PositiveDecimal" + "$ref": "#/components/schemas/PositiveDecimal" }, "biogenicCarbonWithdrawal": { - "anyOf": [ - { - "$ref": "#/definitions/NegativeDecimal" - }, + "allOf": [ { - "type": "null" + "$ref": "#/components/schemas/NegativeDecimal" } - ] + ], + "nullable": true }, "boundaryProcessesDescription": { "type": "string" }, "characterizationFactors": { - "$ref": "#/definitions/CharacterizationFactors" + "$ref": "#/components/schemas/CharacterizationFactors" }, "crossSectoralStandardsUsed": { - "$ref": "#/definitions/CrossSectoralStandardSet" + "$ref": "#/components/schemas/CrossSectoralStandardSet" }, "dLucGhgEmissions": { - "anyOf": [ - { - "$ref": "#/definitions/PositiveDecimal" - }, + "allOf": [ { - "type": "null" + "$ref": "#/components/schemas/PositiveDecimal" } - ] + ], + "nullable": true }, "declaredUnit": { - "$ref": "#/definitions/DeclaredUnit" + "$ref": "#/components/schemas/DeclaredUnit" }, "dqi": { - "anyOf": [ - { - "$ref": "#/definitions/DataQualityIndicators" - }, + "allOf": [ { - "type": "null" + "$ref": "#/components/schemas/DataQualityIndicators" } - ] + ], + "nullable": true }, "exemptedEmissionsDescription": { "type": "string" }, "exemptedEmissionsPercent": { - "$ref": "#/definitions/ExemptedEmissionsPercent" + "$ref": "#/components/schemas/ExemptedEmissionsPercent" }, "fossilCarbonContent": { - "$ref": "#/definitions/PositiveDecimal" + "$ref": "#/components/schemas/PositiveDecimal" }, "fossilGhgEmissions": { - "$ref": "#/definitions/PositiveDecimal" + "$ref": "#/components/schemas/PositiveDecimal" }, "iLucGhgEmissions": { - "anyOf": [ - { - "$ref": "#/definitions/PositiveDecimal" - }, + "allOf": [ { - "type": "null" + "$ref": "#/components/schemas/PositiveDecimal" } - ] + ], + "nullable": true }, "ipccCharacterizationFactorsSources": { - "$ref": "#/definitions/IpccCharacterizationFactorsSources" + "$ref": "#/components/schemas/IpccCharacterizationFactorsSources" }, "landManagementGhgEmissions": { - "anyOf": [ - { - "$ref": "#/definitions/PositiveDecimal" - }, + "allOf": [ { - "type": "null" + "$ref": "#/components/schemas/PositiveDecimal" } - ] + ], + "nullable": true }, "otherBiogenicGhgEmissions": { - "anyOf": [ - { - "$ref": "#/definitions/PositiveDecimal" - }, + "allOf": [ { - "type": "null" + "$ref": "#/components/schemas/PositiveDecimal" } - ] + ], + "nullable": true }, "pCfExcludingBiogenic": { - "$ref": "#/definitions/PositiveDecimal" + "$ref": "#/components/schemas/PositiveDecimal" }, "pCfIncludingBiogenic": { - "anyOf": [ - { - "$ref": "#/definitions/Decimal" - }, + "allOf": [ { - "type": "null" + "$ref": "#/components/schemas/Decimal" } - ] + ], + "nullable": true }, "packagingEmissionsIncluded": { "type": "boolean" }, "packagingGhgEmissions": { - "anyOf": [ - { - "$ref": "#/definitions/PositiveDecimal" - }, + "allOf": [ { - "type": "null" + "$ref": "#/components/schemas/PositiveDecimal" } - ] + ], + "nullable": true }, "primaryDataShare": { - "anyOf": [ - { - "$ref": "#/definitions/Percent" - }, + "allOf": [ { - "type": "null" + "$ref": "#/components/schemas/Percent" } - ] + ], + "nullable": true }, "productOrSectorSpecificRules": { - "$ref": "#/definitions/ProductOrSectorSpecificRuleSet" + "$ref": "#/components/schemas/ProductOrSectorSpecificRuleSet" }, "referencePeriodEnd": { "type": "string", @@ -438,23 +385,19 @@ "format": "date-time" }, "secondaryEmissionFactorSources": { - "anyOf": [ - { - "$ref": "#/definitions/EmissionFactorDSSet" - }, + "allOf": [ { - "type": "null" + "$ref": "#/components/schemas/EmissionFactorDSSet" } - ] + ], + "nullable": true }, "uncertaintyAssessmentDescription": { - "type": [ - "string", - "null" - ] + "type": "string", + "nullable": true }, "unitaryProductAmount": { - "$ref": "#/definitions/StrictlyPositiveDecimal" + "$ref": "#/components/schemas/StrictlyPositiveDecimal" } } }, @@ -513,13 +456,11 @@ "type": "string" }, "documentation": { - "type": [ - "string", - "null" - ] + "type": "string", + "nullable": true }, "specVersion": { - "$ref": "#/definitions/VersionString" + "$ref": "#/components/schemas/VersionString" } } }, @@ -536,22 +477,22 @@ ], "properties": { "completenessDQR": { - "$ref": "#/definitions/FloatBetween1And3" + "$ref": "#/components/schemas/FloatBetween1And3" }, "coveragePercent": { - "$ref": "#/definitions/Percent" + "$ref": "#/components/schemas/Percent" }, "geographicalDQR": { - "$ref": "#/definitions/FloatBetween1And3" + "$ref": "#/components/schemas/FloatBetween1And3" }, "reliabilityDQR": { - "$ref": "#/definitions/FloatBetween1And3" + "$ref": "#/components/schemas/FloatBetween1And3" }, "technologicalDQR": { - "$ref": "#/definitions/FloatBetween1And3" + "$ref": "#/components/schemas/FloatBetween1And3" }, "temporalDQR": { - "$ref": "#/definitions/FloatBetween1And3" + "$ref": "#/components/schemas/FloatBetween1And3" } } }, @@ -580,10 +521,10 @@ ], "properties": { "name": { - "$ref": "#/definitions/NonEmptyString" + "$ref": "#/components/schemas/NonEmptyString" }, "version": { - "$ref": "#/definitions/NonEmptyString" + "$ref": "#/components/schemas/NonEmptyString" } } }, @@ -597,10 +538,10 @@ ], "properties": { "name": { - "$ref": "#/definitions/NonEmptyString" + "$ref": "#/components/schemas/NonEmptyString" }, "version": { - "$ref": "#/definitions/NonEmptyString" + "$ref": "#/components/schemas/NonEmptyString" } } }, @@ -703,20 +644,18 @@ ], "properties": { "operator": { - "$ref": "#/definitions/ProductOrSectorSpecificRuleOperator" + "$ref": "#/components/schemas/ProductOrSectorSpecificRuleOperator" }, "otherOperatorName": { - "anyOf": [ - { - "$ref": "#/definitions/NonEmptyString" - }, + "allOf": [ { - "type": "null" + "$ref": "#/components/schemas/NonEmptyString" } - ] + ], + "nullable": true }, "ruleNames": { - "$ref": "#/definitions/NonEmptyStringVec" + "$ref": "#/components/schemas/NonEmptyStringVec" } } }, @@ -738,20 +677,18 @@ ], "properties": { "operator": { - "$ref": "#/definitions/ProductOrSectorSpecificRuleOperator" + "$ref": "#/components/schemas/ProductOrSectorSpecificRuleOperator" }, "otherOperatorName": { - "anyOf": [ - { - "$ref": "#/definitions/NonEmptyString" - }, + "allOf": [ { - "type": "null" + "$ref": "#/components/schemas/NonEmptyString" } - ] + ], + "nullable": true }, "ruleNames": { - "$ref": "#/definitions/NonEmptyStringVec" + "$ref": "#/components/schemas/NonEmptyStringVec" } } }, diff --git a/src/lib.rs b/src/lib.rs index 7bf5def..1ab856f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -263,6 +263,8 @@ pub struct VersionInteger(pub i32); #[serde(untagged)] /// Encoded geographic scope rules of a Spec Version 2 `CarbonFootprint` pub enum GeographicScope { + #[serde(skip_serializing)] + #[schemars(skip)] Global, #[serde(rename_all = "camelCase")] Regional { diff --git a/src/main.rs b/src/main.rs index d5b6e56..ec36168 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,15 @@ use pact_data_model::*; -use schemars::schema_for; +use schemars::gen::{SchemaGenerator, SchemaSettings}; use serde_json::to_string_pretty; use std::fs::File; use std::io::{Error, Write}; fn main() -> Result<(), Error> { - let schema = schema_for!(ProductFootprint); + let openapi_settings = SchemaSettings::openapi3(); + + let schema_generator = SchemaGenerator::from(openapi_settings); + + let schema = schema_generator.into_root_schema_for::(); let mut schema_json = to_string_pretty(&schema).expect("Failed to serialize schema"); From 29156c193b9722f1a93225a0088f7b3ea0b8071b Mon Sep 17 00:00:00 2001 From: Raimundo Henriques Date: Wed, 10 Jul 2024 16:06:27 +0100 Subject: [PATCH 3/3] chore: use schema generator with draft07 settings --- schema/data-model-schema.json | 270 ++++++++++++++++++++++------------ src/main.rs | 4 +- 2 files changed, 183 insertions(+), 91 deletions(-) diff --git a/schema/data-model-schema.json b/schema/data-model-schema.json index aad8dec..6db8f12 100644 --- a/schema/data-model-schema.json +++ b/schema/data-model-schema.json @@ -1,5 +1,5 @@ { - "$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", + "$schema": "http://json-schema.org/draft-07/schema#", "title": "ProductFootprint", "description": "Data Type \"ProductFootprint\" of Tech Spec Version 2", "type": "object", @@ -23,75 +23,93 @@ "type": "string" }, "companyIds": { - "$ref": "#/components/schemas/CompanyIdSet" + "$ref": "#/definitions/CompanyIdSet" }, "companyName": { - "$ref": "#/components/schemas/NonEmptyString" + "$ref": "#/definitions/NonEmptyString" }, "created": { "type": "string", "format": "date-time" }, "extensions": { - "type": "array", + "type": [ + "array", + "null" + ], "items": { - "$ref": "#/components/schemas/DataModelExtension" + "$ref": "#/definitions/DataModelExtension" }, "nullable": true }, "id": { - "$ref": "#/components/schemas/PfId" + "$ref": "#/definitions/PfId" }, "pcf": { - "$ref": "#/components/schemas/CarbonFootprint" + "$ref": "#/definitions/CarbonFootprint" }, "precedingPfIds": { - "allOf": [ + "anyOf": [ { - "$ref": "#/components/schemas/NonEmptyPfIdVec" + "$ref": "#/definitions/NonEmptyPfIdVec" + }, + { + "type": "null" } ], "nullable": true }, "productCategoryCpc": { - "$ref": "#/components/schemas/NonEmptyString" + "$ref": "#/definitions/NonEmptyString" }, "productDescription": { "type": "string" }, "productIds": { - "$ref": "#/components/schemas/ProductIdSet" + "$ref": "#/definitions/ProductIdSet" }, "productNameCompany": { - "$ref": "#/components/schemas/NonEmptyString" + "$ref": "#/definitions/NonEmptyString" }, "specVersion": { - "$ref": "#/components/schemas/VersionString" + "$ref": "#/definitions/VersionString" }, "status": { - "$ref": "#/components/schemas/PfStatus" + "$ref": "#/definitions/PfStatus" }, "statusComment": { - "type": "string", + "type": [ + "string", + "null" + ], "nullable": true }, "updated": { - "type": "string", + "type": [ + "string", + "null" + ], "format": "date-time", "nullable": true }, "validityPeriodEnd": { - "type": "string", + "type": [ + "string", + "null" + ], "format": "date-time", "nullable": true }, "validityPeriodStart": { - "type": "string", + "type": [ + "string", + "null" + ], "format": "date-time", "nullable": true }, "version": { - "$ref": "#/components/schemas/VersionInteger" + "$ref": "#/definitions/VersionInteger" } }, "definitions": { @@ -107,34 +125,49 @@ "type": "boolean" }, "boundary": { - "allOf": [ + "anyOf": [ + { + "$ref": "#/definitions/AssuranceBoundary" + }, { - "$ref": "#/components/schemas/AssuranceBoundary" + "type": "null" } ], "nullable": true }, "comments": { - "type": "string", + "type": [ + "string", + "null" + ], "nullable": true }, "completedAt": { - "type": "string", + "type": [ + "string", + "null" + ], "format": "date-time", "nullable": true }, "coverage": { - "allOf": [ + "anyOf": [ + { + "$ref": "#/definitions/AssuranceCoverage" + }, { - "$ref": "#/components/schemas/AssuranceCoverage" + "type": "null" } ], "nullable": true }, "level": { - "allOf": [ + "anyOf": [ + { + "$ref": "#/definitions/AssuranceLevel" + }, { - "$ref": "#/components/schemas/AssuranceLevel" + "type": "null" } ], "nullable": true @@ -143,7 +176,10 @@ "type": "string" }, "standardName": { - "type": "string", + "type": [ + "string", + "null" + ], "nullable": true } } @@ -191,7 +227,7 @@ ], "properties": { "geographyRegionOrSubregion": { - "$ref": "#/components/schemas/UNRegionOrSubregion" + "$ref": "#/definitions/UNRegionOrSubregion" } } }, @@ -202,7 +238,7 @@ ], "properties": { "geographyCountry": { - "$ref": "#/components/schemas/ISO3166CC" + "$ref": "#/definitions/ISO3166CC" } } }, @@ -213,7 +249,7 @@ ], "properties": { "geographyCountrySubdivision": { - "$ref": "#/components/schemas/NonEmptyString" + "$ref": "#/definitions/NonEmptyString" } } } @@ -238,40 +274,55 @@ ], "properties": { "aircraftGhgEmissions": { - "allOf": [ + "anyOf": [ { - "$ref": "#/components/schemas/PositiveDecimal" + "$ref": "#/definitions/PositiveDecimal" + }, + { + "type": "null" } ], "nullable": true }, "allocationRulesDescription": { - "type": "string", + "type": [ + "string", + "null" + ], "nullable": true }, "assurance": { - "allOf": [ + "anyOf": [ { - "$ref": "#/components/schemas/Assurance" + "$ref": "#/definitions/Assurance" + }, + { + "type": "null" } ], "nullable": true }, "biogenicAccountingMethodology": { - "allOf": [ + "anyOf": [ + { + "$ref": "#/definitions/BiogenicAccountingMethodology" + }, { - "$ref": "#/components/schemas/BiogenicAccountingMethodology" + "type": "null" } ], "nullable": true }, "biogenicCarbonContent": { - "$ref": "#/components/schemas/PositiveDecimal" + "$ref": "#/definitions/PositiveDecimal" }, "biogenicCarbonWithdrawal": { - "allOf": [ + "anyOf": [ + { + "$ref": "#/definitions/NegativeDecimal" + }, { - "$ref": "#/components/schemas/NegativeDecimal" + "type": "null" } ], "nullable": true @@ -280,26 +331,32 @@ "type": "string" }, "characterizationFactors": { - "$ref": "#/components/schemas/CharacterizationFactors" + "$ref": "#/definitions/CharacterizationFactors" }, "crossSectoralStandardsUsed": { - "$ref": "#/components/schemas/CrossSectoralStandardSet" + "$ref": "#/definitions/CrossSectoralStandardSet" }, "dLucGhgEmissions": { - "allOf": [ + "anyOf": [ { - "$ref": "#/components/schemas/PositiveDecimal" + "$ref": "#/definitions/PositiveDecimal" + }, + { + "type": "null" } ], "nullable": true }, "declaredUnit": { - "$ref": "#/components/schemas/DeclaredUnit" + "$ref": "#/definitions/DeclaredUnit" }, "dqi": { - "allOf": [ + "anyOf": [ + { + "$ref": "#/definitions/DataQualityIndicators" + }, { - "$ref": "#/components/schemas/DataQualityIndicators" + "type": "null" } ], "nullable": true @@ -308,48 +365,60 @@ "type": "string" }, "exemptedEmissionsPercent": { - "$ref": "#/components/schemas/ExemptedEmissionsPercent" + "$ref": "#/definitions/ExemptedEmissionsPercent" }, "fossilCarbonContent": { - "$ref": "#/components/schemas/PositiveDecimal" + "$ref": "#/definitions/PositiveDecimal" }, "fossilGhgEmissions": { - "$ref": "#/components/schemas/PositiveDecimal" + "$ref": "#/definitions/PositiveDecimal" }, "iLucGhgEmissions": { - "allOf": [ + "anyOf": [ + { + "$ref": "#/definitions/PositiveDecimal" + }, { - "$ref": "#/components/schemas/PositiveDecimal" + "type": "null" } ], "nullable": true }, "ipccCharacterizationFactorsSources": { - "$ref": "#/components/schemas/IpccCharacterizationFactorsSources" + "$ref": "#/definitions/IpccCharacterizationFactorsSources" }, "landManagementGhgEmissions": { - "allOf": [ + "anyOf": [ { - "$ref": "#/components/schemas/PositiveDecimal" + "$ref": "#/definitions/PositiveDecimal" + }, + { + "type": "null" } ], "nullable": true }, "otherBiogenicGhgEmissions": { - "allOf": [ + "anyOf": [ + { + "$ref": "#/definitions/PositiveDecimal" + }, { - "$ref": "#/components/schemas/PositiveDecimal" + "type": "null" } ], "nullable": true }, "pCfExcludingBiogenic": { - "$ref": "#/components/schemas/PositiveDecimal" + "$ref": "#/definitions/PositiveDecimal" }, "pCfIncludingBiogenic": { - "allOf": [ + "anyOf": [ { - "$ref": "#/components/schemas/Decimal" + "$ref": "#/definitions/Decimal" + }, + { + "type": "null" } ], "nullable": true @@ -358,23 +427,29 @@ "type": "boolean" }, "packagingGhgEmissions": { - "allOf": [ + "anyOf": [ + { + "$ref": "#/definitions/PositiveDecimal" + }, { - "$ref": "#/components/schemas/PositiveDecimal" + "type": "null" } ], "nullable": true }, "primaryDataShare": { - "allOf": [ + "anyOf": [ + { + "$ref": "#/definitions/Percent" + }, { - "$ref": "#/components/schemas/Percent" + "type": "null" } ], "nullable": true }, "productOrSectorSpecificRules": { - "$ref": "#/components/schemas/ProductOrSectorSpecificRuleSet" + "$ref": "#/definitions/ProductOrSectorSpecificRuleSet" }, "referencePeriodEnd": { "type": "string", @@ -385,19 +460,25 @@ "format": "date-time" }, "secondaryEmissionFactorSources": { - "allOf": [ + "anyOf": [ { - "$ref": "#/components/schemas/EmissionFactorDSSet" + "$ref": "#/definitions/EmissionFactorDSSet" + }, + { + "type": "null" } ], "nullable": true }, "uncertaintyAssessmentDescription": { - "type": "string", + "type": [ + "string", + "null" + ], "nullable": true }, "unitaryProductAmount": { - "$ref": "#/components/schemas/StrictlyPositiveDecimal" + "$ref": "#/definitions/StrictlyPositiveDecimal" } } }, @@ -456,11 +537,14 @@ "type": "string" }, "documentation": { - "type": "string", + "type": [ + "string", + "null" + ], "nullable": true }, "specVersion": { - "$ref": "#/components/schemas/VersionString" + "$ref": "#/definitions/VersionString" } } }, @@ -477,22 +561,22 @@ ], "properties": { "completenessDQR": { - "$ref": "#/components/schemas/FloatBetween1And3" + "$ref": "#/definitions/FloatBetween1And3" }, "coveragePercent": { - "$ref": "#/components/schemas/Percent" + "$ref": "#/definitions/Percent" }, "geographicalDQR": { - "$ref": "#/components/schemas/FloatBetween1And3" + "$ref": "#/definitions/FloatBetween1And3" }, "reliabilityDQR": { - "$ref": "#/components/schemas/FloatBetween1And3" + "$ref": "#/definitions/FloatBetween1And3" }, "technologicalDQR": { - "$ref": "#/components/schemas/FloatBetween1And3" + "$ref": "#/definitions/FloatBetween1And3" }, "temporalDQR": { - "$ref": "#/components/schemas/FloatBetween1And3" + "$ref": "#/definitions/FloatBetween1And3" } } }, @@ -521,10 +605,10 @@ ], "properties": { "name": { - "$ref": "#/components/schemas/NonEmptyString" + "$ref": "#/definitions/NonEmptyString" }, "version": { - "$ref": "#/components/schemas/NonEmptyString" + "$ref": "#/definitions/NonEmptyString" } } }, @@ -538,10 +622,10 @@ ], "properties": { "name": { - "$ref": "#/components/schemas/NonEmptyString" + "$ref": "#/definitions/NonEmptyString" }, "version": { - "$ref": "#/components/schemas/NonEmptyString" + "$ref": "#/definitions/NonEmptyString" } } }, @@ -644,18 +728,21 @@ ], "properties": { "operator": { - "$ref": "#/components/schemas/ProductOrSectorSpecificRuleOperator" + "$ref": "#/definitions/ProductOrSectorSpecificRuleOperator" }, "otherOperatorName": { - "allOf": [ + "anyOf": [ { - "$ref": "#/components/schemas/NonEmptyString" + "$ref": "#/definitions/NonEmptyString" + }, + { + "type": "null" } ], "nullable": true }, "ruleNames": { - "$ref": "#/components/schemas/NonEmptyStringVec" + "$ref": "#/definitions/NonEmptyStringVec" } } }, @@ -677,18 +764,21 @@ ], "properties": { "operator": { - "$ref": "#/components/schemas/ProductOrSectorSpecificRuleOperator" + "$ref": "#/definitions/ProductOrSectorSpecificRuleOperator" }, "otherOperatorName": { - "allOf": [ + "anyOf": [ + { + "$ref": "#/definitions/NonEmptyString" + }, { - "$ref": "#/components/schemas/NonEmptyString" + "type": "null" } ], "nullable": true }, "ruleNames": { - "$ref": "#/components/schemas/NonEmptyStringVec" + "$ref": "#/definitions/NonEmptyStringVec" } } }, diff --git a/src/main.rs b/src/main.rs index ec36168..cd4d7b0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,9 @@ use std::fs::File; use std::io::{Error, Write}; fn main() -> Result<(), Error> { - let openapi_settings = SchemaSettings::openapi3(); + let mut openapi_settings = SchemaSettings::draft07(); + + openapi_settings.option_nullable = true; let schema_generator = SchemaGenerator::from(openapi_settings);