简体   繁体   English

如何仅从 SpringBoot 中的 Open Api 生成 model 类?

[英]How to generate model classes only from Open Api in SpringBoot?

For example this is my open api例如这是我打开的 api

openapi: "3.0.0"
paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets
      tags:
        - pets
      parameters:
        - name: limit
          in: query
          ...
      responses:
        ...
    post:
      summary: Create a pet
      operationId: createPets
      ...
  /pets/{petId}:
    get:
      summary: Info for a specific pet
      operationId: showPetById
      ...
components:
  schemas:
    Pet:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string

and I want to generate only model classes not apis and other things in the com.service.model package of src/main/java instead of target folder in springboot. and I want to generate only model classes not apis and other things in the com.service.model package of src/main/java instead of target folder in springboot. What is the configuration needed in the pom.xml file? pom.xml 文件中需要什么配置?

I think that the generated sources should always be created in the target folder and not in your source code folder.我认为生成的源代码应该始终在目标文件夹中创建,而不是在您的源代码文件夹中。 Besides that, all the code (generated or your own) will eventually be on the same classpath.除此之外,所有代码(生成的或您自己的)最终都将位于同一类路径中。

But if you insist of changing the default location (target/generated-sources) you can add something like this to your swagger-codegen configuration in your pom.xml: <output>src/main/java</output>但是,如果您坚持更改默认位置(目标/生成源),您可以在 pom.xml 中将类似的内容添加到您的 swagger-codegen 配置中: <output>src/main/java</output>

To generate only the Model code you can add these tags to your codegen configuration:要仅生成 Model 代码,您可以将这些标签添加到您的代码生成配置中:

<plugin>
  <artifactId>swagger-codegen-maven-plugin</artifactId>
  <executions>
    <execution>
      <configuration>                            
        <generateApis>false</generateApis>
        <generateModelDocumentation>false</generateModelDocumentation>
        <generateSupportingFiles>false</generateSupportingFiles>
      </configuration>
    </execution>
  </executions>
</plugin>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从现有的猎鹰 api 生成 Open API 规范? - How to generate Open API specification from existing falcon api? 从 WSDL/XML 以编程方式生成 Swagger YAML Open API 规范 - Generate Swagger YAML Open API Spec programmatically from WSDL/XML 如何使用具有构造函数的开放式api生成器生成类模型? - How to generate class models with an open api generator that have a constructor? 打开api 3.0 java代码生成器 - 如何生成实例化列表? - Open api 3.0 java code generator - How to generate instantiated lists? 如何仅为我的模型生成标准定义文件 - How can I generate a swagger definition file only for my model 如何从不同的模块生成客户端 api - How to generate client api from different module 如何使用 openapi-generator-maven-plugin/swagger 生成没有注释的 java model 类? - How to generate java model classes without annotations using openapi-generator-maven-plugin/ swagger? 如何从 OpenAPI/Swagger 模型定义生成 JSON 示例? - How to generate JSON examples from OpenAPI/Swagger model definition? 如何生成swagger文件到azure Java 没有springboot的功能 - How to generate swagger file to azure Java Functions without springboot Open API:从 yaml 文件生成属性模式 JSON 以在 UI 上添加验证 - Open API : Generate properties schema JSON from yaml file for adding validation on UI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM