[kotlin-server] Paths.kt does not contain post-operations
Created by: gfelbing
Description
When generating a kotlin-server, the generated Paths.kt does not contain locations for post-operations.
Swagger-codegen version
2.3.1
Swagger declaration file content or url
swagger: "2.0"
host: "0.0.0.0"
info:
title: "Kotlin Demo"
description: "This is a Kotlin Swagger Demo"
version: "0.0.1"
basePath: "/v1"
paths:
/user/{userId}:
get:
operationId: "getUser"
produces:
- "application/json"
responses:
200:
description: "Success."
schema:
$ref: '#/definitions/IdentifiableUser'
parameters:
- name: "userId"
in: "path"
required: true
type: "integer"
/user:
post:
operationId: "postUser"
produces:
- "application/json"
parameters:
- in: "body"
name: "body"
required: true
schema:
$ref: "#/definitions/User"
responses:
202:
description: "Success"
400:
description: "Invalid User."
definitions:
Identifiable:
type: "object"
required:
- "id"
properties:
id:
type: "integer"
User:
type: "object"
required:
- "name"
- "type"
properties:
name:
type: "string"
type:
type: "string"
enum: ["user", "moderator"]
info:
type: "string"
IdentifiableUser:
type: "object"
allOf:
- $ref: "#/definitions/Identifiable"
- $ref: "#/definitions/User"
Results in:
/**
* Kotlin Demo
* This is a Kotlin Swagger Demo
*
* OpenAPI spec version: 0.0.1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.server
import io.ktor.application.ApplicationCall
import io.ktor.http.HttpMethod
import io.ktor.locations.*
import io.ktor.pipeline.PipelineContext
import io.ktor.routing.Route
import io.ktor.routing.method
import org.openapitools.server.models.*
// NOTE: ktor-location@0.9.0 is missing extension for Route.delete. This includes it.
inline fun <reified T : Any> Route.delete(noinline body: suspend PipelineContext<Unit, ApplicationCall>.(T) -> Unit): Route {
return location(T::class) {
method(HttpMethod.Delete) {
handle(body)
}
}
}
object Paths {
/**
*
*
* @param userId
*/
@Location("/user/{userId}") class getUser(val userId: kotlin.Int)
}
Command line used for generation
openapi-codegen generate -g kotlin-server -i path/to/swagger.yaml -Dmodels -Dapis -DsupportingFiles=Paths.kt
Steps to reproduce
Generate the code using the config mentioned above.
Suggest a fix/enhancement
The template Paths.kt.mustache
contains a check for bodyAllowed:
object Paths {
{{#apis}}
{{#operations}}
{{#operation}}
{{^bodyAllowed}}
/**
* {{summary}}
* {{#unescapedNotes}}{{.}}{{/unescapedNotes}}
{{#allParams}}* @param {{paramName}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
{{/allParams}}*/
@Location("{{path}}") class {{operationId}}({{#allParams}}val {{paramName}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
{{/bodyAllowed}}
{{/operation}}
{{/operations}}
{{/apis}}
}
Blindly removing it results in a NullPointerException.