gradle-swagger-generator-plugin icon indicating copy to clipboard operation
gradle-swagger-generator-plugin copied to clipboard

Error when UI is generated for two sources

Open sharmasourabh opened this issue 6 years ago • 2 comments

Describe the bug

Gives following error when two or more sources are used under swaggerSources while generating UI. It works well for single source.

Caused by:
org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method copy() for arguments [build_f1ze0druuyrt748fg165ca1g2$_run_closure2$_closure18$_closure24$_closure25$_closure26@511a0d5d] on task ':generateSwaggerUISource2' of type org.hidetake.gradle.swagger.generator.GenerateSwaggerUI.

To Reproduce:

Use following code, then generate UI

swaggerSources {
  source1 {
    inputFile = file(<Yaml full path>)
    code {
      language = 'spring'
      configFile = file(<config full path>)
      components = ['models', 'apis']
      dependsOn validation
    }
    ui {
      doLast {
        copy {
          from "index.html"
          into outputDir
        }
      }
    }
  } 
  source2 {
    inputFile = file(<Yaml2 fullpath>)
    code {
      language = 'spring'
      configFile = file(<config2 full path>)
      components = ['apis']
      dependsOn validation
    }
    ui {
      doLast {
        copy {
          from "index.html"
          into outputDir
        }
      }
    }
  }
}

Expected behavior:

Should generate working UI for both sources.

Environment

Plugin version: 2.10.0 (tested with latest 2.18.1 also) Swagger Codegen version: 2.3.1 Gradle version: 4.5.1 Java version: 1.8 OS: Windows 10

sharmasourabh avatar Mar 30 '19 20:03 sharmasourabh

Any workaround to resolve it?

sharmasourabh avatar Apr 10 '19 13:04 sharmasourabh

This seems stale to say the least, but for people coming here from Google, I took the direction of combining multiple files to one before using this plugin.

I opened an issue to suggest the implementation of a $include field which would allow for arbitrary includes of other YAML files.

For now, the workaround I use is an added task to compile the YAML files before using the plugin:

task compileSwaggerSchema(type: Exec) {
  inputs.files 'api.yml', 'index.yml', 'models.yml'
  outputs.file 'documentation/api/schemas/v1/schema.yml'
  workingDir 'documentation/api/schemas/v1'
  commandLine 'bash', '-c', 'npx swagger-cli bundle --outfile schema.yml --type yaml index.yml'
}
generateSwaggerUI.dependsOn compileSwaggerSchema

Example index.yml:

openapi: 3.0.0
paths:
  $ref: "./api.yml"
components:
  schemas:
    $ref: "./models.yml"
# api.yml
/:
  get:
    responses:
      '200':
        description: The authentication process was started successfully.
        content:
          application/json:
            schema:
              $ref: './models.yml#/Response'
     
# models.yml
Response:
  type: object
  properties:
    foo:
      type: string

The workaround requires node and npm. It uses https://github.com/APIDevTools/swagger-cli.

AlexGustafsson avatar Jul 02 '20 11:07 AlexGustafsson