标签: swagger-codegen

为同一个项目中的多个swaggers生成代码

我如何从一个 pom.xml 中的同一个模块/项目中为多个 swagger 文件生成代码。

在我的应用程序中,客户端提供了一个 swagger,我们有一个后端 API 被调用,他们提供了 swagger。我想在同一个项目中为这两个生成代码。我想的一种方法是创建单独的模块并单独执行插件,并在主模块中调用这些依赖项。

如何从一个构建插件生成代码?如果是转贴,请指出现有的。我找不到任何。

这是我在 pom.xml 中配置的插件

 <plugin>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-codegen-maven-plugin</artifactId>
            <version>2.2.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                      <inputSpec>${project.basedir}/src/main/ resources/Service.json</inputSpec><inputSpec>${project.basedir}/src /main/resources/Client.json</inputSpec>
                        <language>java</language>
                        <configOptions>
                            <dateLibrary>java8</dateLibrary>
                        </configOptions>
                        <modelPackage>com.service.model</modelPackage>
                        <environmentVariables>
                            <models/>
                            <supportingFiles>false</supportingFiles>
                        </environmentVariables>
                    </configuration>
                </execution>
            </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

也试过*.json。在任何时候它只需要一个 json 文件并生成代码。

json swagger swagger-codegen

8
推荐指数
1
解决办法
7236
查看次数

如何从vert.x打开Swagger-ui

我想在Vert.X应用程序中实现Swagger-UI.我列出了所有路线,我希望在SpringBoot中像swagger-ui一样看到它们.我也在swagger-editor中手动编辑它们.那么,如何从vert.x app打开localhost:8080/swagger-ui.html并在那里查看所有路由器.

我读到我需要从swagger-editor中保存json并将其放在src/resources中.那之后呢?

我也在这里发现了一个很棒的东西:https://github.com/phiz71/vertx-swaggerhttp://vertx.io/blog/presentation-of-the-vert-x-swagger-project/

但是如何实现呢?

swagger vert.x swagger-ui swagger-editor swagger-codegen

8
推荐指数
1
解决办法
2284
查看次数

有没有办法从C/C++代码生成一个swagger规范文件?

我需要在用C++编写的遗留API接口上创建HTTP API层.我的计划是生成Swagger或开放API文件,然后将其提供给需要编写客户端(将成为新API的使用者)或服务器(旧API的包装器)的一堆项目.

有没有什么可以加快这个要求(除了手动解析它们和创建swagger规范文件)?即使用C++代码生成swagger JSON/YML文件

swagger openapi swagger-codegen openapi-generator

8
推荐指数
1
解决办法
583
查看次数

为什么在我的 gradle 构建过程中会出现元空间错误?

我有时会在我的 gradle 构建过程中遇到元空间错误。

在我的 gradle 配置中,我使用 swagger code-gen 来生成很多类(~40)。我想这可能是问题的来源。

这是build.gradle文件的摘录

