swagger-api / swagger-api/swagger-codegen

sharing swagger model between server and client

Open
#5,572 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

I am trying to use the same model between two swagger java spring boot services. One service has a java client to the other service. I noticed that the java client generated code uses different annotator than the spring boot server generated code. Should I put both annotators on the model if I want to share it or should I just pick one annotator? Or should I not share the models by using copy constructors and full paths when referring to the two classes in the same file? The server code has @JsonProperty and the client code has @SerializedName

Swagger-codegen version

io.swagger.swagger-codegen-cli version 2.2.2

Swagger declaration file content or url

NA

Command line used for generation

-l java option to generate the java client
-l spring option to generate the spring boot service

Steps to reproduce

NA

Related issues

I did not see a related question.

Suggest a Fix

I was thinking of putting both annotators on the shared model. I'm open to suggestions.

The shared model would look like this.

`
import com.fasterxml.jackson.annotation.JsonProperty;

import com.google.gson.annotations.SerializedName;

@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2017-05-05T10:38:26.357-04:00")
public class SharedModel {
@JsonProperty("myentity")
@SerializedName("myentity")
private String myentity = null;
... the rest of the model ...
`

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

The issue provides no source file, test, or implementation entry point to inspect. Start by reviewing the Java and Spring generator templates and their annotation dependencies, then document the supported approach for sharing generated models and how Jackson and Gson annotations interact.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
api, backend
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.