[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
- Add an
example
directive to aRequestBody
or to any other object defining example values. - 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