Forum Discussion

rickla's avatar
rickla
New Contributor
3 years ago

Generating arrays with types, online vs gradle

I have been wrestling with calling the generator in gradle, and I am calling the version 3.0.26, however...

the https://editor.swagger.io client generating java does what I need, but in gradle it doesn't! I can't find out what version of the generator the online does or what settings it uses to generate java.

 

Because the online tool generates code I can use but when I call it in gradle not so much:

 

The snippet of the yaml is at the end. this happens with any 'array' in online, which is good. It makes an array with typed objects, and the RoomInner is where values are set

public class Room extends ArrayList<RoomInner> {

 

However in any attempt in gradle calling the 3.0.26 it's never typed

public class Room extends ArrayList<Object> {

And no such inner class is made, so there's no way to set those elements etc.

 

Banging my head against this wall. 

 

 

 

 

 

Rooms:
required:
- Room
properties:
Room:
$ref: '#/components/schemas/Room'
description: Contains room parameters to search by.
Room:
minItems: 1
type: array
description: Lists room information.
items:
required:
- Adults
- Index
type: object
properties:
Index:
minimum: 1
type: integer
description: Specifies the index number of the room. Room Index must be in order if multiple rooms are specified in the request. All rooms must have the exact same Adult and Child guest count.
example: 1
Adults:
minimum: 1
type: integer
description: Specifies the number of adults to stay in the room.
example: 1

 

3 Replies

  • Hi rickla 

     

    Small differences like that can make for a frustrating experience, I can empathize! 

    Could you share you gradle config related to this? And what gradle plugin are you using?

    • rickla's avatar
      rickla
      New Contributor

      Sure, here are parts of my messy config, so it's not as if it will run, but I am not setting many options just packages etc. It's basically pasted from google examples I found just to get it running.

       

      classpath("io.swagger.codegen.v3:swagger-codegen-maven-plugin:3.0.27")
                          def openAPI = new OpenAPIV3Parser().read(file.absolutePath, null, null)
      def clientOpts = new ClientOptInput().openAPI(openAPI)

      def config = CodegenConfigLoader.forName('java')
      clientOpts.setConfig(config);
      config.setApiPackage(schema.pkg)
      config.setModelPackage(schema.pkg)
      config.setOutputDir(generatedSourceDir)
      def moreClientOpts = new ClientOpts()
      moreClientOpts.setProperties([
      'dateLibrary' : 'java8', // Date library to use
      'apiPackage' : schema.pkg,
      'modelPackage' : schema.pkg
      ])
      clientOpts.setOpts(moreClientOpts)
      println("generating")
      println file.absolutePath;
      config.setInputSpec(file.absolutePath)
      println("generating call")
      new DefaultGenerator().opts(clientOpts).generate() // Executing the generation
      println("generating done")

       

    • rickla's avatar
      rickla
      New Contributor

      I did find a way to make it work using the cli class instead (not sure why really). 

       

      However I found that oneOf apparently doesn't work so using the generator is probably dead.