syngenta / hotcase

The postman documentation tester
https://www.npmjs.com/package/@syngenta-digital/pdt
Apache License 2.0
18 stars 9 forks source link

TypeError: Cannot read property 'schema' of undefined at Documentor._mapPathSchema #11

Open EloiLeanovia opened 3 years ago

EloiLeanovia commented 3 years ago

Hi, I'm currently trying to use your tool, which looks super cool.

I have documentation generated by a springboot plugin, and I'm trying to get the automatic test generation to work with it.

However, when running the following command : My command

I get this error:

(node:14871) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'schema' of undefined at Documentor._mapPathSchemas (/Users/juszczak/.npm/_npx/14871/lib/node_modules/@syngenta-digital/pdt/src/logic/documentor.js:33:69) at Documentor.importSchema (/Users/juszczak/.npm/_npx/14871/lib/node_modules/@syngenta-digital/pdt/src/logic/documentor.js:19:14) at async _runPostManMerges (/Users/juszczak/.npm/_npx/14871/lib/node_modules/@syngenta-digital/pdt/src/index.js:8:5) at async Object.exports.run (/Users/juszczak/.npm/_npx/14871/lib/node_modules/@syngenta-digital/pdt/src/index.js:35:5) (Usenode --trace-warnings ...to show where the warning was created) (node:14871) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag--unhandled-rejections=strict(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:14871) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I had a look at your code, but I came to the conclusion that the problem must come from my documentation file. However, this one is automatically generated and is perfectly interpreted by swagger ui.

So, I've come to ask you for a little help, in case you have any idea why I'm getting this error.

Here is my open-api file.

