forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new Go client (experimental) generator (OpenAPITools#3268)
* add new go experimental generator * extends go client codegen * add go samples and test * comment out haskell client test
- Loading branch information
Showing
147 changed files
with
11,377 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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,39 @@ | ||
#!/bin/sh | ||
|
||
SCRIPT="$0" | ||
echo "# START SCRIPT: $SCRIPT" | ||
|
||
while [ -h "$SCRIPT" ] ; do | ||
ls=`ls -ld "$SCRIPT"` | ||
link=`expr "$ls" : '.*-> \(.*\)$'` | ||
if expr "$link" : '/.*' > /dev/null; then | ||
SCRIPT="$link" | ||
else | ||
SCRIPT=`dirname "$SCRIPT"`/"$link" | ||
fi | ||
done | ||
|
||
if [ ! -d "${APP_DIR}" ]; then | ||
APP_DIR=`dirname "$SCRIPT"`/.. | ||
APP_DIR=`cd "${APP_DIR}"; pwd` | ||
fi | ||
|
||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" | ||
|
||
if [ ! -f "$executable" ] | ||
then | ||
mvn -B clean package | ||
fi | ||
|
||
SPEC="modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml" | ||
GENERATOR="go-experimental" | ||
STUB_DIR="samples/client/petstore/go-experimental/go-petstore" | ||
|
||
echo "Removing files and folders under $STUB_DIR" | ||
rm -rf $STUB_DIR | ||
|
||
# if you've executed sbt assembly previously it will use that instead. | ||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" | ||
ags="generate -t modules/openapi-generator/src/main/resources/$GENERATOR -i $SPEC -g $GENERATOR -o $STUB_DIR -DpackageName=petstore $@" | ||
|
||
java $JAVA_OPTS -jar $executable $ags |
This file contains 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,39 @@ | ||
#!/bin/sh | ||
|
||
SCRIPT="$0" | ||
echo "# START SCRIPT: $SCRIPT" | ||
|
||
while [ -h "$SCRIPT" ] ; do | ||
ls=`ls -ld "$SCRIPT"` | ||
link=`expr "$ls" : '.*-> \(.*\)$'` | ||
if expr "$link" : '/.*' > /dev/null; then | ||
SCRIPT="$link" | ||
else | ||
SCRIPT=`dirname "$SCRIPT"`/"$link" | ||
fi | ||
done | ||
|
||
if [ ! -d "${APP_DIR}" ]; then | ||
APP_DIR=`dirname "$SCRIPT"`/.. | ||
APP_DIR=`cd "${APP_DIR}"; pwd` | ||
fi | ||
|
||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" | ||
|
||
if [ ! -f "$executable" ] | ||
then | ||
mvn -B clean package | ||
fi | ||
|
||
SPEC="modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml" | ||
GENERATOR="go-experimental" | ||
STUB_DIR="samples/openapi3/client/petstore/go-experimental/go-petstore" | ||
|
||
echo "Removing files and folders under $STUB_DIR" | ||
rm -rf $STUB_DIR | ||
|
||
# if you've executed sbt assembly previously it will use that instead. | ||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" | ||
ags="generate -t modules/openapi-generator/src/main/resources/$GENERATOR -i $SPEC -g $GENERATOR -o $STUB_DIR -DpackageName=petstore $@" | ||
|
||
java $JAVA_OPTS -jar $executable $ags |
This file contains 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,21 @@ | ||
setlocal | ||
|
||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar | ||
|
||
If Not Exist %executable% ( | ||
mvn clean package | ||
) | ||
|
||
set SPEC=modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml | ||
set GENERATOR=go-experimental | ||
set STUB_DIR=samples\client\petstore\go-experimental\go-petstore | ||
|
||
echo Removing files and folders under %STUB_DIR% | ||
del /F /S /Q %STUB_DIR% | ||
|
||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties | ||
set ags=generate -t modules\openapi-generator\src\main\resources\%GENERATOR% -i %SPEC% -g %GENERATOR% -o %STUB_DIR% -DpackageName=petstore | ||
|
||
java %JAVA_OPTS% -jar %executable% %ags% | ||
|
||
endlocal |
This file contains 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
This file contains 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,16 @@ | ||
|
||
--- | ||
id: generator-opts-client-go-experimental | ||
title: Config Options for go-experimental | ||
sidebar_label: go-experimental | ||
--- | ||
|
||
| Option | Description | Values | Default | | ||
| ------ | ----------- | ------ | ------- | | ||
|packageName|Go package name (convention: lowercase).| |openapi| | ||
|packageVersion|Go package version.| |1.0.0| | ||
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true| | ||
|isGoSubmodule|whether the generated Go module is a submodule| |false| | ||
|withGoCodegenComment|whether to include Go codegen comment to disable Go Lint and collapse by default GitHub in PRs and diffs| |false| | ||
|withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false| | ||
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false| |
52 changes: 52 additions & 0 deletions
52
...nerator/src/main/java/org/openapitools/codegen/languages/GoClientExperimentalCodegen.java
This file contains 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,52 @@ | ||
/* | ||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) | ||
* | ||
* 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.openapitools.codegen.languages; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class GoClientExperimentalCodegen extends GoClientCodegen { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(GoClientExperimentalCodegen.class); | ||
|
||
public GoClientExperimentalCodegen() { | ||
super(); | ||
} | ||
|
||
/** | ||
* Configures a friendly name for the generator. This will be used by the generator | ||
* to select the library with the -g flag. | ||
* | ||
* @return the friendly name for the generator | ||
*/ | ||
@Override | ||
public String getName() { | ||
return "go-experimental"; | ||
} | ||
|
||
/** | ||
* Returns human-friendly help for the generator. Provide the consumer with help | ||
* tips, parameters here | ||
* | ||
* @return A string value for the help message | ||
*/ | ||
@Override | ||
public String getHelp() { | ||
return "Generates a Go client library (experimental and may subject to breaking changes without further notice)."; | ||
} | ||
|
||
} |
This file contains 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
8 changes: 8 additions & 0 deletions
8
modules/openapi-generator/src/main/resources/go-experimental/.travis.yml
This file contains 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,8 @@ | ||
language: go | ||
|
||
install: | ||
- go get -d -v . | ||
|
||
script: | ||
- go build -v ./ | ||
|
119 changes: 119 additions & 0 deletions
119
modules/openapi-generator/src/main/resources/go-experimental/README.mustache
This file contains 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,119 @@ | ||
# Go API client for {{packageName}} | ||
|
||
{{#appDescription}} | ||
{{{appDescription}}} | ||
{{/appDescription}} | ||
|
||
## Overview | ||
This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI-spec](https://www.openapis.org/) from a remote server, you can easily generate an API client. | ||
|
||
- API version: {{appVersion}} | ||
- Package version: {{packageVersion}} | ||
{{^hideGenerationTimestamp}} | ||
- Build date: {{generatedDate}} | ||
{{/hideGenerationTimestamp}} | ||
- Build package: {{generatorClass}} | ||
{{#infoUrl}} | ||
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}}) | ||
{{/infoUrl}} | ||
|
||
## Installation | ||
|
||
Install the following dependencies: | ||
|
||
```shell | ||
go get github.com/stretchr/testify/assert | ||
go get golang.org/x/oauth2 | ||
go get golang.org/x/net/context | ||
go get github.com/antihax/optional | ||
``` | ||
|
||
Put the package under your project folder and add the following in import: | ||
|
||
```golang | ||
import "./{{packageName}}" | ||
``` | ||
|
||
## Documentation for API Endpoints | ||
|
||
All URIs are relative to *{{basePath}}* | ||
|
||
Class | Method | HTTP request | Description | ||
------------ | ------------- | ------------- | ------------- | ||
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationIdLowerCase}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}} | ||
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} | ||
|
||
## Documentation For Models | ||
|
||
{{#models}}{{#model}} - [{{{classname}}}]({{modelDocPath}}{{{classname}}}.md) | ||
{{/model}}{{/models}} | ||
|
||
## Documentation For Authorization | ||
|
||
{{^authMethods}} Endpoints do not require authorization. | ||
{{/authMethods}}{{#authMethods}}{{#last}} Authentication schemes defined for the API:{{/last}}{{/authMethods}} | ||
{{#authMethods}} | ||
|
||
## {{{name}}} | ||
|
||
{{#isApiKey}}- **Type**: API key | ||
|
||
Example | ||
|
||
```golang | ||
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{ | ||
Key: "APIKEY", | ||
Prefix: "Bearer", // Omit if not necessary. | ||
}) | ||
r, err := client.Service.Operation(auth, args) | ||
``` | ||
|
||
{{/isApiKey}} | ||
{{#isBasic}}- **Type**: HTTP basic authentication | ||
|
||
Example | ||
|
||
```golang | ||
auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{ | ||
UserName: "username", | ||
Password: "password", | ||
}) | ||
r, err := client.Service.Operation(auth, args) | ||
``` | ||
|
||
{{/isBasic}} | ||
{{#isOAuth}} | ||
|
||
- **Type**: OAuth | ||
- **Flow**: {{{flow}}} | ||
- **Authorization URL**: {{{authorizationUrl}}} | ||
- **Scopes**: {{^scopes}}N/A{{/scopes}} | ||
{{#scopes}} - **{{{scope}}}**: {{{description}}} | ||
{{/scopes}} | ||
|
||
Example | ||
|
||
```golang | ||
auth := context.WithValue(context.Background(), sw.ContextAccessToken, "ACCESSTOKENSTRING") | ||
r, err := client.Service.Operation(auth, args) | ||
``` | ||
|
||
Or via OAuth2 module to automatically refresh tokens and perform user authentication. | ||
|
||
```golang | ||
import "golang.org/x/oauth2" | ||
|
||
/* Perform OAuth2 round trip request and obtain a token */ | ||
|
||
tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token) | ||
auth := context.WithValue(oauth2.NoContext, sw.ContextOAuth2, tokenSource) | ||
r, err := client.Service.Operation(auth, args) | ||
``` | ||
|
||
{{/isOAuth}} | ||
{{/authMethods}} | ||
|
||
## Author | ||
|
||
{{#apiInfo}}{{#apis}}{{^hasMore}}{{infoEmail}} | ||
{{/hasMore}}{{/apis}}{{/apiInfo}} |
Oops, something went wrong.