Skip to content

Add a new jetbrains http client generator #14477

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 25 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
29ee594
Dummy client generated
jlengrand Nov 23, 2022
65e8794
Adding dummy versions, my IDE crashed
jlengrand Nov 25, 2022
01fac52
Making my first actual requests
jlengrand Nov 25, 2022
4190a70
Creates first version of API Generator for Jetbrains Client
jlengrand Nov 29, 2022
046c4ed
Adds generated API files
jlengrand Nov 29, 2022
d72a012
Adds more complex API definition
jlengrand Nov 29, 2022
fc631bb
Adds basic supporting files
jlengrand Nov 29, 2022
00a980e
Adds minimal set of values in env file`
jlengrand Nov 30, 2022
bc2283c
Adds minimal support for API Key header
jlengrand Dec 6, 2022
38009c9
Adds Adyen API sample
jlengrand Dec 7, 2022
a90ee91
Add null checks on code
jlengrand Jan 17, 2023
99a1e81
Merge branch 'master' into feat/jetbrains-http-client
jlengrand Jan 17, 2023
50ef5bd
Simplifies the generator, cleans output
jlengrand Jan 17, 2023
8a0d065
Improves README
jlengrand Jan 17, 2023
5986d8a
Fix minor issues with README
jlengrand Jan 17, 2023
a1ef814
Removes API file and config used for local testing
jlengrand Jan 18, 2023
3fc8580
Remove leftover logging file
jlengrand Jan 18, 2023
16a320d
Disables tests as I find how to write them
jlengrand Jan 18, 2023
131ac45
Sets generator as experimental
jlengrand Jan 18, 2023
8e7db2d
Add new generator language enum value
jlengrand Jan 21, 2023
67cfc66
Adds generator doc file
jlengrand Jan 21, 2023
5c42cd3
Adds generators main file
jlengrand Jan 21, 2023
31a72fa
Removes unused method. Adds my name
jlengrand Jan 22, 2023
7bb45d5
Merge master
jlengrand Jan 30, 2023
b44371c
Adding Jetbrains HTTP Client to the README
jlengrand Jan 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 51 additions & 49 deletions README.md

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions bin/configs/jetbrains-http-client-petstore-new.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
generatorName: jetbrains-http-client
outputDir: samples/client/petstore/jetbrains/http/client
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/jetbrains-http-client
additionalProperties:
hideGenerationTimestamp: "true"
1 change: 1 addition & 0 deletions docs/generators.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ The following generators are available:
* [javascript-closure-angular](generators/javascript-closure-angular.md)
* [javascript-flowtyped](generators/javascript-flowtyped.md)
* [jaxrs-cxf-client](generators/jaxrs-cxf-client.md)
* [jetbrains-http-client (experimental)](generators/jetbrains-http-client.md)
* [jmeter](generators/jmeter.md)
* [julia-client (beta)](generators/julia-client.md)
* [k6 (beta)](generators/k6.md)
Expand Down
167 changes: 167 additions & 0 deletions docs/generators/jetbrains-http-client.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
---
title: Documentation for the jetbrains-http-client Generator
---

## METADATA

| Property | Value | Notes |
| -------- | ----- | ----- |
| generator name | jetbrains-http-client | pass this to the generate command after -g |
| generator stability | EXPERIMENTAL | |
| generator type | CLIENT | |
| generator language | Jetbrains HTTP Client (HTTP/REST) | |
| generator default templating engine | mustache | |
| helpTxt | Generates a jetbrains-http client. See https://www.jetbrains.com/help/idea/http-client-in-product-code-editor.html | |

## CONFIG OPTIONS
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.

| Option | Description | Values | Default |
| ------ | ----------- | ------ | ------- |
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
|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|
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
|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|
|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|
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|

## IMPORT MAPPING

| Type/Alias | Imports |
| ---------- | ------- |


## INSTANTIATION TYPES

| Type/Alias | Instantiated By |
| ---------- | --------------- |


## LANGUAGE PRIMITIVES

<ul class="column-ul">
</ul>

## RESERVED WORDS

<ul class="column-ul">
</ul>

## FEATURE SET


### Client Modification Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|BasePath|✗|ToolingExtension
|Authorizations|✗|ToolingExtension
|UserAgent|✗|ToolingExtension
|MockServer|✗|ToolingExtension

### Data Type Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Custom|✗|OAS2,OAS3
|Int32|✓|OAS2,OAS3
|Int64|✓|OAS2,OAS3
|Float|✓|OAS2,OAS3
|Double|✓|OAS2,OAS3
|Decimal|✓|ToolingExtension
|String|✓|OAS2,OAS3
|Byte|✓|OAS2,OAS3
|Binary|✓|OAS2,OAS3
|Boolean|✓|OAS2,OAS3
|Date|✓|OAS2,OAS3
|DateTime|✓|OAS2,OAS3
|Password|✓|OAS2,OAS3
|File|✓|OAS2
|Uuid|✗|
|Array|✓|OAS2,OAS3
|Null|✗|OAS3
|AnyType|✗|OAS2,OAS3
|Object|✓|OAS2,OAS3
|Maps|✓|ToolingExtension
|CollectionFormat|✓|OAS2
|CollectionFormatMulti|✓|OAS2
|Enum|✓|OAS2,OAS3
|ArrayOfEnum|✓|ToolingExtension
|ArrayOfModel|✓|ToolingExtension
|ArrayOfCollectionOfPrimitives|✓|ToolingExtension
|ArrayOfCollectionOfModel|✓|ToolingExtension
|ArrayOfCollectionOfEnum|✓|ToolingExtension
|MapOfEnum|✓|ToolingExtension
|MapOfModel|✓|ToolingExtension
|MapOfCollectionOfPrimitives|✓|ToolingExtension
|MapOfCollectionOfModel|✓|ToolingExtension
|MapOfCollectionOfEnum|✓|ToolingExtension

### Documentation Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Readme|✗|ToolingExtension
|Model|✓|ToolingExtension
|Api|✓|ToolingExtension

### Global Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Host|✓|OAS2,OAS3
|BasePath|✓|OAS2,OAS3
|Info|✓|OAS2,OAS3
|Schemes|✗|OAS2,OAS3
|PartialSchemes|✓|OAS2,OAS3
|Consumes|✓|OAS2
|Produces|✓|OAS2
|ExternalDocumentation|✓|OAS2,OAS3
|Examples|✓|OAS2,OAS3
|XMLStructureDefinitions|✗|OAS2,OAS3
|MultiServer|✗|OAS3
|ParameterizedServer|✗|OAS3
|ParameterStyling|✗|OAS3
|Callbacks|✓|OAS3
|LinkObjects|✗|OAS3

### Parameter Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Path|✓|OAS2,OAS3
|Query|✓|OAS2,OAS3
|Header|✓|OAS2,OAS3
|Body|✓|OAS2
|FormUnencoded|✓|OAS2
|FormMultipart|✓|OAS2
|Cookie|✓|OAS3

### Schema Support Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Simple|✓|OAS2,OAS3
|Composite|✓|OAS2,OAS3
|Polymorphism|✓|OAS2,OAS3
|Union|✗|OAS3
|allOf|✗|OAS2,OAS3
|anyOf|✗|OAS3
|oneOf|✗|OAS3
|not|✗|OAS3

### Security Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|BasicAuth|✓|OAS2,OAS3
|ApiKey|✓|OAS2,OAS3
|OpenIDConnect|✗|OAS3
|BearerToken|✓|OAS3
|OAuth2_Implicit|✓|OAS2,OAS3
|OAuth2_Password|✓|OAS2,OAS3
|OAuth2_ClientCredentials|✓|OAS2,OAS3
|OAuth2_AuthorizationCode|✓|OAS2,OAS3

### Wire Format Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|JSON|✓|OAS2,OAS3
|XML|✓|OAS2,OAS3
|PROTOBUF|✗|ToolingExtension
|Custom|✗|OAS2,OAS3
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public enum GeneratorLanguage {
DART("Dart"), EIFFEL("Eiffel"), ELIXIR("Elixir"), ELM("Elm"),
ERLANG("Erlang"), FLASH("Flash"), F_SHARP("F#"), GO("Go"),
JAVASCRIPT("Javascript"), GRAPH_QL("GraphQL"), GROOVY("Groovy"),
HASKELL("Haskell"), TYPESCRIPT("Typescript"), K_SIX("k6"), KOTLIN("Kotlin"),
HASKELL("Haskell"), HTTP("Jetbrains HTTP Client (HTTP/REST)"), TYPESCRIPT("Typescript"), K_SIX("k6"), KOTLIN("Kotlin"),
KTORM("Ktorm"), LUA("Lua"), MYSQL("Mysql"), NIM("Nim"),
OBJECTIVE_C("Objective-C"), OCAML("OCaml"), PERL("Perl"), PHP("PHP"),
POWERSHELL("PowerShell"), PROTOBUF("Protocol Buffers (Protobuf)"), PYTHON("Python"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package org.openapitools.codegen.languages;

import com.google.common.collect.ImmutableMap;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
import org.openapitools.codegen.*;

import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.openapitools.codegen.meta.GeneratorMetadata;
import org.openapitools.codegen.meta.Stability;
import org.openapitools.codegen.model.ApiInfoMap;
import org.openapitools.codegen.model.ModelMap;
import org.openapitools.codegen.model.OperationMap;
import org.openapitools.codegen.model.OperationsMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class JetbrainsHttpClientClientCodegen extends DefaultCodegen implements CodegenConfig {
public static final String PROJECT_NAME = "Jetbrains HTTP Client";

public CodegenType getTag() {
return CodegenType.CLIENT;
}

public String getName() {
return "jetbrains-http-client";
}

public String getHelp() {
return "Generates a jetbrains-http client. See https://www.jetbrains.com/help/idea/http-client-in-product-code-editor.html";
}

@Override
public GeneratorLanguage generatorLanguage() {
return GeneratorLanguage.HTTP;
}

public JetbrainsHttpClientClientCodegen() {
super();

generatorMetadata = GeneratorMetadata.newBuilder(generatorMetadata)
.stability(Stability.EXPERIMENTAL)
.build();

outputFolder = "generated-code" + File.separator + "jetbrains-http-client";
apiTemplateFiles.put("api.mustache", ".http");
embeddedTemplateDir = templateDir = "jetbrains-http-client";
apiPackage = "Apis";
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
}

@Override
protected ImmutableMap.Builder<String, Mustache.Lambda> addMustacheLambdas() {

return super.addMustacheLambdas()
.put("doubleMustache", new DoubleMustacheLambda());
}

public static class DoubleMustacheLambda implements Mustache.Lambda {
@Override
public void execute(Template.Fragment fragment, Writer writer) throws IOException {
String text = fragment.execute();
writer.write(text
.replaceAll("\\{", "{{")
.replaceAll("}", "}}")
);
}
}

@Override
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> bundle) {

return bundle;
}

@Override
public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<ModelMap> allModels) {
return super.postProcessOperationsWithModels(objs, allModels);
}

@Override
public void postProcess() {
System.out.println("################################################################################");
System.out.println("# Thanks for using OpenAPI Generator. #");
System.out.println("# Please consider donation to help us maintain this project \uD83D\uDE4F #");
System.out.println("# https://opencollective.com/openapi_generator/donate #");
System.out.println("# #");
System.out.println("# This generator was written by Julien Lengrand-Lambert (https://github.com/jlengrand) #");
System.out.println("################################################################################");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,6 @@ org.openapitools.codegen.languages.TypeScriptNodeClientCodegen
org.openapitools.codegen.languages.TypeScriptReduxQueryClientCodegen
org.openapitools.codegen.languages.TypeScriptRxjsClientCodegen
org.openapitools.codegen.languages.WsdlSchemaCodegen

org.openapitools.codegen.languages.JetbrainsHttpClientClientCodegen
org.openapitools.codegen.languages.JuliaClientCodegen
org.openapitools.codegen.languages.JuliaServerCodegen
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# {{appName}} - Jetbrains API Client

## OpenAPI File description

{{#appDescription}}{{appDescription}}{{/appDescription}}

* API basepath : [{{basePath}}]({{basePath}})
* Version : {{version}}

## Documentation for API Endpoints

{{#generateApiDocs}}
All URIs are relative to *{{{basePath}}}*, but will link to the `.http` file that contains the endpoint definition

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**](Apis/{{apiDocPath}}{{classname}}.http#{{operationIdLowerCase}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{{summary}}}{{/summary}}
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
{{/generateApiDocs}}


_This client was generated by the jetbrains-http-client of OpenAPI Generator_
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## {{classname}}
{{#operations}}
{{#operation}}

### {{#summary}}{{summary}}{{/summary}}
# @name {{operationId}}
{{httpMethod}} {{basePath}}{{#lambda.doubleMustache}}{{path}}{{/lambda.doubleMustache}}
{{#consumes}}Content-Type: {{{mediaType}}}
{{/consumes}}
{{/operation}}
{{/operations}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.openapitools.codegen.jetbrains.http.client;

import org.openapitools.codegen.*;
import org.openapitools.codegen.languages.JetbrainsHttpClientClientCodegen;
import io.swagger.models.*;
import io.swagger.models.properties.*;

import org.testng.Assert;
import org.testng.annotations.Test;

@SuppressWarnings("static-method")
public class JetbrainsHttpClientClientCodegenModelTest {

@Test(description = "convert a simple java model")
public void simpleModelTest() {
final Model model = new ModelImpl()
.description("a sample model")
.property("id", new LongProperty())
.property("name", new StringProperty())
.required("id")
.required("name");
final DefaultCodegen codegen = new JetbrainsHttpClientClientCodegen();

// TODO: Complete this test.
// Assert.fail("Not implemented.");
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.openapitools.codegen.jetbrains.http.client;

import org.openapitools.codegen.*;
import org.openapitools.codegen.languages.JetbrainsHttpClientClientCodegen;
import io.swagger.models.*;
import io.swagger.parser.SwaggerParser;
import org.testng.Assert;
import org.testng.annotations.Test;

public class JetbrainsHttpClientClientCodegenTest {

JetbrainsHttpClientClientCodegen codegen = new JetbrainsHttpClientClientCodegen();

@Test
public void shouldSucceed() throws Exception {
// TODO: Complete this test.
// Assert.fail("Not implemented.");
}
}
Loading