-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatgpt.txt
More file actions
227 lines (184 loc) · 6.21 KB
/
chatgpt.txt
File metadata and controls
227 lines (184 loc) · 6.21 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
I'm writing code to create a Github Client API in Java based on the openapi schema definition.
I have my own kind of client I'd like to create, one that uses Jakarta Json B to do the json marshalling and use my special client, which I'll have to show you. You and I will be generating classes together in this style. First, here's an example of part of the "issue" schema type A fragment from the components/schema section of the github openapi document.
"issue": {
"title": "Issue",
"description": "Issues are a great way to keep track of tasks, enhancements, and bugs for your projects.",
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"node_id": {
"type": "string"
},
"url": {
"description": "URL for the issue",
"example": "https://api.github.com/repositories/42/issues/1",
"type": "string",
"format": "uri"
},
"repository_url": {
"type": "string",
"format": "uri"
},
"labels_url": {
"type": "string"
},
"comments_url": {
"type": "string",
"format": "uri"
},
"events_url": {
"type": "string",
"format": "uri"
},
"html_url": {
"type": "string",
"format": "uri"
},
"number": {
"description": "Number uniquely identifying the issue within its repository",
"example": 42,
"type": "integer"
},
"state": {
"description": "State of the issue; either 'open' or 'closed'",
"example": "open",
"type": "string"
},
"state_reason": {
"description": "The reason for the current state",
"example": "not_planned",
"type": "string",
"nullable": true,
"enum": [
"completed",
"reopened",
"not_planned"
]
},
"title": {
"description": "Title of the issue",
"example": "Widget creation fails in Safari on OS X 10.8",
"type": "string"
},
"body": {
"description": "Contents of the issue",
"example": "It looks like the new widget form is broken on Safari. When I try and create the widget, Safari crashes. This is reproducible on 10.8, but not 10.9. Maybe a browser bug?",
"type": "string",
"nullable": true
},
"user": {
"$ref": "#/components/schemas/nullable-simple-user"
},
And how that fragment looks in Java
/*
* 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 org.tomitribe.github.client;
import jakarta.json.bind.annotation.JsonbProperty;
import jakarta.json.bind.annotation.JsonbTypeAdapter;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.tomitribe.github.core.EnumAdapter;
import java.net.URI;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Issue {
private Integer id;
@JsonbProperty("node_id")
private String nodeId;
@JsonbProperty("url")
private URI url;
@JsonbProperty("repository_url")
private URI repositoryUrl;
@JsonbProperty("comments_url")
private URI commentsUrl;
@JsonbProperty("events_url")
private URI eventsUrl;
@JsonbProperty("html_url")
private URI htmlUrl;
@JsonbProperty("number")
private Integer number;
@JsonbProperty("state")
@JsonbTypeAdapter(StateAdapter.class)
private State state;
@JsonbProperty("state_reason")
@JsonbTypeAdapter(StateReasonAdapter.class)
private StateReason stateReason;
@JsonbProperty("title")
private String title;
@JsonbProperty("body")
private String body;
@JsonbProperty("user")
private SimpleUser user;
public enum State {
OPEN("open"), CLOSED("closed");
private final String name;
State(final String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public String toString() {
return name;
}
}
public static class StateAdapter extends EnumAdapter<State> {
public StateAdapter() {
super(State.class);
}
}
public enum StateReason {
COMPLETED("completed"),
REOPENED("reopened"),
NOT_PLANNED("not_planned");
private final String name;
StateReason(final String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public String toString() {
return name;
}
}
public static class StateReasonAdapter extends EnumAdapter<StateReason> {
public StateReasonAdapter() {
super(StateReason.class);
}
}
}
We need to use Boolean instead of boolean so we can detect scenarios where the value was not supplied
When a schema has a ref let's put the ref name in the javadoc as well so it's easier for me to find
Let's add the openapi descriptions as javadoc to the classes we generate
Ensure the field order is identical to the openapi property order
Always generate inline for fast copy/paste.
Where the property "type" is "integer" and "format" is "int64", the Java type should be Long
Where the property name ends in "_url", is of type "string" and has a valid URL as the example, use the java type URI
Where the property name ends in "_at", is of type "string" and shows a date value as the example, assume format "date-time" and use an Instant as the java type
Where the property type is "string" and no "enum" values were listed, but the description strongly implies it's an enum and lists the possible values, assume it's an enum and create a Java enum for it. For example
"visibility": {
"description": "The repository visibility: public, private, or internal.",
"default": "public",
"type": "string"
}