{
   "openapi":"3.0.1",
   "info":{
      "title":"My title",
      "description":"This documentation must only be accessible in the development environment",
      "contact":{
         "name":"XXXXX XXXXXXXX",
         "email":"XXXX.XXXXXX@email.com"
      },
      "version":"v1.3"
   },
   "servers":[
      {
         "url":"http://localhost:8080",
         "description":"Generated server url"
      }
   ],
   "paths":{
      "/admin/actif":{
         "get":{
            "tags":[
               "AdminActifController"
            ],
            "summary":"Récupère tous les actifs selon un ou plusieurs filtres",
            "description":"Les filtres peuvent être le statut, la date de fin de garantie, la date d'achat, la date de mise au rebut...",
            "operationId":"getAllByFilters",
            "parameters":[
               {
                  "name":"actifSpec",
                  "in":"query",
                  "required":true,
                  "schema":{
                     "$ref":"#/components/schemas/SpecificationActif"
                  }
               }
            ],
            "responses":{
               "200":{
                  "description":"OK",
                  "content":{
                     "application/json":{
                        "schema":{
                           "type":"array",
                           "items":{
                              "$ref":"#/components/schemas/ActifResumeDTO"
                           }
                        }
                     }
                  }
               }
            }
         },
         "post":{
            "tags":[
               "AdminActifController"
            ],
            "summary":"Enregistre l'achat d'un actif",
            "operationId":"save",
            "requestBody":{
               "content":{
                  "application/json":{
                     "schema":{
                        "$ref":"#/components/schemas/CreationActifDTO"
                     }
                  }
               },
               "required":true
            },
            "responses":{
               "200":{
                  "description":"OK",
                  "content":{
                     "application/json":{
                        "schema":{
                           "$ref":"#/components/schemas/AdminActifDetailDTO"
                        }
                     }
                  }
               }
            }
         }
      },
      "/admin/emprunts/{id}":{
         "patch":{
            "tags":[
               "AdminEmpruntController"
            ],
            "summary":"Enregistre la fin de prêt d'un actif",
            "operationId":"saveFinEmprunt",
            "parameters":[
               {
                  "name":"id",
                  "in":"path",
                  "required":true,
                  "schema":{
                     "type":"integer",
                     "format":"int64"
                  }
               }
            ],
            "requestBody":{
               "content":{
                  "application/json":{
                     "schema":{
                        "$ref":"#/components/schemas/FinEmpruntDTO"
                     }
                  }
               },
               "required":true
            },
            "responses":{
               "200":{
                  "description":"OK",
                  "content":{
                     "application/json":{
                        "schema":{
                           "$ref":"#/components/schemas/EmpruntDTO"
                        }
                     }
                  }
               }
            }
         }
      },
      "/consultant/actif/empruntes":{
         "get":{
            "tags":[
               "ConsultantActifController"
            ],
            "summary":"Retourne la liste des actifs empruntés par le consultant",
            "operationId":"getActifsEmpruntes",
            "responses":{
               "200":{
                  "description":"OK",
                  "content":{
                     "application/json":{
                        "schema":{
                           "type":"array",
                           "items":{
                              "$ref":"#/components/schemas/ActifResumeDTO"
                           }
                        }
                     }
                  }
               }
            }
         }
      },
      "/admin/reparations/{id}":{
         "patch":{
            "tags":[
               "AdminReparationController"
            ],
            "summary":"Enregistre une fin de réparation pour un actif",
            "operationId":"saveFinReparation",
            "parameters":[
               {
                  "name":"id",
                  "in":"path",
                  "required":true,
                  "schema":{
                     "type":"integer",
                     "format":"int64"
                  }
               }
            ],
            "requestBody":{
               "content":{
                  "application/json":{
                     "schema":{
                        "$ref":"#/components/schemas/FinReparationDTO"
                     }
                  }
               },
               "required":true
            },
            "responses":{
               "200":{
                  "description":"OK",
                  "content":{
                     "application/json":{
                        "schema":{
                           "$ref":"#/components/schemas/ReparationDTO"
                        }
                     }
                  }
               }
            }
         }
      },
      "/":{
         "get":{
            "tags":[
               "HomeController"
            ],
            "summary":"Redirige vers la page swagger-ui",
            "operationId":"index",
            "responses":{
               "200":{
                  "description":"OK",
                  "content":{
                     "*/*":{
                        "schema":{
                           "type":"string"
                        }
                     }
                  }
               }
            }
         }
      },
      "/admin/emprunts":{
         "post":{
            "tags":[
               "AdminEmpruntController"
            ],
            "summary":"Enregistre un prêt d'un actif a un consultant",
            "operationId":"saveEmprunt",
            "requestBody":{
               "content":{
                  "application/json":{
                     "schema":{
                        "$ref":"#/components/schemas/DebutEmpruntDTO"
                     }
                  }
               },
               "required":true
            },
            "responses":{
               "200":{
                  "description":"OK",
                  "content":{
                     "application/json":{
                        "schema":{
                           "$ref":"#/components/schemas/EmpruntDTO"
                        }
                     }
                  }
               }
            }
         }
      },
      "/consultant/actif":{
         "get":{
            "tags":[
               "ConsultantActifController"
            ],
            "summary":"Retourne la liste des actifs, filtrés par disponibilité",
            "operationId":"getAllByFilters_1",
            "parameters":[
               {
                  "name":"actifSpec",
                  "in":"query",
                  "required":true,
                  "schema":{
                     "$ref":"#/components/schemas/SpecificationActif"
                  }
               }
            ],
            "responses":{
               "200":{
                  "description":"OK",
                  "content":{
                     "application/json":{
                        "schema":{
                           "type":"array",
                           "items":{
                              "$ref":"#/components/schemas/ActifResumeDTO"
                           }
                        }
                     }
                  }
               }
            }
         }
      },
      "/admin/reparations":{
         "post":{
            "tags":[
               "AdminReparationController"
            ],
            "summary":"Enregistre une réparation pour un actif",
            "operationId":"saveReparation",
            "requestBody":{
               "content":{
                  "application/json":{
                     "schema":{
                        "$ref":"#/components/schemas/DebutReparationDTO"
                     }
                  }
               },
               "required":true
            },
            "responses":{
               "200":{
                  "description":"OK",
                  "content":{
                     "application/json":{
                        "schema":{
                           "$ref":"#/components/schemas/ReparationDTO"
                        }
                     }
                  }
               }
            }
         }
      },
      "/admin/actif/{id}":{
         "get":{
            "tags":[
               "AdminActifController"
            ],
            "summary":"Retourne un actif détaillé",
            "operationId":"getDetail",
            "parameters":[
               {
                  "name":"id",
                  "in":"path",
                  "required":true,
                  "schema":{
                     "type":"integer",
                     "format":"int64"
                  }
               }
            ],
            "responses":{
               "200":{
                  "description":"OK",
                  "content":{
                     "application/json":{
                        "schema":{
                           "$ref":"#/components/schemas/AdminActifDetailDTO"
                        }
                     }
                  }
               }
            }
         },
         "delete":{
            "tags":[
               "AdminActifController"
            ],
            "summary":"Supprime un actif ",
            "description":"Seul les actifs qui n'ont jamais été empruntés peuvent être supprimés",
            "operationId":"delete",
            "parameters":[
               {
                  "name":"id",
                  "in":"path",
                  "required":true,
                  "schema":{
                     "type":"integer",
                     "format":"int64"
                  }
               }
            ],
            "responses":{
               "200":{
                  "description":"OK"
               }
            }
         },
         "patch":{
            "tags":[
               "AdminActifController"
            ],
            "summary":"Enregistre la mise au rebut d'un actif",
            "operationId":"saveMiseAuRebut",
            "parameters":[
               {
                  "name":"id",
                  "in":"path",
                  "required":true,
                  "schema":{
                     "type":"integer",
                     "format":"int64"
                  }
               }
            ],
            "requestBody":{
               "content":{
                  "application/json":{
                     "schema":{
                        "$ref":"#/components/schemas/MiseAuRebutDTO"
                     }
                  }
               },
               "required":true
            },
            "responses":{
               "200":{
                  "description":"OK",
                  "content":{
                     "application/json":{
                        "schema":{
                           "$ref":"#/components/schemas/AdminActifDetailDTO"
                        }
                     }
                  }
               }
            }
         }
      },
      "/consultant/actif/{id}":{
         "get":{
            "tags":[
               "ConsultantActifController"
            ],
            "summary":"Retourne un actif détaillé",
            "operationId":"getDetails",
            "parameters":[
               {
                  "name":"id",
                  "in":"path",
                  "required":true,
                  "schema":{
                     "type":"integer",
                     "format":"int64"
                  }
               }
            ],
            "responses":{
               "200":{
                  "description":"OK",
                  "content":{
                     "application/json":{
                        "schema":{
                           "$ref":"#/components/schemas/ConsultantActifDetailDTO"
                        }
                     }
                  }
               }
            }
         }
      },
      "/consultant/incidents":{
         "post":{
            "tags":[
               "ConsultantIncidentController"
            ],
            "summary":"Signaler un incident sur un actif emprunté",
            "operationId":"signalerIncident",
            "requestBody":{
               "content":{
                  "application/json":{
                     "schema":{
                        "$ref":"#/components/schemas/CreationIncidentDTO"
                     }
                  }
               },
               "required":true
            },
            "responses":{
               "200":{
                  "description":"OK",
                  "content":{
                     "application/json":{
                        "schema":{
                           "$ref":"#/components/schemas/IncidentDTO"
                        }
                     }
                  }
               }
            }
         }
      },
      "/admin/consultant":{
         "get":{
            "tags":[
               "AdminConsultantController"
            ],
            "summary":"Récupère la liste de tous les consultants",
            "operationId":"getAll",
            "responses":{
               "200":{
                  "description":"OK",
                  "content":{
                     "application/json":{
                        "schema":{
                           "type":"array",
                           "items":{
                              "$ref":"#/components/schemas/ConsultantWithIdDTO"
                           }
                        }
                     }
                  }
               }
            }
         }
      }
   },
   "components":{
      "schemas":{
         "CreationActifDTO":{
            "type":"object",
            "properties":{
               "intitule":{
                  "type":"string"
               },
               "typeActif":{
                  "type":"string",
                  "enum":[
                     "LIVRE",
                     "LIVRE_NUMERIQUE",
                     "ORDINATEUR_PORTABLE",
                     "SMARTPHONE",
                     "MACHINE_VIRTUELLE",
                     "CLE"
                  ]
               },
               "etiquette":{
                  "type":"string"
               },
               "champLibre":{
                  "type":"string"
               },
               "valeur":{
                  "type":"number",
                  "format":"float"
               },
               "facture":{
                  "type":"string"
               },
               "dateAchat":{
                  "type":"string",
                  "format":"date-time"
               },
               "debutGarantie":{
                  "type":"string",
                  "format":"date-time"
               },
               "finGarantie":{
                  "type":"string",
                  "format":"date-time"
               }
            }
         },
         "AdminActifDetailDTO":{
            "type":"object",
            "properties":{
               "id":{
                  "type":"integer",
                  "format":"int64"
               },
               "intitule":{
                  "type":"string"
               },
               "typeActif":{
                  "type":"string",
                  "enum":[
                     "LIVRE",
                     "LIVRE_NUMERIQUE",
                     "ORDINATEUR_PORTABLE",
                     "SMARTPHONE",
                     "MACHINE_VIRTUELLE",
                     "CLE"
                  ]
               },
               "etiquette":{
                  "type":"string"
               },
               "champLibre":{
                  "type":"string"
               },
               "valeur":{
                  "type":"number",
                  "format":"float"
               },
               "facture":{
                  "type":"string"
               },
               "statut":{
                  "type":"string",
                  "enum":[
                     "NOUVEAU",
                     "DISPONIBLE",
                     "EMPRUNTE",
                     "A_REPARER",
                     "EN_REPARATION",
                     "AU_REBUT"
                  ]
               },
               "dateAchat":{
                  "type":"string",
                  "format":"date-time"
               },
               "dateMiseRebut":{
                  "type":"string",
                  "format":"date-time"
               },
               "debutGarantie":{
                  "type":"string",
                  "format":"date-time"
               },
               "finGarantie":{
                  "type":"string",
                  "format":"date-time"
               },
               "reparations":{
                  "type":"array",
                  "items":{
                     "$ref":"#/components/schemas/ReparationDTO"
                  }
               },
               "emprunts":{
                  "type":"array",
                  "items":{
                     "$ref":"#/components/schemas/EmpruntDTO"
                  }
               }
            }
         },
         "ConsultantDTO":{
            "type":"object",
            "properties":{
               "nom":{
                  "type":"string"
               },
               "prenom":{
                  "type":"string"
               }
            }
         },
         "EmpruntDTO":{
            "type":"object",
            "properties":{
               "idEmprunt":{
                  "type":"integer",
                  "format":"int64"
               },
               "dateDebut":{
                  "type":"string",
                  "format":"date-time"
               },
               "dateFin":{
                  "type":"string",
                  "format":"date-time"
               },
               "etatLieuxEntree":{
                  "type":"string"
               },
               "etatLieuxSortie":{
                  "type":"string"
               },
               "incidents":{
                  "type":"array",
                  "items":{
                     "$ref":"#/components/schemas/IncidentDTO"
                  }
               },
               "consultant":{
                  "$ref":"#/components/schemas/ConsultantDTO"
               }
            }
         },
         "IncidentDTO":{
            "type":"object",
            "properties":{
               "idIncident":{
                  "type":"integer",
                  "format":"int64"
               },
               "date":{
                  "type":"string",
                  "format":"date-time"
               },
               "description":{
                  "type":"string"
               },
               "isaReparer":{
                  "type":"boolean"
               }
            }
         },
         "ReparationDTO":{
            "type":"object",
            "properties":{
               "idReparation":{
                  "type":"integer",
                  "format":"int64"
               },
               "debutReparation":{
                  "type":"string",
                  "format":"date-time"
               },
               "finReparation":{
                  "type":"string",
                  "format":"date-time"
               },
               "description":{
                  "type":"string"
               },
               "cout":{
                  "type":"number",
                  "format":"float"
               },
               "facture":{
                  "type":"string"
               }
            }
         },
         "FinEmpruntDTO":{
            "type":"object",
            "properties":{
               "dateFin":{
                  "type":"string",
                  "format":"date-time"
               },
               "etatLieuxSortie":{
                  "type":"string"
               }
            }
         },
         "ActifResumeDTO":{
            "type":"object",
            "properties":{
               "id":{
                  "type":"integer",
                  "format":"int64"
               },
               "intitule":{
                  "type":"string"
               },
               "typeActif":{
                  "type":"string",
                  "enum":[
                     "LIVRE",
                     "LIVRE_NUMERIQUE",
                     "ORDINATEUR_PORTABLE",
                     "SMARTPHONE",
                     "MACHINE_VIRTUELLE",
                     "CLE"
                  ]
               },
               "etiquette":{
                  "type":"string"
               },
               "statut":{
                  "type":"string",
                  "enum":[
                     "NOUVEAU",
                     "DISPONIBLE",
                     "EMPRUNTE",
                     "A_REPARER",
                     "EN_REPARATION",
                     "AU_REBUT"
                  ]
               },
               "consultantEmprunteurActuel":{
                  "$ref":"#/components/schemas/ConsultantDTO"
               }
            }
         },
         "FinReparationDTO":{
            "type":"object",
            "properties":{
               "finReparation":{
                  "type":"string",
                  "format":"date-time"
               },
               "facture":{
                  "type":"string"
               }
            }
         },
         "SpecificationActif":{
            "type":"object"
         },
         "DebutEmpruntDTO":{
            "type":"object",
            "properties":{
               "dateDebut":{
                  "type":"string",
                  "format":"date-time"
               },
               "etatLieuxEntree":{
                  "type":"string"
               },
               "idActif":{
                  "type":"integer",
                  "format":"int64"
               },
               "idConsultant":{
                  "type":"integer",
                  "format":"int64"
               }
            }
         },
         "DebutReparationDTO":{
            "type":"object",
            "properties":{
               "debutReparation":{
                  "type":"string",
                  "format":"date-time"
               },
               "description":{
                  "type":"string"
               },
               "cout":{
                  "type":"number",
                  "format":"float"
               },
               "idActif":{
                  "type":"integer",
                  "format":"int64"
               }
            }
         },
         "ConsultantActifDetailDTO":{
            "type":"object",
            "properties":{
               "id":{
                  "type":"integer",
                  "format":"int64"
               },
               "intitule":{
                  "type":"string"
               },
               "typeActif":{
                  "type":"string",
                  "enum":[
                     "LIVRE",
                     "LIVRE_NUMERIQUE",
                     "ORDINATEUR_PORTABLE",
                     "SMARTPHONE",
                     "MACHINE_VIRTUELLE",
                     "CLE"
                  ]
               },
               "etiquette":{
                  "type":"string"
               },
               "champLibre":{
                  "type":"string"
               },
               "statut":{
                  "type":"string",
                  "enum":[
                     "NOUVEAU",
                     "DISPONIBLE",
                     "EMPRUNTE",
                     "A_REPARER",
                     "EN_REPARATION",
                     "AU_REBUT"
                  ]
               },
               "dateMiseRebut":{
                  "type":"string",
                  "format":"date-time"
               },
               "debutGarantie":{
                  "type":"string",
                  "format":"date-time"
               },
               "finGarantie":{
                  "type":"string",
                  "format":"date-time"
               },
               "reparations":{
                  "type":"array",
                  "items":{
                     "$ref":"#/components/schemas/ReparationDTO"
                  }
               },
               "emprunts":{
                  "type":"array",
                  "items":{
                     "$ref":"#/components/schemas/EmpruntDTO"
                  }
               }
            }
         },
         "CreationIncidentDTO":{
            "type":"object",
            "properties":{
               "date":{
                  "type":"string",
                  "format":"date-time"
               },
               "description":{
                  "type":"string"
               },
               "idActif":{
                  "type":"integer",
                  "format":"int64"
               },
               "isaReparer":{
                  "type":"boolean"
               }
            }
         },
         "ConsultantWithIdDTO":{
            "type":"object",
            "properties":{
               "id":{
                  "type":"integer",
                  "format":"int64"
               },
               "nom":{
                  "type":"string"
               },
               "prenom":{
                  "type":"string"
               }
            }
         },
         "MiseAuRebutDTO":{
            "type":"object",
            "properties":{
               "dateMiseRebut":{
                  "type":"string",
                  "format":"date-time"
               }
            }
         }
      }
   }
}

