Blame view

backend/base/src/main/java/springfox/documentation/schema/Example.java 3.38 KB
8d73e917   陈威   初始化提交
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 *
 *  Copyright 2017-2019 the original author or authors.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *
 */
package springfox.documentation.schema;

import static java.util.Optional.ofNullable;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import com.fasterxml.jackson.annotation.JsonInclude;

import springfox.documentation.service.VendorExtension;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Example {
	private final String id;
	private final String summary;
	private final String description;
	private final Object value;
	private final String externalValue;
	private final String mediaType;
	private final List<VendorExtension> extensions = new ArrayList<>();

	/**
	 * @deprecated @since 3.0.0 Use @see
	 *             {@link Example#Example(String, String, String, Object, String, String)}
	 * @param value - example literal
	 */
	@Deprecated
	public Example(Object value) {
		this.value = value;
		this.mediaType = null;
		externalValue = null;
		id = null;
		summary = null;
		description = null;
	}

	/**
	 * @deprecated @since 3.0.0 Use @see
	 *             {@link Example#Example(String, String, String, Object, String, String)}
	 * @param mediaType - media type of the example
	 * @param value     - example literal
	 */
	@Deprecated
	public Example(String mediaType, Object value) {
		this.mediaType = mediaType;
		this.value = value;
		externalValue = null;
		id = null;
		summary = null;
		description = null;
	}

	public Example(String id, String summary, String description, Object value, String externalValue,
			String mediaType) {
		this.id = id;
		this.summary = summary;
		this.description = description;
		this.value = value;
		this.externalValue = externalValue;
		this.mediaType = mediaType;
	}

	public String getId() {
		return id;
	}

	public String getSummary() {
		return summary;
	}

	public String getDescription() {
		return description;
	}

	public String getExternalValue() {
		return externalValue;
	}

	public List<VendorExtension> getExtensions() {
		return extensions;
	}

	public Object getValue() {
		return value;
	}

	public Optional<String> getMediaType() {
		return ofNullable(mediaType);
	}

	@Override
	public String toString() {
		return String.valueOf(value);
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (o == null || getClass() != o.getClass()) {
			return false;
		}
		Example example = (Example) o;
		return id != null && id.equals(example.id) && Objects.equals(summary,
				example.summary)
				&& Objects.equals(description, example.description) && value.equals(example.value)
				&& externalValue.equals(example.externalValue) && mediaType.equals(example.mediaType)
				&& extensions.equals(example.extensions);
	}

	@Override
	public int hashCode() {
		return Objects.hash(id, summary, description, value, externalValue, mediaType, extensions);
	}
}