Repository navigation
Open
Labels
Description
Bug Report Checklist
- [x ] Have you provided a full/minimal spec to reproduce the issue?
- [ x] Have you validated the input using an OpenAPI validator (example)?
- [ x] Have you tested with the latest master to confirm the issue still exists?
- [ x] Have you searched for related issues/PRs?
- [ x] What's the actual output vs expected output?
- [- ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Code generation for spring server does not generate default value for array of primitive type (for array of complex type it is complicated, probably impossible)
Example below:
openapi: '3.0.2'
info:
title: Search API
version: '1.0'
servers:
- url: http://localhost:8080/api/v1
tags:
- name: "search"
paths:
/search:
get:
tags:
- search
description: ""
operationId: "search"
parameters:
- in: query
name: p
description: Page
schema:
type: integer
default: 0
minimum: 0
- in: query
name: orderBy
description: Filter by status not equal (AND condition applied)
schema:
type: array
default: ["updatedAt:DESC", "createdAt:DESC"]
items:
type: string
enum: [ "createdAt:ASC", "createdAt:DESC",
"updatedAt:ASC", "updatedAt:DESC" ]
responses:
204:
description: "Custom response"
Generated:
@Operation(
operationId = "search",
tags = { "search" },
responses = {
@ApiResponse(responseCode = "204", description = "Custom response")
}
)
@RequestMapping(
method = RequestMethod.GET,
value = "/search"
)
default ResponseEntity<Void> search(
@Min(0) @Parameter(name = "p", description = "Page") @Valid @RequestParam(value = "p", required = false, defaultValue = "0") Integer p,
@Parameter(name = "orderBy", description = "Filter by status not equal (AND condition applied)") @Valid @RequestParam(value = "orderBy", required = false) List<String> orderBy
) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
Expected something like: (as said here):
default ResponseEntity<Void> search(
@Min(0) @Parameter(name = "p", description = "Page") @Valid @RequestParam(value = "p", required = false, defaultValue = "0") Integer p,
@Parameter(name = "orderBy", description = "Filter by status not equal (AND condition applied)") @Valid @RequestParam(value = "orderBy", required = false, defaultValue = "updatedAt:DESC,createdAt:DESC") List<String> orderBy
) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
Activity
mbaroody commentedon Mar 26, 2022
Having a similar issue with
default: []. Expecting@RequestParam(value = "orderBy", required = false, defaultValue = ""), which would serialize to an emptyList.borsch commentedon Mar 29, 2022
@humbleCraftman @mbaroody PR with required change has been merged to master. Feel free to build/get latest openapi-generator and use
humbleCraftman commentedon Mar 29, 2022
Thanks for the reactivity
elliebas commentedon Mar 27, 2023
Hi, would it be possible to fix it for a Kotlin code generator as well? Thanks
gorjan-mishevski commentedon Dec 27, 2023
+1 for the Kotlin generation.