CODEGEN的使用
【摘要】 CODEGEN命令参数NAME swagger-codegen-cli generate - Generate code with chosen langSYNOPSIS swagger-codegen-cli generate [(-a <authorization> | --auth <authorization>)]
CODEGEN
命令参数
NAME
swagger-codegen-cli generate - Generate code with chosen lang
SYNOPSIS
swagger-codegen-cli generate
[(-a <authorization> | --auth <authorization>)]
[--additional-properties <additional properties>...]
[--api-package <api package>] [--artifact-id <artifact id>]
[--artifact-version <artifact version>]
[(-c <configuration file> | --config <configuration file>)]
[-D <system properties>...] [--git-repo-id <git repo id>]
[--git-user-id <git user id>] [--group-id <group id>]
[--http-user-agent <http user agent>]
(-i <spec file> | --input-spec <spec file>)
[--ignore-file-override <ignore file override location>]
[--import-mappings <import mappings>...]
[--instantiation-types <instantiation types>...]
[--invoker-package <invoker package>]
(-l <language> | --lang <language>)
[--language-specific-primitives <language specific primitives>...]
[--library <library>] [--model-name-prefix <model name prefix>]
[--model-name-suffix <model name suffix>]
[--model-package <model package>]
[(-o <output directory> | --output <output directory>)]
[--release-note <release note>] [--remove-operation-id-prefix]
[--reserved-words-mappings <reserved word mappings>...]
[(-s | --skip-overwrite)]
[(-t <template directory> | --template-dir <template directory>)]
[--type-mappings <type mappings>...] [(-v | --verbose)]
OPTIONS
-a <authorization>, --auth <authorization>
adds authorization headers when fetching the swagger definitions
remotely. Pass in a URL-encoded string of name:header with a comma
separating multiple values
...... (results omitted)
-v, --verbose
verbose mode
修改mustache模板
在codegen项目里的resource文件夹中有各种语言的模板。
CME项目可以在JavaJaxRS/cxf模板的基础上修改。在运行codegen时通过-t
命令指定模板所在的文件夹。
修改pom.mustache
去掉cxf的相关引用,使用CloudSOP平台的库。
<dependency>
<groupId>com.huawei.bsp</groupId>
<artifactId>com.huawei.bsp.commonlib.jaxrs</artifactId>
<version>6.0.12</version>
</dependency>
去掉logback相关库。
去掉swagger相关库。
修改json库从fasterxml到codehaus。
各库的版本也需要修改,或者直接删去版本吗,通过parent项目指定。
在apiServiceImpl.mustache
中去掉
import org.apache.cxf.jaxrs.model.wadl.Description;
import org.apache.cxf.jaxrs.model.wadl.DocTarget;
修改了cxf子文件夹中的returnTypes.mustache,改成跟根目录的一致。
去掉.swagger-codegen-ignore
中的**/impl/*
。
Maven plug-in
可配置参数
- inputSpec - OpenAPI Spec file path
- language - target generation language
- output - target output path (default is ${project.build.directory}/generated-sources/swagger)
- templateDirectory - directory with mustache templates
- addCompileSourceRoot - add the output directory to the project as a source root (true by default)
- modelPackage - the package to use for generated model objects/classes
- apiPackage - the package to use for generated api objects/classes
- invokerPackage - the package to use for the generated invoker objects
- configOptions - a map of language-specific parameters (see below)
- configHelp - dumps the configuration help for the specified library (generates no sources)
sortParamsByRequiredFlag
Sort method arguments to place required parameters before optional parameters. (Default: true)
ensureUniqueParams
Whether to ensure parameter names are unique in an operation (rename parameters that are not). (Default: true)
modelPackage
package for generated models
apiPackage
package for generated api classes
invokerPackage
root package for generated code
groupId
groupId in generated pom.xml
artifactId
artifactId in generated pom.xml
artifactVersion
artifact version in generated pom.xml
sourceFolder
source folder for generated code
localVariablePrefix
prefix for generated code members and local variables
serializableModel
boolean - toggle "implements Serializable" for generated models (Default: false)
bigDecimalAsString
Treat BigDecimal values as Strings to avoid precision loss. (Default: false)
fullJavaUtil
whether to use fully qualified name for classes under java.util (Default: false)
library
library template (sub-template) to use (Default: <default>)
<default> - HTTP client: Jersey client 1.18. JSON processing: Jackson 2.4.2
feign - HTTP client: Netflix Feign 8.1.1
jersey2 - HTTP client: Jersey client 2.6
okhttp-gson - HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1
retrofit - HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1 (Retrofit 1.9.0)
retrofit2 - HTTP client: OkHttp 2.5.0. JSON processing: Gson 2.4 (Retrofit 2.0.0-beta2)
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)