简体   繁体   English

openapi-generator 不生成 model

[英]openapi-generator not generating model

I am using the openapi-generator to create a multipart/form-data.我正在使用 openapi-generator 来创建多部分/表单数据。 In an ideal situation I should be able to upload a file, and specify in the options what should happen with the file.在理想情况下,我应该能够上传文件,并在选项中指定文件应该发生什么。

I would like the options to be an object. For one or another reason, this does not seem to work.我希望选项为 object。出于某种原因,这似乎不起作用。 The openapi-generator generates the API interface, etc, but it does not generate the model for the options object. openapi-generator 生成 API 接口等,但它不会为选项 object 生成 model。

I can specify the options individually, but I prefer the options to be an object, with the necessary model to it.我可以单独指定选项,但我更喜欢选项是 object,以及必要的 model。 I believe this provides a more structured way to deal with the options.我相信这提供了一种更有条理的方式来处理选项。

My yaml file looks like this (I specified what works and what doesn't work):我的 yaml 文件如下所示(我指定了哪些有效,哪些无效):

  /fileuploadwithoptions:
    post:
      summary: Upload a file and processes it according to the options specified.
      requestBody:
        content:
          multipart/form-data:
            schema:
              required:
                - file
              type: object
              properties:
                file:
                  type: string
                  format: binary
                option1:  <-- this works
                  type: string
                  description: A descriptions for option 1.
                options: <-- this does not work
                  #type: application/json
                  type: object
                  description: The options.
                  properties:
                    option1:
                      type: string
                      description: A descriptions for option 1.
                    option2:
                      type: string
                      description: A descriptions for option 2.
            encoding:
              file:
                contentType: application/octet-stream

This generates the following API:这会生成以下 API:

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (6.0.1).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */
package com.teradact.tokenizerplusserver.api;

import com.teradact.tokenizerplusserver.model.FileuploadwithoptionsPostRequestOptions;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import javax.validation.constraints.*;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.annotation.Generated;

@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2022-10-11T08:11:04.909499+02:00[Europe/Brussels]")
@Validated
@Tag(name = "fileuploadwithoptions", description = "the fileuploadwithoptions API")
public interface FileuploadwithoptionsApi {

    default Optional<NativeWebRequest> getRequest() {
        return Optional.empty();
    }

    /**
     * POST /fileuploadwithoptions : Upload a file and processes it according to the options specified.
     *
     * @param file  (required)
     * @param option1 A descriptions for option 1. (optional)
     * @param options  (optional)
     * @return The file. (status code 200)
     *         or bad input parameter (status code 400)
     */
    @Operation(
        operationId = "fileuploadwithoptionsPost",
        summary = "Upload a file and processes it according to the options specified.",
        responses = {
            @ApiResponse(responseCode = "200", description = "The processed file.", content = {
                @Content(mediaType = "application/octet-stream", schema = @Schema(implementation = org.springframework.core.io.Resource.class))
            }),
            @ApiResponse(responseCode = "400", description = "bad input parameter")
        }
    )
    @RequestMapping(
        method = RequestMethod.POST,
        value = "/fileuploadwithoptions",
        produces = { "application/octet-stream" },
        consumes = { "multipart/form-data" }
    )
    default ResponseEntity<org.springframework.core.io.Resource> fileuploadwithoptionsPost(
        @Parameter(name = "file", description = "", required = true) @RequestPart(value = "file", required = true) MultipartFile file,
        @Parameter(name = "option1", description = "A descriptions for option 1.") @Valid @RequestParam(value = "option1", required = false) String option1,
        @Parameter(name = "options", description = "") @Valid @RequestParam(value = "options", required = false) FileuploadwithoptionsPostRequestOptions options
    ) {
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);

    }

}

This gives however the following error:然而,这给出了以下错误:

"Cannot resolve symbol 'FileuploadwithoptionsPostRequestOptions", since the model for the object is simply not created. “无法解析符号‘FileuploadwithoptionsPostRequestOptions’”,因为根本没有创建 object 的 model。

Thanks in advance for pointing out where I am wrong!在此先感谢您指出我错在哪里!

The interface has the name 'FileuploadwithoptionsApi', YAML file has /fileuploadwithoptions and the response entity has name fileuploadwithoptionsPost but the RequestParam has object 'FileuploadwithoptionsPostRequestOptions' is it because of this it cannot resolve the symbol.该接口的名称为“FileuploadwithoptionsApi”,YAML 文件具有 /fileuploadwithoptions,响应实体的名称为 fileuploadwithoptionsPost,但 RequestParam 具有 object“FileuploadwithoptionsPostRequestOptions”,因此它无法解析符号。

@Parameter(name = "options", description = "") @Valid @RequestParam(value = "options", required = false) FileuploadwithoptionsPostRequestOptions options)

Is the object 'FileuploadwithoptionsPostRequestOptions' instantiated or does it have a similar class or interface matching the object present in @Request Param. object 'FileuploadwithoptionsPostRequestOptions' 是否已实例化,或者它是否具有类似的 class 或与@Request Param 中存在的 object 相匹配的接口。

Ok, you have imported the required class for the object try using @RequestPart as you have used for file.好的,您已经为 object 导入了所需的 class,尝试使用 @RequestPart,就像您用于文件一样。 Try if it works.试试看是否有效。

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

相关问题 是否可以检查 returnType 是否是 OpenApi-Generator 中的文件? - Is it possible to check if returnType is a file in the OpenApi-Generator? 为什么 openapi-generator 生成的文件会被忽略? - Why are the openapi-generator generated files ignored? openapi-generator gradle 插件 output 目录 - openapi-generator gradle plugin output directory openapi-generator /maven 插件生成带有 «, » 字符的无效 java 代码 - openapi-generator /maven plugin generates invalid java code with «, » characters 如何在 gradle java 应用程序中包含来自 openapi-generator 的客户端? - How to include the client from openapi-generator in a gradle java application? 有没有办法配置 openapi-generator 在生成期间使用 jakarta 包 - Is there a way to configure openapi-generator to use jakarta package during generation 为什么 openapi-generator 使用不存在的导入 - Why does openapi-generator use imports that do not exist 带有 spring-boot 的 openapi-generator,删除生成的值 - openapi-generator with spring-boot, remove generated values OpenAPI Generator - Java Client 生成与 Spring Server 不同的模型 - OpenAPI Generator - Java Client generating different model than Spring Server 如何防止 openapi-generator 在 java 中使用通配符导入 - How to prevent openapi-generator from using wildcard imports in java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM