Search code examples
spring-bootopenapiopenapi-generatoropenapi-generator-maven-plugin

OpenApiGenerate is generating model names that i dont specify


I am using openApiGenerate to generate the controller interfaces and model classes. But unfortunately it generates few models that dosent comply with what i provided. It is appending Inner word with some of the request models.

Is there anyway i can specify the name of models that it generates?

I am using the following in gradle -

openApiGenerate {
inputSpec = "$projectDir/openapi.yaml"
generatorName = 'spring'
outputDir = "$buildDir/generated"
apiPackage = 'fi.x.x'
modelPackage = 'fi.x.x.model'
library = 'spring-boot'
configOptions.set([
    interfaceOnly: "true"
])

}

Like for example we have operationId to specify the method name of the controller interfaces. I am looking for similar configurations to customize the model names generated and force not to pick other name than specified.

A modified snapshot of the Api :

paths:
/xyz/v1/con:
post:
  operationId: postCon
  tags:
    - Create Con
  summary: Create Con
  parameters:
      schema:
        type: string
      required: true
  requestBody:
    description: Con body payload
    required: true
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/CreateCon'
  responses:
    '200':
      description: Con created successfully
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/CreateConResponse'

So when i use the openApi generator with spring or java as generators, i get the model created with names like like - CreateConInner etc. Some of the name are however same as specified in schemas block. Also that, i got an interface Api generated and the name is XyzApi (The first word in the api uri.) Is there a way to override this name as well.

As I said, previously, there is operationsId that does a similar task to rename the method name and that works.

Thanks!! Nilotpal


Solution

  • You should provide your openapi file.

    But I assume you specified some models "inline". Thus they don't have a specific name so the generator has to give it one. Use $ref to make sure you declare every object type in your file. Then the generator won't try to guess a name for you it will use the name of the schemas.

    It is not possible to configure the plug in in any way to achieve this. The openapi file has to be modified.