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
  • #828
Closed
Open
Issue created Aug 17, 2018 by Administrator@rootContributor

[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.

Assignee
Assign to
Time tracking