danielgtaylor / openapi-cli-generator

Generate a CLI from an OpenAPI 3 specification
MIT License
179 stars 49 forks source link

Getting Started Issues #35

Open kpayson opened 4 years ago

kpayson commented 4 years ago

I want to build a cli from my company's api and I'm trying to get started with the openapi-cli-generator https://github.com/danielgtaylor/openapi-cli-generator but I'm running into some different errors.

I took the petstore demo api https://petstore.swagger.io/v2/swagger.json removed the top of the file comments and converted it to yaml using https://www.json2yaml.com/ then following the steps on the openapi-cli-generator github page, I run openapi-cli-generator generate petstore.yaml

and I get this type of error: Failed to resolve '#/definitions/Pet' in fragment in URI: 'definitions': Struct field not found: definitions which is complaining about lines like schema: "$ref": "#/definitions/Pet" in the yaml file. I tried replacing the $ref values with '' ex "$ref":"" and now I can run openapi-cli-generator generate petstore.yaml Was relacing the ref values with empty string the right thing to do? What is the nature of the problem.

Next, the git hub instructions say to add a line like openapiRegister(false) what is this supposed to do exactly? What does it mean to register a command? Are these the commands that will be part of the cli? What does the syntax look like? The github page doesn't give any examples

Is there supposed to be a one cli command per api call in the generated cli? petstore-cli PetstoreFindPetsByStatus --help - unknown command "PetstoreFindPetsByStatus" for "petstore-cli.exe" (I need to register the command that I want?)

myrho commented 4 years ago

ad 1.: Use OpenAPI version 3.0: https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml

ad 2.: The function openapiRegister is created by the openapi-cli-generator generate subcommand. It's named after the name of the YAML file (here: "openapi.yaml" hence "openapiRegister"). This function kind of activates the API for use in the resulting CLI tool.