swagger-api / swagger-api/swagger-codegen

[[JAVA] - Need to generate java.lang.Exception object from Swagger 2.0

Open
#8,019 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I belong to swagger API design team. A Java developer in my team wants me add a CustomException object that extends an Exception object which gets generated as java.lang.Exception object when code is generated using codegen. His argument is that using additionalProperties I was able to generate below code using codegen.

import java.util.Objects;
import java.util.HashMap;
import java.util.Map;
public class RowData extends HashMap<String, Object> {

In the same way he wants me to come up with a way in swagger so that below code is generated by codegen. Please let me know if this is possible in swagger or do we have to manually create this in java class post code generation

import java.lang.Exception;
public class CustomException extends Exception {

Swagger-codegen version

swagger-codegen-cli-2.3.1

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 reviewing the Swagger 2.0 definition and Java generation behavior in swagger-codegen-cli-2.3.1, then determine whether the generator supports exception inheritance. Done means establishing and documenting a supported way to generate CustomException extending java.lang.Exception, or confirming it must be created manually after generation.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design, devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.