Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对于Swagger字典类型(Java codegen),是否使用LinkedHashMap而不是HashMap?_Java_Swagger_Openapi_Swagger Codegen - Fatal编程技术网

对于Swagger字典类型(Java codegen),是否使用LinkedHashMap而不是HashMap?

对于Swagger字典类型(Java codegen),是否使用LinkedHashMap而不是HashMap?,java,swagger,openapi,swagger-codegen,Java,Swagger,Openapi,Swagger Codegen,我正在使用openapi 3.0.2和codegen插件: <groupId>io.swagger.codegen.v3</groupId> <artifactId>swagger-codegen-maven-plugin</artifactId> <version>3.0.14</version> 当我为此生成Java代码时,它被建模为一个类,扩展了HashMap: @ApiModel(description = "A

我正在使用openapi 3.0.2和codegen插件:

<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.14</version>
当我为此生成Java代码时,它被建模为一个类,扩展了
HashMap

@ApiModel(description = "A description.")
@Validated
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2020-02-26T12:17:36.248Z[Europe/London]")
public class Labels extends HashMap<String, String>  {
...
}
@ApiModel(description=“A description.”)
@验证
@javax.annotation.Generated(value=“io.swagger.codegen.v3.generators.java.SpringCodegen”,date=“2020-02-26T12:17:36.248Z[欧洲/伦敦]”)
公共类标签扩展HashMap{
...
}
是否有任何方法可以指示swagger使用
LinkedHashMap
而不是
HashMap
?(无需将此类从codegen中排除并手动修改)


我想在将词典返回给客户端时控制词典中条目的顺序。

我使用maven插件修改生成的文件:

<plugin>
        <groupId>org.codehaus.gmavenplus</groupId>
        <artifactId>gmavenplus-plugin</artifactId>
        <executions>
                <execution>
                        <id>modify-swagger</id>
                        <phase>generate-sources</phase>
                        <goals>
                                <goal>execute</goal>
                        </goals>
                        <configuration>
                                <properties>
                                        <property>
                                                <name>targetDir</name>
                                                <value>${project.build.directory}</value>
                                        </property>
                                </properties>
                                <scripts>
                                        <script><![CDATA[
                                                def labelsFile = new File(targetDir
                                                                + "/swagger-codegen/src/main/java/com/acme/models/Labels.java")
                                                def labelsFileContents = labelsFile.text
                                                if (labelsFileContents == null) {
                                                        throw Exception();
                                                }

                                                def newLabelsFileContents = labelsFileContents.replaceAll('HashMap', 'LinkedHashMap')
                                                labelsFile.write(newLabelsFileContents)
                                        ]]></script>
                                </scripts>
                        </configuration>
                </execution>
        </executions>
</plugin>

org.codehaus.gmavenplus
gmavenplus插件
矫揉造作
生成源
执行
targetDir
${project.build.directory}

似乎这个问题已经解决了,这将使
LinkedHashMap
成为默认实现感谢@Lino,我确实看到了这一点,但我现在尝试为几种不同的类型(spring、jaxrs cs等)生成服务器代码,它们都生成了一个扩展HashMap的类
<plugin>
        <groupId>org.codehaus.gmavenplus</groupId>
        <artifactId>gmavenplus-plugin</artifactId>
        <executions>
                <execution>
                        <id>modify-swagger</id>
                        <phase>generate-sources</phase>
                        <goals>
                                <goal>execute</goal>
                        </goals>
                        <configuration>
                                <properties>
                                        <property>
                                                <name>targetDir</name>
                                                <value>${project.build.directory}</value>
                                        </property>
                                </properties>
                                <scripts>
                                        <script><![CDATA[
                                                def labelsFile = new File(targetDir
                                                                + "/swagger-codegen/src/main/java/com/acme/models/Labels.java")
                                                def labelsFileContents = labelsFile.text
                                                if (labelsFileContents == null) {
                                                        throw Exception();
                                                }

                                                def newLabelsFileContents = labelsFileContents.replaceAll('HashMap', 'LinkedHashMap')
                                                labelsFile.write(newLabelsFileContents)
                                        ]]></script>
                                </scripts>
                        </configuration>
                </execution>
        </executions>
</plugin>