swagger-api / swagger-api/swagger-codegen

[Question] Specifying a Custom Swagger-Parser Extension at Runtime?

Open
#6,207 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

General: Question
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

I'm currently trying to generate code from vendor-supplied Swagger documentation that is not up to spec in that it returns array types as "Array" instead of "array" so I am running into the same issue as is described in https://github.com/swagger-api/swagger-codegen/issues/473.

I don't have the ability to modify the Swagger JSON returned by the vendor service prior to running Code Gen on it so I need to modify it at run-time. I looked through the CodeGen code and options but it doesn't seem that there are any hooks to replace Swagger Types with other Swagger Types before conversions happen (I tried to use a type mapping from "Array" to "array" but that resulted in the same issue noted in the linked ticket above).

My solution at this point has been to create a custom SwaggerParserExtension and include that as a dependency in Swagger CodeGen's POM and then after rebuilding CodeGen my extension can be used. This works fine for now but it does require that I maintain and use a custom fork of CodeGen. I don't know a lot about how Java SPI works so I'm not sure if this is possible or not but it would be great if there was a way to inject a custom SwaggerParserExtension at runtime.

Swagger-codegen version

v2.3.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how SwaggerParserExtension implementations are discovered and how CodeGen dependencies are supplied through the POM. Reproduce the vendor input using "Array" and determine the runtime extension mechanism and API needed. Done means a custom parser extension can be injected without rebuilding or maintaining a CodeGen fork.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.