Skip to content

Instantly share code, notes, and snippets.

@motorro
Last active November 18, 2019 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motorro/29f63b5a452af0db4904fdede7a99a79 to your computer and use it in GitHub Desktop.
Save motorro/29f63b5a452af0db4904fdede7a99a79 to your computer and use it in GitHub Desktop.
Swagger generator nested ref issue
/*
* Sample API
* API description in Markdown.
*
* OpenAPI spec version: 1.0.0
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package io.swagger.client.model;
import java.util.Objects;
import java.util.Arrays;
import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
// ----------------------------------------------------------------------
// There is no such class in models although DisplayMessage is genereated
// ----------------------------------------------------------------------
import io.swagger.client.model.RefSchemasYamlDisplayMessage;
import io.swagger.v3.oas.annotations.media.Schema;
import java.io.IOException;
/**
* Error response
*/
@Schema(description = "Error response")
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaClientCodegen", date = "2019-11-18T15:44:07.799+03:00[Europe/Moscow]")
public class Error {
/**
* Error code
*/
@JsonAdapter(CodeEnum.Adapter.class)
public enum CodeEnum {
GENERAL_400("GENERAL_400"),
ENTITY_404("ENTITY_404"),
SERVER_500("SERVER_500");
private String value;
CodeEnum(String value) {
this.value = value;
}
public String getValue() {
return value;
}
@Override
public String toString() {
return String.valueOf(value);
}
public static CodeEnum fromValue(String text) {
for (CodeEnum b : CodeEnum.values()) {
if (String.valueOf(b.value).equals(text)) {
return b;
}
}
return null;
}
public static class Adapter extends TypeAdapter<CodeEnum> {
@Override
public void write(final JsonWriter jsonWriter, final CodeEnum enumeration) throws IOException {
jsonWriter.value(enumeration.getValue());
}
@Override
public CodeEnum read(final JsonReader jsonReader) throws IOException {
String value = jsonReader.nextString();
return CodeEnum.fromValue(String.valueOf(value));
}
}
} @SerializedName("code")
private CodeEnum code = null;
@SerializedName("message")
private String message = null;
// ----------------------------------------------------------------------
// Should be DisplayMessage here
// ----------------------------------------------------------------------
@SerializedName("displayMessage")
private RefSchemasYamlDisplayMessage displayMessage = null;
public Error code(CodeEnum code) {
this.code = code;
return this;
}
/**
* Error code
* @return code
**/
@Schema(description = "Error code")
public CodeEnum getCode() {
return code;
}
public void setCode(CodeEnum code) {
this.code = code;
}
public Error message(String message) {
this.message = message;
return this;
}
/**
* Basic error message
* @return message
**/
@Schema(description = "Basic error message")
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Error displayMessage(RefSchemasYamlDisplayMessage displayMessage) {
this.displayMessage = displayMessage;
return this;
}
/**
* Get displayMessage
* @return displayMessage
**/
@Schema(description = "")
public RefSchemasYamlDisplayMessage getDisplayMessage() {
return displayMessage;
}
public void setDisplayMessage(RefSchemasYamlDisplayMessage displayMessage) {
this.displayMessage = displayMessage;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Error error = (Error) o;
return Objects.equals(this.code, error.code) &&
Objects.equals(this.message, error.message) &&
Objects.equals(this.displayMessage, error.displayMessage);
}
@Override
public int hashCode() {
return Objects.hash(code, message, displayMessage);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Error {\n");
sb.append(" code: ").append(toIndentedString(code)).append("\n");
sb.append(" message: ").append(toIndentedString(message)).append("\n");
sb.append(" displayMessage: ").append(toIndentedString(displayMessage)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}
openapi: 3.0.1
info:
title: Sample API
description: API description in Markdown.
version: 1.0.0
servers:
- url: 'https://api.example.com'
paths:
/users:
get:
summary: Returns a list of users.
description: Optional extended description in Markdown.
responses:
'500':
$ref: '#/components/responses/Error500'
components:
schemas:
DisplayMessage:
$ref: 'ref_schemas.yaml#/DisplayMessage'
Error:
$ref: 'ref_errors.yaml#/Error'
responses:
Error500:
$ref: 'ref_responses.yaml#/Error500'
# -----------
# Errors
# -----------
Error:
description: Error response
type: object
properties:
code:
description: Error code
type: string
enum:
- GENERAL_400
- ENTITY_404
- SERVER_500
message:
description: Basic error message
type: string
displayMessage:
$ref: './ref_schemas.yaml#/DisplayMessage'
Error500:
description: An unexpected error occured.
content:
application/vnd.com.navalchess+json:
schema:
$ref: './ref_errors.yaml#/Error'
DisplayMessage:
description: Message to display to client
type: object
properties:
header:
description: Message header
type: string
text:
description: Message text
type: string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment