Search code examples
swaggerswagger-codegen

Can you use .\swagger-codegen-cli.jar generate to generate files that are not located in the same folder as swagger-codegen-cli?


Using java -jar .\swagger-codegen-cli.jar generate -l typescript-angular -i .\swagger.json, I can turn ".\swagger.json" into a typescript-angular file. However, the .json file must be in the same folder as the swagger-codegen-cli, which is impractical when you have many files to convert (You have to manually download and move every file). I've scoured the web, but haven't been able to find a practical solution. Is there a way to do this? Am I able to integrate swagger-codegen in such a way that I can "mass produce" files? I know I can change the output directory (-o) but that isn't what I'm looking for. Say I have a folder called "scripts" where I've got a lot of .json files. Am I able to call swagger-codegen-cli generate on any file inside of that folder, even if swagger-codegen-cli is located in a different folder?


Solution

  • The -i argument expects a fully-qualified or relative path to an OpenAPI file, or an URL where that file is located. That is, the file does not have to be in the same folder as the Swagger Codegen CLI.

    Examples:

    # The file is in the current working folder
    -i swagger.json
    -i ./swagger.json
    
    # The file is in a subfolder of the current working folder
    -i sub/folder/swagger.json
    -i ./sub/folder/swagger.json
    
    # Relative path to a file in another folder
    -i ../../path/to/swagger.json
    
    # Absolute path - Windows
    -i C:/path/to/swagger.json
    
    # Absolute path - *nix
    -i ~/path/to/swagger.json
    
    # URL
    -i https://petstore.swagger.io/v2/swagger.json