dependencies {
    ...
    implementation("io.swagger:swagger-annotations:1.5.10")
    implementation("io.springfox:springfox-swagger2:2.9.2")
    swaggerCodegen("io.swagger.codegen.v3:swagger-codegen-cli:3.0.0")
}
...
swaggerSources {
    doe1 {
        inputFile = file('src/main/resources/wiremock/gfc/yaml/doe-1.yaml')
        code {
            language = 'spring'
            components = ['models']
            additionalProperties = ["modelPackage": "io.swagger.model.doe1", "invokerPackage": "io.swagger.model"]
        }
    }
    doe2 {
        inputFile = file('src/main/resources/wiremock/gfc/yaml/doe-2.yaml')
        code {
            language = 'spring'
            components = ['models']
            additionalProperties = ["modelPackage": "io.swagger.model.doe2", "invokerPackage": "io.swagger.model"]
        }
    }
    ...

    doe40 {
        inputFile = file('src/main/resources/wiremock/gfc/yaml/doe-40.yaml')
        code {
            language = 'spring'
            components = ['models']
            additionalProperties = …
Run Code Online (Sandbox Code Playgroud)

java gradle swagger-codegen

8
推荐指数
1
解决办法
2355
查看次数

代码生成的 Swagger“必需”与“可为空”

我注意到在使用typescript-fetch生成器生成 API 客户端时,生成的接口将所有属性指定为可为空,即使在 swagger/open API 定义中未指定为可为空。此外,将它们设为不可为空的唯一时间是使用required = true.

我还没有发现“必需”和“可空”之间的明确区别,因为它与它应该如何影响代码生成有关,但直观地说,“必需”似乎应该让客户端强制在创建请求时存在一个值,而具有nullable = false(这是默认值)应该在响应对象上生成一个不可为空的属性。

我正在寻找两者之间的明确区别,以便确定 code-gen 在指定字段是否可为空方面是否存在问题。

swagger swagger-codegen

8
推荐指数
0
解决办法
549
查看次数

用于增强类型扩展 Hashmap 的 Dynamodb 属性转换器提供程序

我有一个正在扩展的类型HashMap<String, String>。根据此处的文档,可以为该类型添加自定义转换器。但它似乎不起作用。的内容hashMap不会被转换,输出如下所示;

"summary": {
  "en": null
},
Run Code Online (Sandbox Code Playgroud)

知道如何转换Label及其字段及其哈希图的内容吗?

家长

@DynamoDbBean(converterProviders = {
    CustomAttributeConverterProvider.class,
    DefaultAttributeConverterProvider.class})
public class Summary extends BaseEntry  {

  private @Valid Label summary = null;

}
Run Code Online (Sandbox Code Playgroud)

孩子

@DynamoDbBean(converterProviders = {
    CustomAttributeConverterProvider.class,
    DefaultAttributeConverterProvider.class})
public class Label extends HashMap<String, String>  {
  private @Valid String en = null;
}
Run Code Online (Sandbox Code Playgroud)

HashMap属性转换器

public class HashMapAttributeConverter implements AttributeConverter<Map<String, String>> {
  private static AttributeConverter<Map<String, String>> mapConverter;

  /** Default constructor. */
  public HashMapAttributeConverter() {
    mapConverter =
        MapAttributeConverter.builder(EnhancedType.mapOf(String.class, String.class))
            .mapConstructor(HashMap::new) …
Run Code Online (Sandbox Code Playgroud)

java amazon-dynamodb swagger-codegen

8
推荐指数
1
解决办法
1万
查看次数

如何指定行结束符 (CRLF)

我们使用Swagger Codegen 2.4.5 从我们的 API 生成模型。除了一个相对较小的例外之外,一切都完全按照我们的需要进行。

我们正在生成 C# 模型,并且根据 Windows,这些模型通常以行CRLF结尾存储。每当我们运行生成器时,这些文件都会生成带有行LF结尾的文件。

我们希望所有模型都使用而CRLF不是生成LF。有没有办法改变这种行为?

我研究了 Mustache 的使用方式 -一点- 并通读了 codegen 的常规命令行选项和 csharp 特定选项 ( java -jar swagger-codegen-cli-2.4.5.jar config-help -l csharp),但找不到任何内容。

进一步说明:

目前这是一个问题,因为每次您结帐然后再次运行生成时,模型都会显示为已更改。这只是因为它们现在用行结尾进行编码,而 git 已将它们签出为(我们无法更改)LFCRLF

目前我能想到的唯一其他选择是在生成过程完成后用 CRLF 重写项目中的每个文件。如果有办法通过发电机的话我会更喜欢它。

newline lf swagger-codegen

7
推荐指数
1
解决办法
3589
查看次数

Swagger Codegen basePath 被忽略

我正在尝试使用Swagger Codegen » 2.2.1生成一些 Web 服务定义

所有配置都在工作,并且我的.yaml定义正确生成了类。

为什么该属性basePath被忽略?


@RestController只使用paths定义生成:

https://springboot-base-save-return.appdes.xnet/saveBackendReturn
Run Code Online (Sandbox Code Playgroud)

预期(使用basePathpaths定义):

https://springboot-base-save-return.appdes.xnet/v1/saveBackendReturn
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?我忘记了什么吗?


我的.yaml合同:

swagger: '2.0'
info:
  description: My Project
  version: 1.0.0
  title: Save Backend Return
host: springboot-base-save-return.appdes.xnet
basePath: /v1
tags:
  - name: saveBackendReturn
    description: Save Backend Return
schemes:
  - https
paths:
  /saveBackendReturn:
    post:
      tags:
        - saveBackendReturn
      summary: Save Backend Return
      description: My Project
      operationId: saveBackendReturn
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - …
Run Code Online (Sandbox Code Playgroud)

spring yaml contract-first swagger swagger-codegen

7
推荐指数
1
解决办法
2831
查看次数

Angular 10 Swagger Codegen:通用类型 ModuleWithProviders&lt;T&gt; 需要 1 个类型参数

我正在生成https://editor.swagger.io/ Codegen 代理。它在 Angular 10 中给出了以下错误。如何修复?

通用类型“ModuleWithProviders”需要 1 个类型参数。

export class ApiModule {
    public static forRoot(configurationFactory: () => Configuration): ModuleWithProviders {
        return {
            ngModule: ApiModule,
            providers: [ { provide: Configuration, useFactory: configurationFactory } ]
        };
    }

    constructor( @Optional() @SkipSelf() parentModule: ApiModule,
                 @Optional() http: HttpClient) {
        if (parentModule) {
            throw new Error('ApiModule is already loaded. Import in your base AppModule only.');
        }
        if (!http) {
            throw new Error('You need to import the HttpClientModule in your AppModule! \n' +
            'See also …
Run Code Online (Sandbox Code Playgroud)

swagger typescript swagger-codegen angular angular10

7
推荐指数
1
解决办法
1871
查看次数

如何在 Maven 中将多个 OpenAPI 3.0 规范文件合并为一个?

在使用 Spring Boot 的 Maven 项目中,有多个 OpenAPI 3.0 规范文件。一个规范定义了所有 HTTP 错误 (errors.yml),并且 error.yml 的组件在其他规范中引用。我想生成一个输出规范,其中包含 error.yml 的所有组件。

输入规格:

  schema:
    $ref: "errors.yml#/components/schemas/Error"
Run Code Online (Sandbox Code Playgroud)

期望的输出规格:

schema:
  $ref: "#/components/schemas/Error"
  ...
Error:
  ...
Run Code Online (Sandbox Code Playgroud)

我可以使用 swagger-codegen-cli 来做到这一点:

java -Dfile.encoding=UTF-8 -jar swagger-codegen-cli-3.0.33.jar generate -l openapi-yaml -i search-api-contract/target/expert_api.yml -o . -DoutputFile=search-api-contract/target/expert_api.yml
Run Code Online (Sandbox Code Playgroud)

如何使用 Maven pom.xml 生成一份规范?

maven openapi swagger-codegen swagger-codegen-maven-plugin

7
推荐指数
1
解决办法
8504
查看次数