-
Notifications
You must be signed in to change notification settings - Fork 435
Developer guide: show what the protocol generators actually emit #5811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
187fb60
Developer guide: show what the protocol generators actually emit
shai-almog edc5268
Developer guide: the protocol call sites must survive a successful em…
shai-almog 5652e06
Developer guide: license headers on the committed generator output
shai-almog dc1bace
Developer guide: isOk() classifies the payload, not the trip
shai-almog 89b0c5a
Developer guide: the REST callback gets three different things
shai-almog a7f2f6c
cn1:generate-openapi emits a reference to a class it does not write
shai-almog 660874e
Developer guide: a 2xx that would not parse is not an empty result
shai-almog 4082fad
Developer guide: the full license header on the test file the gate no…
shai-almog 14bf421
Developer guide: the call sites are the Java 17 shape, and say so
shai-almog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
docs/demos/common/src/main/java/com/example/hello/GreeterCallSite.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * Copyright (c) 2026, Codename One and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. Codename One designates this | ||
| * particular file as subject to the "Classpath" exception as provided | ||
| * by Oracle in the LICENSE file that accompanied this code. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Codename One through http://www.codenameone.com/ if you | ||
| * need additional information or have any questions. | ||
| */ | ||
| package com.example.hello; | ||
|
|
||
| import com.codename1.components.ToastBar; | ||
| import java.util.Arrays; | ||
|
|
||
| /// Call site for the `@GrpcClient` interface `cn1:generate-grpc` emits. | ||
| /// Included by the developer guide's `generate-grpc` appendix. | ||
| class GreeterCallSite { | ||
|
|
||
| // tag::appendix-goal-generate-grpc-java-002[] | ||
| void sayHello(String bearerToken) { | ||
| GreeterGrpc greeter = GreeterGrpc.of("https://grpc.example.com"); | ||
| HelloRequest request = new HelloRequest("Ada", Arrays.asList("ada", "countess"), Mood.HAPPY); | ||
|
|
||
| greeter.sayHello(request, bearerToken, response -> { | ||
| if (response.isOk() && response.getResponseData() != null) { | ||
| ToastBar.showInfoMessage(response.getResponseData().message()); | ||
| } else if (response.isOk()) { | ||
| ToastBar.showErrorMessage("The server returned an empty reply"); | ||
| } else { | ||
| // getResponseCode() is the gRPC status, not the HTTP one -- | ||
| // a gRPC-Web call can carry a failure under HTTP 200. | ||
| ToastBar.showErrorMessage("gRPC status " + response.getResponseCode() | ||
| + ": " + response.getResponseErrorMessage()); | ||
| } | ||
| }); | ||
| } | ||
| // end::appendix-goal-generate-grpc-java-002[] | ||
| } | ||
44 changes: 44 additions & 0 deletions
44
docs/demos/common/src/main/java/com/example/hello/GreeterGrpc.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Copyright (c) 2026, Codename One and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. Codename One designates this | ||
| * particular file as subject to the "Classpath" exception as provided | ||
| * by Oracle in the LICENSE file that accompanied this code. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Codename One through http://www.codenameone.com/ if you | ||
| * need additional information or have any questions. | ||
| */ | ||
| // Generated by cn1:generate-grpc. | ||
| package com.example.hello; | ||
|
|
||
| import com.codename1.annotations.grpc.GrpcClient; | ||
| import com.codename1.annotations.grpc.Rpc; | ||
| import com.codename1.annotations.rest.Header; | ||
| import com.codename1.io.grpc.GrpcClients; | ||
| import com.codename1.io.grpc.GrpcResponse; | ||
| import com.codename1.util.OnComplete; | ||
|
|
||
| // tag::appendix-goal-generate-grpc-java-001[] | ||
| @GrpcClient("helloworld.Greeter") | ||
| public interface GreeterGrpc { | ||
|
|
||
| @Rpc("SayHello") | ||
| void sayHello(com.example.hello.HelloRequest request, @Header("Authorization") String bearerToken, OnComplete<GrpcResponse<com.example.hello.HelloReply>> callback); | ||
|
|
||
| static GreeterGrpc of(String baseUrl) { | ||
| return GrpcClients.create(GreeterGrpc.class, baseUrl); | ||
| } | ||
| } | ||
| // end::appendix-goal-generate-grpc-java-001[] |
34 changes: 34 additions & 0 deletions
34
docs/demos/common/src/main/java/com/example/hello/HelloReply.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Copyright (c) 2026, Codename One and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. Codename One designates this | ||
| * particular file as subject to the "Classpath" exception as provided | ||
| * by Oracle in the LICENSE file that accompanied this code. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Codename One through http://www.codenameone.com/ if you | ||
| * need additional information or have any questions. | ||
| */ | ||
| // Generated by cn1:generate-grpc. | ||
| package com.example.hello; | ||
|
|
||
| import com.codename1.annotations.grpc.ProtoField; | ||
| import com.codename1.annotations.grpc.ProtoMessage; | ||
|
|
||
| @ProtoMessage | ||
| public record HelloReply( | ||
| @ProtoField(tag = 1) String message, | ||
| @ProtoField(tag = 2, wireType = ProtoField.WireKind.SINT, name = "emoji_code") int emojiCode, | ||
| @ProtoField(tag = 3) com.example.hello.HelloRequest echo | ||
| ) {} |
35 changes: 35 additions & 0 deletions
35
docs/demos/common/src/main/java/com/example/hello/HelloRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * Copyright (c) 2026, Codename One and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. Codename One designates this | ||
| * particular file as subject to the "Classpath" exception as provided | ||
| * by Oracle in the LICENSE file that accompanied this code. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Codename One through http://www.codenameone.com/ if you | ||
| * need additional information or have any questions. | ||
| */ | ||
| // Generated by cn1:generate-grpc. | ||
| package com.example.hello; | ||
|
|
||
| import com.codename1.annotations.grpc.ProtoField; | ||
| import com.codename1.annotations.grpc.ProtoMessage; | ||
| import java.util.List; | ||
|
|
||
| @ProtoMessage | ||
| public record HelloRequest( | ||
| @ProtoField(tag = 1) String name, | ||
| @ProtoField(tag = 2) List<String> aliases, | ||
| @ProtoField(tag = 3) com.example.hello.Mood mood | ||
| ) {} |
43 changes: 43 additions & 0 deletions
43
docs/demos/common/src/main/java/com/example/hello/Mood.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * Copyright (c) 2026, Codename One and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. Codename One designates this | ||
| * particular file as subject to the "Classpath" exception as provided | ||
| * by Oracle in the LICENSE file that accompanied this code. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Codename One through http://www.codenameone.com/ if you | ||
| * need additional information or have any questions. | ||
| */ | ||
| // Generated by cn1:generate-grpc. | ||
| package com.example.hello; | ||
|
|
||
| import com.codename1.annotations.grpc.ProtoEnum; | ||
|
|
||
| @ProtoEnum | ||
| public enum Mood { | ||
| UNKNOWN(0), | ||
| HAPPY(1), | ||
| SAD(2); | ||
|
|
||
| public final int number; | ||
| Mood(int n) { this.number = n; } | ||
|
|
||
| public static Mood forNumber(int n) { | ||
| for (Mood v : values()) { | ||
| if (v.number == n) return v; | ||
| } | ||
| return null; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
docs/demos/common/src/main/java/com/example/petstore/PetApiCallSite.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * Copyright (c) 2026, Codename One and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. Codename One designates this | ||
| * particular file as subject to the "Classpath" exception as provided | ||
| * by Oracle in the LICENSE file that accompanied this code. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Codename One through http://www.codenameone.com/ if you | ||
| * need additional information or have any questions. | ||
| */ | ||
| package com.example.petstore; | ||
|
|
||
| import com.codename1.components.ToastBar; | ||
|
|
||
| /// Call site for the `@RestClient` interface `cn1:generate-openapi` emits. | ||
| /// Included by the developer guide's `generate-openapi` appendix. | ||
| class PetApiCallSite { | ||
|
|
||
| // tag::appendix-goal-generate-openapi-java-003[] | ||
| void loadPet(String bearerToken) { | ||
| PetApi api = PetApi.of("https://petstore3.swagger.io/api/v3"); | ||
|
|
||
| api.getPetById(10L, bearerToken, response -> { | ||
| // Two things have to be settled before the payload is a Pet. | ||
| // The generated impl passes null when the request never | ||
| // completed, and on an error status it forwards the raw | ||
| // Response<String> under this type -- so on that path | ||
| // getResponseData() is the error body, not a Pet, and | ||
| // touching it as one is a cast that does not throw on iOS. | ||
| if (response == null) { | ||
| ToastBar.showErrorMessage("The request did not complete"); | ||
| } else if (response.getResponseCode() < 200 || response.getResponseCode() > 299) { | ||
| ToastBar.showErrorMessage(response.getResponseErrorMessage()); | ||
| } else if (response.getResponseData() == null) { | ||
| ToastBar.showErrorMessage("The server returned no pet"); | ||
| } else { | ||
| ToastBar.showInfoMessage(response.getResponseData().name()); | ||
| } | ||
| }); | ||
| } | ||
| // end::appendix-goal-generate-openapi-java-003[] | ||
| } |
56 changes: 56 additions & 0 deletions
56
docs/demos/common/src/main/java/com/example/petstore/StoreApi.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * Copyright (c) 2026, Codename One and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. Codename One designates this | ||
| * particular file as subject to the "Classpath" exception as provided | ||
| * by Oracle in the LICENSE file that accompanied this code. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Codename One through http://www.codenameone.com/ if you | ||
| * need additional information or have any questions. | ||
| */ | ||
| // Generated by cn1:generate-openapi. | ||
| package com.example.petstore; | ||
|
|
||
| import com.codename1.annotations.rest.Body; | ||
| import com.codename1.annotations.rest.Cookie; | ||
| import com.codename1.annotations.rest.DELETE; | ||
| import com.codename1.annotations.rest.GET; | ||
| import com.codename1.annotations.rest.Header; | ||
| import com.codename1.annotations.rest.PATCH; | ||
| import com.codename1.annotations.rest.POST; | ||
| import com.codename1.annotations.rest.PUT; | ||
| import com.codename1.annotations.rest.Path; | ||
| import com.codename1.annotations.rest.Query; | ||
| import com.codename1.annotations.rest.RestClient; | ||
| import com.codename1.io.rest.Response; | ||
| import com.codename1.io.rest.RestClients; | ||
| import com.codename1.util.OnComplete; | ||
|
|
||
| @RestClient | ||
| public interface StoreApi { | ||
|
|
||
| @POST("/store/order") | ||
| void placeOrder(@Body com.example.petstore.model.Order body, @Header("Authorization") String bearerToken, OnComplete<Response<com.example.petstore.model.Order>> callback); | ||
|
|
||
| @GET("/store/order/{orderId}") | ||
| void getOrderById(@Path("orderId") Long orderId, @Header("Authorization") String bearerToken, OnComplete<Response<com.example.petstore.model.Order>> callback); | ||
|
|
||
| @DELETE("/store/order/{orderId}") | ||
| void deleteOrder(@Path("orderId") Long orderId, @Header("Authorization") String bearerToken, OnComplete<Response<String>> callback); | ||
|
|
||
| static StoreApi of(String baseUrl) { | ||
| return RestClients.create(StoreApi.class, baseUrl); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.