Linux command
swagger-codegen 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Generate client
swagger-codegen generate -i [api.yaml] -l [java] -o [output/]
List languages
swagger-codegen langs
Generate with config
swagger-codegen generate -i [api.yaml] -l [python] -c [config.json] -o [output/]
Validate spec
swagger-codegen validate -i [api.yaml]
Show help for language
swagger-codegen config-help -l [typescript-angular]
说明
swagger-codegen generates API client libraries, server stubs, and documentation from OpenAPI (Swagger) specification files. It reads a YAML or JSON API definition and produces code in dozens of target languages and frameworks including Java, Python, TypeScript, Go, Ruby, and many more. Client generation creates ready-to-use SDK code with models, API classes, and serialization logic matching the API specification. Server stub generation scaffolds backend code with route definitions and request/response models. Documentation generation produces HTML or other formats. The tool uses Mustache templates that can be customized to control the exact output format. A configuration file can specify additional options such as package names, model naming conventions, and library preferences for the target language.
参数
- generate
- Generate code.
- langs
- List languages.
- validate
- Validate spec.
- -i _FILE_
- Input spec file.
- -l _LANG_
- Target language.
- -o _DIR_
- Output directory.
- -c _FILE_
- Config file.
FAQ
What is the swagger-codegen command used for?
swagger-codegen generates API client libraries, server stubs, and documentation from OpenAPI (Swagger) specification files. It reads a YAML or JSON API definition and produces code in dozens of target languages and frameworks including Java, Python, TypeScript, Go, Ruby, and many more. Client generation creates ready-to-use SDK code with models, API classes, and serialization logic matching the API specification. Server stub generation scaffolds backend code with route definitions and request/response models. Documentation generation produces HTML or other formats. The tool uses Mustache templates that can be customized to control the exact output format. A configuration file can specify additional options such as package names, model naming conventions, and library preferences for the target language.
How do I run a basic swagger-codegen example?
Run `swagger-codegen generate -i [api.yaml] -l [java] -o [output/]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does generate do in swagger-codegen?
Generate code.