Issue
I've been learning recently about openapi generator and I wanted to generate a simple api using it, but after setting everything up and running the generator, it works mostly fine but all the types for my functions, entities and more are of type "kotlin.Any"
I am using Maven and this is the configuration for my plugin
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- RELEASE_VERSION -->
<version>6.6.0</version>
<!-- /RELEASE_VERSION -->
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/openapi.yaml</inputSpec>
<generatorName>kotlin-spring</generatorName>
<configOptions>
<sourceFolder>src/gen/kotlin/main</sourceFolder>
<interfaceOnly>true</interfaceOnly>
<useSpringBoot3>true</useSpringBoot3>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
this is my autogenerated /users
endpoint:
@Operation(
summary = "Get user information",
operationId = "usersGet",
description = """This endpoint requires a valid bearer token""",
responses = [
ApiResponse(responseCode = "200", description = "OK", content = [Content(schema = Schema(implementation = kotlin.Any::class))]),
ApiResponse(responseCode = "401", description = "")
],
security = [ SecurityRequirement(name = "BearerAuth") ]
)
@RequestMapping(
method = [RequestMethod.GET],
value = ["/users"],
produces = ["application/json"]
)
fun usersGet(): ResponseEntity<kotlin.Any> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}
this is how I declared my /users
endpoing inside my .yaml file:
/users:
get:
summary: Get user information
description: This endpoint requires a valid bearer token
security:
- BearerAuth: []
responses:
"200":
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/UserResponse'
"401":
$ref: '#/components/responses/Unauthorized'
tags:
- user
and this is the model for UserResponse
:
UserResponse:
example:
lastName: Doe
name: Jhon
id: 1
email: [email protected]
token: fkljasdhf9fjkfh23fhkhiafo9
properties:
id:
description: "Auto generated by the api, not required for any transaction"
example: 1
type: integer
email:
example: [email protected]
type: string
name:
example: Jhon
type: string
lastName:
example: Doe
type: string
token:
description: Auto generated by the api once you create a user or login with
valid credentials
example: fkljasdhf9fjkfh23fhkhiafo9
type: string
Is there something I am missing?
Solution
After some research, it looks like this problem is caused by the version of openapi generator. In my case I was using version 6.6.0 which seems to have a bug that provokes none of the classes to have the correct types. After updating to the latest current version (7.2.0) it works perfectly fine.
Answered By - Lordkaito
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.