openapi-cli-generator
openapi-cli-generator copied to clipboard
Getting Started Issues
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?)
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.