swagger-api / swagger-api/swagger-codegen

[JAVA] Error generating boolean default value

Open
#8,711 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Hi,

I'm trying to define a default value for a boolean in query but the flag is not generated.

Actually, I use version : 3.0.0-20180714.172900-89

My yml file :

openapi: 3.0.1
info:
version: 1.0.0
title: API
servers:

  • url: http://api/v1/mof
    tags:
  • name: periodes
    description: Services
    paths:
    /periodes:
    parameters:
    • $ref: '#/components/parameters/Uai'
      get:
      parameters:
      • $ref: '#/components/parameters/UniquementValide'
        tags:
      • periodes
        summary: Liste
        operationId: lireListe
        responses:
        200:...

.... -> At the end of the file
components:
schemas:
....(no details)
parameters:
UniquementValide:
name: uniquementValide
in: query
description: Paramètre optionnel qui spécifie si le service ne doit ramener
que les éléments valides
schema:
type: boolean
default: 'true'
required: false

For Java client, the generated function is :

default ResponseEntity<List<Periode lireListe(
@NotNull @ApiParam(value = "L'UAI de l'établissement", required = true) @Valid @RequestParam(value = "uai", required = true) String uai,
@ApiParam(value = "Paramètre optionnel qui spécifie si le service ne doit ramener que les éléments valides") @Valid @RequestParam(value = "uniquementValide", required = false) Boolean uniquementValide) {
.....
}

Previously, using v.2.x I have the default value like this :

default ResponseEntity<List<Periode lireListe(
@NotNull @ApiParam(value = "L'UAI de l'établissement", required = true) @Valid @RequestParam(value = "uai", required = true) String uai,
@ApiParam(value = "Paramètre optionnel qui spécifie si le service ne doit ramener que les éléments valides") @Valid @RequestParam(value = "uniquementValide", required = false, defaultValue="true") Boolean uniquementValide) {
....
}

Best regards,
Nicolas

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided OpenAPI YAML and the generated Java client method, focusing on the uniquementValide query parameter and its boolean default. Compare the generated signature with the v2.x example; done means default: 'true' produces defaultValue="true" in the Java annotation.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.