micronaut-openapi
micronaut-openapi copied to clipboard
javadoc for record components not read
Expected Behavior
Should read javadoc comments from @param
tags of records:
/**
*
* @param name The name of the pet
* @author gkrocher
*/
@Serdeable
public record Pet(
@NotBlank
@Size(max = 200)
String name) {}
Actual Behaviour
Doesn't read the javadoc
Steps To Reproduce
No response
Environment Information
No response
Example Application
No response
Version
3.7.1
@graemerocher Need full example for it. I already wrote test for records:
void "test read javadoc from class level for records"() {
given:
when:
buildBeanDefinition('test.MyBean', '''
package test;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
@Controller
class PersonController {
@Get("/person")
Person getPerson() {
return new Person("John", 42);
}
}
/**
* The Person class description
*
* @param name this is persons name
* @param age this is persons age
*
* @return new instance of Person class
*/
record Person(@Nullable String name, Integer age) {}
@jakarta.inject.Singleton
class MyBean {}
''')
then:
Utils.testReference != null
when:
OpenAPI openAPI = Utils.testReference
then:
openAPI.components.schemas
openAPI.components.schemas.size() == 1
Schema personSchema = openAPI.components.schemas['Person']
personSchema.name == 'Person'
personSchema.type == 'object'
personSchema.description == 'The Person class description'
personSchema.properties.name.type == 'string'
personSchema.properties.name.description == 'this is persons name'
personSchema.properties.age.type == 'integer'
personSchema.properties.age.description == 'this is persons age'
personSchema.required
personSchema.required.size() == 1
personSchema.required.contains('age')
}
And now I wrote another test for your case - it works too:
void "test read javadoc from class level for records - 2"() {
given:
when:
buildBeanDefinition('test.MyBean', '''
package test;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.serde.annotation.Serdeable;
@Controller
class PetController {
@Get("/pet")
Pet getPet() {
return new Pet("John");
}
}
/**
*
* @param name The name of the pet
* @author gkrocher
*/
@Serdeable
record Pet(
@NotBlank
@Size(max = 200)
String name) {}
@jakarta.inject.Singleton
class MyBean {}
''')
then:
Utils.testReference != null
when:
OpenAPI openAPI = Utils.testReference
then:
openAPI.components.schemas
openAPI.components.schemas.size() == 1
Schema petchema = openAPI.components.schemas['Pet']
petchema.name == 'Pet'
petchema.type == 'object'
petchema.description == null
petchema.properties.name.type == 'string'
petchema.properties.name.description == 'The name of the pet'
petchema.required
petchema.required.size() == 1
petchema.required.contains('name')
}
@graemerocher Checked this on sample project - all works fine:
Controller:
@Controller
public class TestController {
@Get
public Pet test() {
return null;
}
}
DTO:
/**
* @param name The name of the pet
* @author gkrocher
*/
@Serdeable
public record Pet(
@NotBlank
@Size(max = 200)
String name) {
}
Generated yml:
openapi: 3.0.1
info:
title: mn-schema-override-exemplar
version: "0.0"
paths:
/:
get:
operationId: test
responses:
"200":
description: test 200 response
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
components:
schemas:
Pet:
required:
- name
type: object
properties:
name:
maxLength: 200
minLength: 1
type: string
description: The name of the pet
Maybe something got cached, try clearing the build and restarting it with org.gradle.caching = false
If the problem persists, then you need a full-fledged example to reproduce, because I can't reproduce the problem locally
@graemerocher ping you about this issue. I still can't reproduce your problem. Could you give me sample app ?
let me try reproduce
ok seems to work, closing. Thanks!