Skip to content

Commit eca9ec7

Browse files
authored
Feat/jetbrains http client (#14477)
* Dummy client generated * Adding dummy versions, my IDE crashed * Making my first actual requests * Creates first version of API Generator for Jetbrains Client * Adds generated API files * Adds more complex API definition * Adds basic supporting files * Adds empty environment file for variables * Adds basic README * Adds minimal set of values in env file` * Adds minimal support for API Key header * Adds Adyen API sample * Add null checks on code * Simplifies the generator, cleans output * Improves README * Fix minor issues with README * Removes API file and config used for local testing * Remove leftover logging file * Disables tests as I find how to write them * Sets generator as experimental * Add new generator language enum value * Adds generator doc file * Adds generators main file * Removes unused method. Adds my name * Adding Jetbrains HTTP Client to the README
1 parent fa1cbb9 commit eca9ec7

19 files changed

Lines changed: 602 additions & 51 deletions

File tree

README.md

Lines changed: 51 additions & 49 deletions
Large diffs are not rendered by default.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
generatorName: jetbrains-http-client
2+
outputDir: samples/client/petstore/jetbrains/http/client
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/jetbrains-http-client
5+
additionalProperties:
6+
hideGenerationTimestamp: "true"

docs/generators.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ The following generators are available:
3939
* [javascript-closure-angular](generators/javascript-closure-angular.md)
4040
* [javascript-flowtyped](generators/javascript-flowtyped.md)
4141
* [jaxrs-cxf-client](generators/jaxrs-cxf-client.md)
42+
* [jetbrains-http-client (experimental)](generators/jetbrains-http-client.md)
4243
* [jmeter](generators/jmeter.md)
4344
* [julia-client (beta)](generators/julia-client.md)
4445
* [k6 (beta)](generators/k6.md)
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
---
2+
title: Documentation for the jetbrains-http-client Generator
3+
---
4+
5+
## METADATA
6+
7+
| Property | Value | Notes |
8+
| -------- | ----- | ----- |
9+
| generator name | jetbrains-http-client | pass this to the generate command after -g |
10+
| generator stability | EXPERIMENTAL | |
11+
| generator type | CLIENT | |
12+
| generator language | Jetbrains HTTP Client (HTTP/REST) | |
13+
| generator default templating engine | mustache | |
14+
| helpTxt | Generates a jetbrains-http client. See https://www.jetbrains.com/help/idea/http-client-in-product-code-editor.html | |
15+
16+
## CONFIG OPTIONS
17+
These options may be applied as additional-properties (cli) or configOptions (plugins). Refer to [configuration docs](https://openapi-generator.tech/docs/configuration) for more details.
18+
19+
| Option | Description | Values | Default |
20+
| ------ | ----------- | ------ | ------- |
21+
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
22+
|disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.</dd></dl>|true|
23+
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
24+
|enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|<dl><dt>**false**</dt><dd>No changes to the enum's are made, this is the default option.</dd><dt>**true**</dt><dd>With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.</dd></dl>|false|
25+
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C#have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.</dd></dl>|true|
26+
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
27+
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
28+
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
29+
30+
## IMPORT MAPPING
31+
32+
| Type/Alias | Imports |
33+
| ---------- | ------- |
34+
35+
36+
## INSTANTIATION TYPES
37+
38+
| Type/Alias | Instantiated By |
39+
| ---------- | --------------- |
40+
41+
42+
## LANGUAGE PRIMITIVES
43+
44+
<ul class="column-ul">
45+
</ul>
46+
47+
## RESERVED WORDS
48+
49+
<ul class="column-ul">
50+
</ul>
51+
52+
## FEATURE SET
53+
54+
55+
### Client Modification Feature
56+
| Name | Supported | Defined By |
57+
| ---- | --------- | ---------- |
58+
|BasePath|✗|ToolingExtension
59+
|Authorizations|✗|ToolingExtension
60+
|UserAgent|✗|ToolingExtension
61+
|MockServer|✗|ToolingExtension
62+
63+
### Data Type Feature
64+
| Name | Supported | Defined By |
65+
| ---- | --------- | ---------- |
66+
|Custom|✗|OAS2,OAS3
67+
|Int32|✓|OAS2,OAS3
68+
|Int64|✓|OAS2,OAS3
69+
|Float|✓|OAS2,OAS3
70+
|Double|✓|OAS2,OAS3
71+
|Decimal|✓|ToolingExtension
72+
|String|✓|OAS2,OAS3
73+
|Byte|✓|OAS2,OAS3
74+
|Binary|✓|OAS2,OAS3
75+
|Boolean|✓|OAS2,OAS3
76+
|Date|✓|OAS2,OAS3
77+
|DateTime|✓|OAS2,OAS3
78+
|Password|✓|OAS2,OAS3
79+
|File|✓|OAS2
80+
|Uuid||
81+
|Array|✓|OAS2,OAS3
82+
|Null|✗|OAS3
83+
|AnyType|✗|OAS2,OAS3
84+
|Object|✓|OAS2,OAS3
85+
|Maps|✓|ToolingExtension
86+
|CollectionFormat|✓|OAS2
87+
|CollectionFormatMulti|✓|OAS2
88+
|Enum|✓|OAS2,OAS3
89+
|ArrayOfEnum|✓|ToolingExtension
90+
|ArrayOfModel|✓|ToolingExtension
91+
|ArrayOfCollectionOfPrimitives|✓|ToolingExtension
92+
|ArrayOfCollectionOfModel|✓|ToolingExtension
93+
|ArrayOfCollectionOfEnum|✓|ToolingExtension
94+
|MapOfEnum|✓|ToolingExtension
95+
|MapOfModel|✓|ToolingExtension
96+
|MapOfCollectionOfPrimitives|✓|ToolingExtension
97+
|MapOfCollectionOfModel|✓|ToolingExtension
98+
|MapOfCollectionOfEnum|✓|ToolingExtension
99+
100+
### Documentation Feature
101+
| Name | Supported | Defined By |
102+
| ---- | --------- | ---------- |
103+
|Readme|✗|ToolingExtension
104+
|Model|✓|ToolingExtension
105+
|Api|✓|ToolingExtension
106+
107+
### Global Feature
108+
| Name | Supported | Defined By |
109+
| ---- | --------- | ---------- |
110+
|Host|✓|OAS2,OAS3
111+
|BasePath|✓|OAS2,OAS3
112+
|Info|✓|OAS2,OAS3
113+
|Schemes|✗|OAS2,OAS3
114+
|PartialSchemes|✓|OAS2,OAS3
115+
|Consumes|✓|OAS2
116+
|Produces|✓|OAS2
117+
|ExternalDocumentation|✓|OAS2,OAS3
118+
|Examples|✓|OAS2,OAS3
119+
|XMLStructureDefinitions|✗|OAS2,OAS3
120+
|MultiServer|✗|OAS3
121+
|ParameterizedServer|✗|OAS3
122+
|ParameterStyling|✗|OAS3
123+
|Callbacks|✓|OAS3
124+
|LinkObjects|✗|OAS3
125+
126+
### Parameter Feature
127+
| Name | Supported | Defined By |
128+
| ---- | --------- | ---------- |
129+
|Path|✓|OAS2,OAS3
130+
|Query|✓|OAS2,OAS3
131+
|Header|✓|OAS2,OAS3
132+
|Body|✓|OAS2
133+
|FormUnencoded|✓|OAS2
134+
|FormMultipart|✓|OAS2
135+
|Cookie|✓|OAS3
136+
137+
### Schema Support Feature
138+
| Name | Supported | Defined By |
139+
| ---- | --------- | ---------- |
140+
|Simple|✓|OAS2,OAS3
141+
|Composite|✓|OAS2,OAS3
142+
|Polymorphism|✓|OAS2,OAS3
143+
|Union|✗|OAS3
144+
|allOf|✗|OAS2,OAS3
145+
|anyOf|✗|OAS3
146+
|oneOf|✗|OAS3
147+
|not|✗|OAS3
148+
149+
### Security Feature
150+
| Name | Supported | Defined By |
151+
| ---- | --------- | ---------- |
152+
|BasicAuth|✓|OAS2,OAS3
153+
|ApiKey|✓|OAS2,OAS3
154+
|OpenIDConnect|✗|OAS3
155+
|BearerToken|✓|OAS3
156+
|OAuth2_Implicit|✓|OAS2,OAS3
157+
|OAuth2_Password|✓|OAS2,OAS3
158+
|OAuth2_ClientCredentials|✓|OAS2,OAS3
159+
|OAuth2_AuthorizationCode|✓|OAS2,OAS3
160+
161+
### Wire Format Feature
162+
| Name | Supported | Defined By |
163+
| ---- | --------- | ---------- |
164+
|JSON|✓|OAS2,OAS3
165+
|XML|✓|OAS2,OAS3
166+
|PROTOBUF|✗|ToolingExtension
167+
|Custom|✗|OAS2,OAS3

modules/openapi-generator/src/main/java/org/openapitools/codegen/GeneratorLanguage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public enum GeneratorLanguage {
2828
DART("Dart"), EIFFEL("Eiffel"), ELIXIR("Elixir"), ELM("Elm"),
2929
ERLANG("Erlang"), FLASH("Flash"), F_SHARP("F#"), GO("Go"),
3030
JAVASCRIPT("Javascript"), GRAPH_QL("GraphQL"), GROOVY("Groovy"),
31-
HASKELL("Haskell"), TYPESCRIPT("Typescript"), K_SIX("k6"), KOTLIN("Kotlin"),
31+
HASKELL("Haskell"), HTTP("Jetbrains HTTP Client (HTTP/REST)"), TYPESCRIPT("Typescript"), K_SIX("k6"), KOTLIN("Kotlin"),
3232
KTORM("Ktorm"), LUA("Lua"), MYSQL("Mysql"), NIM("Nim"),
3333
OBJECTIVE_C("Objective-C"), OCAML("OCaml"), PERL("Perl"), PHP("PHP"),
3434
POWERSHELL("PowerShell"), PROTOBUF("Protocol Buffers (Protobuf)"), PYTHON("Python"),
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package org.openapitools.codegen.languages;
2+
3+
import com.google.common.collect.ImmutableMap;
4+
import com.samskivert.mustache.Mustache;
5+
import com.samskivert.mustache.Template;
6+
import org.openapitools.codegen.*;
7+
8+
import java.io.File;
9+
import java.io.IOException;
10+
import java.io.Writer;
11+
import java.util.ArrayList;
12+
import java.util.List;
13+
import java.util.Map;
14+
import java.util.Set;
15+
import java.util.concurrent.ConcurrentHashMap;
16+
import java.util.function.Function;
17+
import java.util.function.Predicate;
18+
import java.util.stream.Collectors;
19+
20+
import org.openapitools.codegen.meta.GeneratorMetadata;
21+
import org.openapitools.codegen.meta.Stability;
22+
import org.openapitools.codegen.model.ApiInfoMap;
23+
import org.openapitools.codegen.model.ModelMap;
24+
import org.openapitools.codegen.model.OperationMap;
25+
import org.openapitools.codegen.model.OperationsMap;
26+
import org.slf4j.Logger;
27+
import org.slf4j.LoggerFactory;
28+
29+
public class JetbrainsHttpClientClientCodegen extends DefaultCodegen implements CodegenConfig {
30+
public static final String PROJECT_NAME = "Jetbrains HTTP Client";
31+
32+
public CodegenType getTag() {
33+
return CodegenType.CLIENT;
34+
}
35+
36+
public String getName() {
37+
return "jetbrains-http-client";
38+
}
39+
40+
public String getHelp() {
41+
return "Generates a jetbrains-http client. See https://www.jetbrains.com/help/idea/http-client-in-product-code-editor.html";
42+
}
43+
44+
@Override
45+
public GeneratorLanguage generatorLanguage() {
46+
return GeneratorLanguage.HTTP;
47+
}
48+
49+
public JetbrainsHttpClientClientCodegen() {
50+
super();
51+
52+
generatorMetadata = GeneratorMetadata.newBuilder(generatorMetadata)
53+
.stability(Stability.EXPERIMENTAL)
54+
.build();
55+
56+
outputFolder = "generated-code" + File.separator + "jetbrains-http-client";
57+
apiTemplateFiles.put("api.mustache", ".http");
58+
embeddedTemplateDir = templateDir = "jetbrains-http-client";
59+
apiPackage = "Apis";
60+
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
61+
}
62+
63+
@Override
64+
protected ImmutableMap.Builder<String, Mustache.Lambda> addMustacheLambdas() {
65+
66+
return super.addMustacheLambdas()
67+
.put("doubleMustache", new DoubleMustacheLambda());
68+
}
69+
70+
public static class DoubleMustacheLambda implements Mustache.Lambda {
71+
@Override
72+
public void execute(Template.Fragment fragment, Writer writer) throws IOException {
73+
String text = fragment.execute();
74+
writer.write(text
75+
.replaceAll("\\{", "{{")
76+
.replaceAll("}", "}}")
77+
);
78+
}
79+
}
80+
81+
@Override
82+
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> bundle) {
83+
84+
return bundle;
85+
}
86+
87+
@Override
88+
public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<ModelMap> allModels) {
89+
return super.postProcessOperationsWithModels(objs, allModels);
90+
}
91+
92+
@Override
93+
public void postProcess() {
94+
System.out.println("################################################################################");
95+
System.out.println("# Thanks for using OpenAPI Generator. #");
96+
System.out.println("# Please consider donation to help us maintain this project \uD83D\uDE4F #");
97+
System.out.println("# https://opencollective.com/openapi_generator/donate #");
98+
System.out.println("# #");
99+
System.out.println("# This generator was written by Julien Lengrand-Lambert (https://github.com/jlengrand) #");
100+
System.out.println("################################################################################");
101+
}
102+
}

modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,6 @@ org.openapitools.codegen.languages.TypeScriptNodeClientCodegen
138138
org.openapitools.codegen.languages.TypeScriptReduxQueryClientCodegen
139139
org.openapitools.codegen.languages.TypeScriptRxjsClientCodegen
140140
org.openapitools.codegen.languages.WsdlSchemaCodegen
141-
141+
org.openapitools.codegen.languages.JetbrainsHttpClientClientCodegen
142142
org.openapitools.codegen.languages.JuliaClientCodegen
143143
org.openapitools.codegen.languages.JuliaServerCodegen
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# {{appName}} - Jetbrains API Client
2+
3+
## OpenAPI File description
4+
5+
{{#appDescription}}{{appDescription}}{{/appDescription}}
6+
7+
* API basepath : [{{basePath}}]({{basePath}})
8+
* Version : {{version}}
9+
10+
## Documentation for API Endpoints
11+
12+
{{#generateApiDocs}}
13+
All URIs are relative to *{{{basePath}}}*, but will link to the `.http` file that contains the endpoint definition
14+
15+
Class | Method | HTTP request | Description
16+
------------ | ------------- | ------------- | -------------
17+
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**](Apis/{{apiDocPath}}{{classname}}.http#{{operationIdLowerCase}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{{summary}}}{{/summary}}
18+
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
19+
{{/generateApiDocs}}
20+
21+
22+
_This client was generated by the jetbrains-http-client of OpenAPI Generator_
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## {{classname}}
2+
{{#operations}}
3+
{{#operation}}
4+
5+
### {{#summary}}{{summary}}{{/summary}}
6+
# @name {{operationId}}
7+
{{httpMethod}} {{basePath}}{{#lambda.doubleMustache}}{{path}}{{/lambda.doubleMustache}}
8+
{{#consumes}}Content-Type: {{{mediaType}}}
9+
{{/consumes}}
10+
{{/operation}}
11+
{{/operations}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.openapitools.codegen.jetbrains.http.client;
2+
3+
import org.openapitools.codegen.*;
4+
import org.openapitools.codegen.languages.JetbrainsHttpClientClientCodegen;
5+
import io.swagger.models.*;
6+
import io.swagger.models.properties.*;
7+
8+
import org.testng.Assert;
9+
import org.testng.annotations.Test;
10+
11+
@SuppressWarnings("static-method")
12+
public class JetbrainsHttpClientClientCodegenModelTest {
13+
14+
@Test(description = "convert a simple java model")
15+
public void simpleModelTest() {
16+
final Model model = new ModelImpl()
17+
.description("a sample model")
18+
.property("id", new LongProperty())
19+
.property("name", new StringProperty())
20+
.required("id")
21+
.required("name");
22+
final DefaultCodegen codegen = new JetbrainsHttpClientClientCodegen();
23+
24+
// TODO: Complete this test.
25+
// Assert.fail("Not implemented.");
26+
}
27+
28+
}
29+

0 commit comments

Comments
 (0)