Manweill / swagger-axios-codegen

swagger client to use axios and typescript
MIT License
306 stars 83 forks source link

Trouble when generating with string type definitions #2

Closed damir-manapov closed 5 years ago

damir-manapov commented 6 years ago

Hi!

I'm have trouble when generating with string type definitions. Example of swagger.json:

{
  "swagger" : "2.0",
  "info" : {
    "version" : "1.0.0",
    "title" : "Test API"
  },
  "host" : "api.test.com",
  "basePath" : "/v1",
  "schemes" : [ "https" ],
  "produces" : [ "application/json" ],
  "paths" : {
  },
  "definitions" : {
    "ContractStatus" : {
      "type" : "string",
      "description" : "Enumeration of contract status",
      "enum" : [ "Placed", "Approved", "Started", "Closed" ]
    }
  }
}

Error:

(node:31783) UnhandledPromiseRejectionWarning: TypeError: Cannot convert undefined or null to object
    at Function.entries (<anonymous>)
    at createDefinitionClass (/Users/damir/proj/node_modules/swagger-axios-codegen/dist/definitionCodegen.js:65:39)
    at Object.definitionsCodeGen (/Users/damir/proj/node_modules/swagger-axios-codegen/dist/definitionCodegen.js:101:34)
    at codegen (/Users/damir/proj/node_modules/swagger-axios-codegen/dist/index.js:56:38)
    at Object.<anonymous> (/Users/damir/proj/swag/codegen.js:3:1)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
(node:31783) 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(). (rejection id: 1)
(node:31783) [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.
Manweill commented 6 years ago

I have not seen such a structure like this. How do you got it

Manweill commented 6 years ago

@damir-manapov I can fix it,but the codegen will return empty of this swagger.json

damir-manapov commented 6 years ago

There it is: https://swagger.io/docs/specification/2-0/enums/ It may be used as usual definition: https://app.swaggerhub.com/apis/LearningTech/EnumExample/0.0.1

damir-manapov commented 6 years ago

@Manweill perfect! Will it work for https://api.swaggerhub.com/apis/LearningTech/EnumExample/0.0.1 ?

Manweill commented 6 years ago

when you use swagger in your application,it is like this

"Contract": {
      "description": "Model of the contract",
      "type": "object",
      "properties": {
        "contractId": {
          "type": "string",
          "description": "Contract unique identificator in the system"
        },
        "contractName": {
          "type": "string",
          "description": "Short name of the contract"
        },
        "status": {
          "type": "string",
          "enum": [
            "Placed",
            "Approved",
            "Started",
            "Closed"
          ]
        }
      }
    }
damir-manapov commented 6 years ago

Ok, @Manweill It will be great if such swagger works

damir-manapov commented 6 years ago

Hi! How long it might take to fix this?

Manweill commented 6 years ago

@damir-manapov Welcome PR! And then, I will fix it at Mid-October

Manweill commented 5 years ago

fix in 0.3