Thanks in advance :)

paulcruse-syn commented 3 years ago

Hi,

I'll take a look and get back with a solution shortly

SimonCull commented 2 years ago

Any update on this?

kyleposluns commented 2 years ago

I am also having issues with this error.

EloiLeanovia commented 2 years ago

Hi, I think I have targeted the problem. In the src/logic/documentor.js file on line 31. The problem was that only Content-Type: application/json cases were processed. So, if your swagger contains others Content-Type such as application/xml or text/plain, it crashes.

The solution I found was to add :

if (this._openapi && content) { const {'application/json': app_json} = content; if(app_json){ this._mapping[mapping_key][code] = app_json.schema; } }

instead of

if (this._openapi && content) { const {'application/json': app_json} = content; this._mapping[mapping_key][code] = app_json.schema; }

to make it works (only with JSON)

@paulcruse-syn does it seems you a correct solution ? I have to notify you that I have another issue (I will open a new ticket issue for it) : commands are working, I have no error but it does not write the tests in the collection. I don't know if it's related to my modification.

Thanks in advance for your replies :)

paulcruse-syn commented 2 years ago

@EloiLeanovia this is great!

Can you make a PR withe changes and a test case to cover it?

EloiLeanovia commented 2 years ago

@EloiLeanovia this is great!

Can you make a PR withe changes and a test case to cover it?

Yes I will do that if I can make it works totally.

dudziakm commented 1 year ago

@EloiLeanovia this is great! Can you make a PR withe changes and a test case to cover it?

Yes I will do that if I can make it works totally.

was the PR created? ;)