Closed phillim1 closed 4 years ago
At first glance I think you're doing this correctly. I'll dig into it.
It was a bug. The problem came down to the library attempting to validate your example before fully resolving your discriminator references.
Thanks for the issue. It's now fixed and published to NPM as version 1.10.8
.
Getting issues from almost similar OAS3 document from openapi-enforcer @ 1.11.2 Unable to deserialize value' ' at: tradeLegs' ' at: 0' ' Unable to determine deserialization schema beca use too many schemas match. Use of a discriminator or making your schemas more specific would help this problem.' ' at: 1' ' Unable to determine deserialization schema beca use too many schemas match. Use of a discriminator or making your schemas more specific would help this problem.'
The OAS3 schema is ,
"TradeDetails": {
"type": "object",
"title": "TradeDetails",
"description": "Detailed version of the trade data.",
"properties": {
"tradeId": {
"type": "string",
"description": "The reference identifier of the trade.",
"example": "500560B",
"maxLength": 256
},
"tradeType": {
"type": "string",
"example": "SWAP",
"description": "Financial type of the deal.",
"maxLength": 50
},
"tradeStatus": {
"type": "string",
"example": "PRE-TRADE",
"description": "Status of the deal such as verified, done, pre-trade, pre-deal.",
"maxLength": 50
},
"legalEntityId": {
"type": "string",
"description": "Identifier of the legal entity, institution/business that owns the transactions.",
"example": "0010107588B",
"maxLength": 256
},
"anonymizedCptyId": {
"type": "string",
"description": "Anonymized Identifier of the counterparty with which the trade is executed.",
"example": "0010107588B",
"maxLength": 256
},
"collateralCurrency": {
"type": "string",
"example": "EUR",
"description": "Collateral currency in format ISO 4217.",
"pattern": "[A-Z]{3,3}"
},
"csaId": {
"type": "string",
"description": "Identifier of the counterparty CSA.",
"example": "0010107588B_CSA",
"maxLength": 256
},
"tradingBookName": {
"$ref": "#/components/schemas/TradingBook"
},
"nettingSetId": {
"type": "string",
"description": "Identifier of Netting set.",
"example": "Netting Set 1",
"maxLength": 256
},
"tradeLegs": {
"type": "array",
"description": "The definition of trade financials by leg.",
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/InterestRateInstrument"
},
{
"$ref": "#/components/schemas/ForeignExchangeInstrument"
}
],
"discriminator": {
"propertyName": "instrumentType"
}
}
}
}
Validating Response is,
{
"id": "6011a1d6d80b3b60df9d8b89",
"tradeId": "18237HM",
"tradeType": "SWAP",
"tradeStatus": "VER",
"legalEntityId": "MGCCOLL",
"anonymizedCptyId": "e00f5ba5-0d3b-4ced-bcf2-ccc29861aa52",
"collateralCurrency": "",
"csaId": "",
"tradingBookName": {
"businessUnit": "MGCCOLL",
"desk": "MGCDESK",
"book": "ECBOOK"
},
"nettingSetId": "MGCCOLLSB",
"tradeLegs": [
{
"instrumentType": "InterestRateInstrument",
"instrumentId": "000009QC",
"currency": "USD",
"direction": "SELL",
"effectiveDate": "2013-01-22",
"maturityDate": "2019-01-22",
"notional": 51000000,
"fixedRate": 0,
"minRate": null,
"maxRate": null,
"index": "LIBOR",
"term": "12M",
"basis": "A360",
"periodSchedule": [
{
"periodId": null,
"periodStart": null,
"periodEnd": null,
"fixingDate": null,
"fxFixingDate": null,
"payDate": "2013-01-22",
"paymentType": "notional-exchange",
"notional": null,
"notionalChange": 51000000,
"rate": 0,
"spread": 0,
"periodDetails": null
}
],
"instrumentDetails": null
},
{
"instrumentType": "InterestRateInstrument",
"instrumentId": "000009QD",
"currency": "EUR",
"direction": "BUY",
"effectiveDate": "2013-01-22",
"maturityDate": "2019-01-22",
"notional": 37488973.831226,
"fixedRate": 0.05,
"minRate": null,
"maxRate": null,
"index": "FIXED",
"term": "",
"basis": "30/360",
"periodSchedule": [
{
"periodId": null,
"periodStart": null,
"periodEnd": null,
"fixingDate": null,
"fxFixingDate": null,
"payDate": "2013-01-22",
"paymentType": "notional-exchange",
"notional": null,
"notionalChange": -37488973.831226,
"rate": 0,
"spread": 0,
"periodDetails": null
}
],
"instrumentDetails": null
}
]
}
after updating with mapping
"mapping": {
"InterestRateInstrument": "#/components/schemas/InterestRateInstrument",
"ForeignExchangeInstrument": "#/components/schemas/ForeignExchangeInstrument"
}
it shows
TypeError: Cannot read property 'staticData' of undefined"
Using openapi-enforcer @ 1.10.5 with the below file gives a warning as follows:
"WARNED - API schema warnings found by openapi-enforcer for swagger.162457205.json [ EnforcerException: One or more warnings exist in the OpenApi definition at: components > schemas > Pets > example Invalid value Discriminator property "petType" as "Cat" did not map to a schema ]"
If I then add mapping as follows
then I receive a failure as follows: _"FAILED - API schema errors found by openapi-enforcer for swagger.163231602.json [ EnforcerException: One or more errors exist in the OpenApi definition at: components > schemas Unexpected error encountered: TypeError: Cannot read property 'staticData' of undefined at runDeserialize (<...>/node_modules/openapi-enforcer/src/schema/deserialize.js:110:47) at runDeserialize (<...>/node_modules/openapi-enforcer/src/schema/deserialize.js:65:43) at Schema.deserialize (<...>/node_modules/openapi-enforcer/src/enforcers/Schema.js:52:24) at deserializeAndValidate (<...>/node_modules/openapi-enforcer/src/enforcers/Schema.js:789:31) at Schema.init (<...>/node_modules/openapi-enforcer/src/enforcers/Schema.js:230:27) at build (<...>/node_modules/openapi-enforcer/src/super.js:162:46) at new Schema (eval at createConstructor (<...>/node_modules/openapi-enforcer/src/super.js:37:15)- at runChildValidator (<...>/node_modules/openapi-enforcer/src/definition-validator.js:378:20) at <...>/nodemodules/openapi-enforcer/src/definition-validator.js:136:44 at Array.forEach () ]"
Please can you confirm whether this is an issue with openapi-enforcer or the syntax of my file.