Skip to content

Evaluate OpenAPI tooling #25

Description

@pvdbosch

In GitLab by @pvdbosch on Sep 7, 2018, 16:25

  1. Test senya.io, stoplight.io, apicurio or any other interesting tool to author swagger files.

  2. Evaluate code generation maven plugins: openapi-generator vs swagger codegen.
    Recommend one?

Comparison (WIP):

Swagger codegen:

  • specifying explicitely additionalProperties: true was required to let generated Java classes support additional properties not specified in the Swagger file (untested on openapi-generator)
    • even with this specified, the generated code didn't work properly
  • when generating fat swagger, creates top level types for inlined (non-Venetian-blind) types. It shouldn't. The generated types don't follow styleguide naming convention. (untested on openapi-generator)
  • generated code's formatting a bit better
  • invalid escaping for regexp: @Pattern(regexp="\d{11}") => doesn't compile, should be @Pattern(regexp="\\d{11}") (tested with v3 of codegen)

openapi-generator:

  • more actively developed
  • unnecessary java imports, bad formatting in generated code - maybe fixable with some tuning
  • additionalProperties: true has no effect
  • 4.x use of allOf:
    • generate useless *AllOf classes for Swagger types inlined in an allOf composition. They are imported in the composite class but not used
    • no inheritance in generated code anymore when using allOf with a referenced type: e.g. InvalidParamProblem no longer extends Problem (see [BUG] [Java] inheritance is generated without discriminator field OpenAPITools/openapi-generator#5097 (comment))
    • workaround for both: only specify base class in allOf and specify properties on same level like this:
      MyType: { allOf: [$ref: '#/components/schemas/T'], properties: { x: {type: string}} }
  • converts format: uri to java.net.URI as of 4.1.0
  • In 4.3.1: inline object types become java.lang.Object instead of proper generated type. Workaround: make them explicit (non-inline) types

Other notes:

  • specifying an array of types, while valid JSON Schema, doesn't seem to be supported in OpenAPI
  • format: decimal isn't part of the OpenAPI standards, and isn't supported for code generation
  • Custom typemappings may be needed in maven config, e.g.
    • to get byte array as return type (e.g. when returning image) for type: file instead of default java.io.File:
      <typeMappings><typeMapping>file=byte[]</typeMapping></typeMappings>
  • all plugins: JAX-RS always returns a default http status code (200 for OK with body, 204 for OK without body). Only way to override is by generating javax.ws.rs.core.Response return types for all generated models.
  1. Smals will share their extensions to the code generation plugin, adding proper support for additional properties to all generated classes.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions