OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.5k stars 6.51k forks source link

[BUG] Vendor extension is empty/ non-existent #14166

Open curcaandrei opened 1 year ago

curcaandrei commented 1 year ago

I'm using OAS3 generator for Java as a Maven plugin to generate POJOs, controllers, delegates etc for my APIs with the Mustache templates from the openapi-generator repository: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/JavaSpring/apiController.mustache

I'm trying to edit this template so that the "@Controller" annotation is generated only if a condition is met. I've searched for multiple solutions for this and one of them was using "vendorExtensions".

I've made the following contract with x-generateController vendorExtension:


openapi: 3.0.0
info:
  title: User API
  description: API for user changes
  contact:
    name: xxx
    url: xxx
    email: xxx
  license:
    name: xxx
    url: xxx
  version: 1.0.0
tags:
  - name: user
x-generateController: True
paths:
  /users:
  ...

And then in the Mustache template file I have put the following:

{{#vendorExtensions.x-generateController}}
@Controller("{{classname}}")
{{/vendorExtensions.x-generateController}}

The generator works just fine without this condition but it seems like it doesn't take into account x-generateController. In fact, if I try to just place it as a comment like this:

// {{vendorExtensions.x-generateController}} I get only "// " and an empty space. I've also tried putting it at the "endpoint level" and not in the "info level" and the problem is the same.

Is there anything more that I should've done in the configuration? Is there any alternative for a condition in the Mustache template?

SauliusTheBlack commented 3 months ago

has there been any evolution on this, it appears that I have the same issue

magiusdarrigo commented 1 week ago

This is still an issue in v7.8.0