Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #6365
Closed
Open
Issue created May 19, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][JAVA] RequestBody examples not set in docs

Created by: alexibz

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Generated examples in docs don't include sample body parameters. For example this is the output generated for the openapi declaration included below in the post:

// Import classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.models.*;
import org.openapitools.client.api.DefaultApi;

public class Example {
    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();
        defaultClient.setBasePath("https://petstore.swagger.io/v2");

        DefaultApi apiInstance = new DefaultApi(defaultClient);
        Pet pet = new Pet(); // Pet | 
        try {
            Pet result = apiInstance.createPet(pet);
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling DefaultApi#createPet");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

The expected output would be to include the example parameters:

Pet pet = new Pet();
pet.setName("MyPet");
pet.setPetType("Cat");
openapi-generator version

Tried with 5.0.0-snapshot and the stable 4.3.1 release.

OpenAPI declaration file content or url
openapi: 3.0.2
info:
  version: 1.0.0
  title: PetStore API
servers:
  - url: https://petstore.swagger.io/v2
    description: PetStore server
paths:
  /pets:
    post:
      summary: Create a Pet
      operationId: createPet
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Pet"

      responses:
        201:
          description: Created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Pet"

components:
  schemas:
    Pet:
      type: object
      properties:
        name:
          type: string
        petType:
          type: string
      required:
        - name
        - petType
      example:
        name: "MyPet"
        petType: "Cat"
Command line used for generation
java -DhideGenerationTimestamp=true -jar ./scripts/openapi-generator-cli.jar generate \
    -i ./openapi/openapi.yaml \
    -g java \
    --library resteasy \
    -o ./clients/swagger-java \
    -c ./scripts/config.json
Steps to reproduce
  1. Add an example directive to a RequestBody or to any other object defining example values.
  2. Observe the docs, for example, DefaultApi.md will not have the example value set in the RequestBody Object. It will only work for primitives.
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/6324

Assignee
Assign to
Time tracking