question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OAS 3 paramType = "body" not working. springfox-boot-starter:3.0.0

See original GitHub issue
@PostMapping("/create")
    @HystrixCommand(commandKey = "Create project")
    @ResponseStatus(HttpStatus.CREATED)
    @ApiOperation(notes = "Создаёт папки проекта на Dropbox и регистрирует в хранилище", value = "Создать проект", consumes = "application/json", tags = {"project", })
    @ApiResponses(
            value = {
                    @ApiResponse(code = 201, message = "Операция выполнена успешна."),
                    @ApiResponse(code = 409, message = "Папки проекта уже существуют. Не удалось создать."),
                    @ApiResponse(code = 403, message = "Ошибка авторизации."),
                    @ApiResponse(code = 404, message = "Запрошенный ресурс не существует."),
            })
    @ApiImplicitParams(
            value = {
                @ApiImplicitParam(name = "body", paramType = "body", dataTypeClass = ProjectName.class, required = true, value = "JSON объект с именем проекта и его транслитом на аглийский."),
                @ApiImplicitParam(name = "temp", paramType = "query", dataTypeClass = Long.class, required = true, value = "temp")
            })
    public ResponseEntity<Void> createProject(@RequestBody ProjectName projectName) {
        return ResponseEntity
                .status(service.createProject(projectName))
                .build();
    }

generated output

"parameters": [
          {
            "name": "temp",
            "in": "query",
            "description": "temp",
            "required": true,
            "style": "form",
            "allowReserved": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProjectName"
              }
            }
          }
        }

if i change type from body to query that working. But i need in:"body"

@ApiImplicitParams(
            value = {
                @ApiImplicitParam(name = "body", paramType = "query", dataTypeClass = ProjectName.class, required = true, value = "JSON объект с именем проекта и его транслитом на аглийский."),
                @ApiImplicitParam(name = "temp", paramType = "query", dataTypeClass = Long.class, required = true, value = "temp")
            })
"parameters": [
          {
            "name": "body",
            "in": "query",
            "description": "JSON объект с именем проекта и его транслитом на аглийский.",
            "required": true,
            "style": "form",
            "allowReserved": true,
            "schema": {
              "$ref": "#/components/schemas/ProjectName"
            }
          },
          {
            "name": "temp",
            "in": "query",
            "description": "temp",
            "required": true,
            "style": "form",
            "allowReserved": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProjectName"
              }
            }
          }
        },

bean

    @Bean
    public Docket openApi(TypeResolver typeResolver){
        return new Docket(DocumentationType.OAS_30)
                .useDefaultResponseMessages(false)
                .securityContexts(Lists.newArrayList(securityContext()))
                .securitySchemes(Lists.newArrayList(apiKey()))
                .select()
                .apis(RequestHandlerSelectors.basePackage("ru.trmedia.trportal.admin.web.rest"))
                .build()
                .additionalModels(
                        typeResolver.resolve(ProjectName.class)
                )
                .apiInfo(new ApiInfoBuilder().version("1.0").title("Admin API").description("Documentation Admin API v1.0").build())
                .tags(
                        new Tag("project", "Операции с проектом")
                );
    }

model ( if i change model class to Long, still not working)

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(description = "Имя проекта и его транслит на английский", value = "ProjectName")
public class ProjectName {
    @ApiModelProperty(value = "имя проекта на латиннице, прим.: Магнит")
    private String projectName;
    @ApiModelProperty(value = "имя проекта на латиннице, прим.: Magnet")
    private String projectNameTranslit;
}

maven

<dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.plugin</groupId>
            <artifactId>spring-plugin-core</artifactId>
            <version>2.0.0.RELEASE</version>
        </dependency>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
andermirikcommented, Feb 1, 2021
@ApiImplicitParam(name = "body", paramType = "body", dataType="ProjectName", dataTypeClass = ProjectName.class, required = true, value = "JSON объект с именем проекта и его транслитом на аглийский."),
@ApiImplicitParam(name = "temp", paramType = "query", dataTypeClass = Long.class, required = true, value = "temp")

"parameters": [
          {
            "name": "temp",
            "in": "query",
            "description": "temp",
            "required": true,
            "style": "form",
            "allowReserved": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
``
2reactions
namila007commented, Feb 1, 2021

try adding “dataType=ProjectName”

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found